Merge branch 'issue/62_php8'
This commit is contained in:
commit
c902a5ff1f
|
|
@ -7,9 +7,9 @@
|
||||||
* extension.
|
* extension.
|
||||||
*/
|
*/
|
||||||
class CRM_Civiproxy_ExtensionUtil {
|
class CRM_Civiproxy_ExtensionUtil {
|
||||||
const SHORT_NAME = "civiproxy";
|
const SHORT_NAME = 'civiproxy';
|
||||||
const LONG_NAME = "de.systopia.civiproxy";
|
const LONG_NAME = 'de.systopia.civiproxy';
|
||||||
const CLASS_PREFIX = "CRM_Civiproxy";
|
const CLASS_PREFIX = 'CRM_Civiproxy';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translate a string using the extension's domain.
|
* Translate a string using the extension's domain.
|
||||||
|
|
@ -24,7 +24,7 @@ class CRM_Civiproxy_ExtensionUtil {
|
||||||
* Translated text.
|
* Translated text.
|
||||||
* @see ts
|
* @see ts
|
||||||
*/
|
*/
|
||||||
public static function ts($text, $params = []) {
|
public static function ts($text, $params = []): string {
|
||||||
if (!array_key_exists('domain', $params)) {
|
if (!array_key_exists('domain', $params)) {
|
||||||
$params['domain'] = [self::LONG_NAME, NULL];
|
$params['domain'] = [self::LONG_NAME, NULL];
|
||||||
}
|
}
|
||||||
|
|
@ -41,7 +41,7 @@ class CRM_Civiproxy_ExtensionUtil {
|
||||||
* Ex: 'http://example.org/sites/default/ext/org.example.foo'.
|
* Ex: 'http://example.org/sites/default/ext/org.example.foo'.
|
||||||
* Ex: 'http://example.org/sites/default/ext/org.example.foo/css/foo.css'.
|
* Ex: 'http://example.org/sites/default/ext/org.example.foo/css/foo.css'.
|
||||||
*/
|
*/
|
||||||
public static function url($file = NULL) {
|
public static function url($file = NULL): string {
|
||||||
if ($file === NULL) {
|
if ($file === NULL) {
|
||||||
return rtrim(CRM_Core_Resources::singleton()->getUrl(self::LONG_NAME), '/');
|
return rtrim(CRM_Core_Resources::singleton()->getUrl(self::LONG_NAME), '/');
|
||||||
}
|
}
|
||||||
|
|
@ -79,6 +79,13 @@ class CRM_Civiproxy_ExtensionUtil {
|
||||||
|
|
||||||
use CRM_Civiproxy_ExtensionUtil as E;
|
use CRM_Civiproxy_ExtensionUtil as E;
|
||||||
|
|
||||||
|
function _civiproxy_civix_mixin_polyfill() {
|
||||||
|
if (!class_exists('CRM_Extension_MixInfo')) {
|
||||||
|
$polyfill = __DIR__ . '/mixin/polyfill.php';
|
||||||
|
(require $polyfill)(E::LONG_NAME, E::SHORT_NAME, E::path());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (Delegated) Implements hook_civicrm_config().
|
* (Delegated) Implements hook_civicrm_config().
|
||||||
*
|
*
|
||||||
|
|
@ -91,9 +98,9 @@ function _civiproxy_civix_civicrm_config(&$config = NULL) {
|
||||||
}
|
}
|
||||||
$configured = TRUE;
|
$configured = TRUE;
|
||||||
|
|
||||||
$template =& CRM_Core_Smarty::singleton();
|
$template = CRM_Core_Smarty::singleton();
|
||||||
|
|
||||||
$extRoot = dirname(__FILE__) . DIRECTORY_SEPARATOR;
|
$extRoot = __DIR__ . DIRECTORY_SEPARATOR;
|
||||||
$extDir = $extRoot . 'templates';
|
$extDir = $extRoot . 'templates';
|
||||||
|
|
||||||
if (is_array($template->template_dir)) {
|
if (is_array($template->template_dir)) {
|
||||||
|
|
@ -105,19 +112,7 @@ function _civiproxy_civix_civicrm_config(&$config = NULL) {
|
||||||
|
|
||||||
$include_path = $extRoot . PATH_SEPARATOR . get_include_path();
|
$include_path = $extRoot . PATH_SEPARATOR . get_include_path();
|
||||||
set_include_path($include_path);
|
set_include_path($include_path);
|
||||||
}
|
_civiproxy_civix_mixin_polyfill();
|
||||||
|
|
||||||
/**
|
|
||||||
* (Delegated) Implements hook_civicrm_xmlMenu().
|
|
||||||
*
|
|
||||||
* @param $files array(string)
|
|
||||||
*
|
|
||||||
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_xmlMenu
|
|
||||||
*/
|
|
||||||
function _civiproxy_civix_civicrm_xmlMenu(&$files) {
|
|
||||||
foreach (_civiproxy_civix_glob(__DIR__ . '/xml/Menu/*.xml') as $file) {
|
|
||||||
$files[] = $file;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -130,6 +125,7 @@ function _civiproxy_civix_civicrm_install() {
|
||||||
if ($upgrader = _civiproxy_civix_upgrader()) {
|
if ($upgrader = _civiproxy_civix_upgrader()) {
|
||||||
$upgrader->onInstall();
|
$upgrader->onInstall();
|
||||||
}
|
}
|
||||||
|
_civiproxy_civix_mixin_polyfill();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -170,6 +166,7 @@ function _civiproxy_civix_civicrm_enable() {
|
||||||
$upgrader->onEnable();
|
$upgrader->onEnable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_civiproxy_civix_mixin_polyfill();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -217,160 +214,6 @@ function _civiproxy_civix_upgrader() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Search directory tree for files which match a glob pattern.
|
|
||||||
*
|
|
||||||
* Note: Dot-directories (like "..", ".git", or ".svn") will be ignored.
|
|
||||||
* Note: In Civi 4.3+, delegate to CRM_Utils_File::findFiles()
|
|
||||||
*
|
|
||||||
* @param string $dir base dir
|
|
||||||
* @param string $pattern , glob pattern, eg "*.txt"
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
function _civiproxy_civix_find_files($dir, $pattern) {
|
|
||||||
if (is_callable(['CRM_Utils_File', 'findFiles'])) {
|
|
||||||
return CRM_Utils_File::findFiles($dir, $pattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
$todos = [$dir];
|
|
||||||
$result = [];
|
|
||||||
while (!empty($todos)) {
|
|
||||||
$subdir = array_shift($todos);
|
|
||||||
foreach (_civiproxy_civix_glob("$subdir/$pattern") as $match) {
|
|
||||||
if (!is_dir($match)) {
|
|
||||||
$result[] = $match;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($dh = opendir($subdir)) {
|
|
||||||
while (FALSE !== ($entry = readdir($dh))) {
|
|
||||||
$path = $subdir . DIRECTORY_SEPARATOR . $entry;
|
|
||||||
if ($entry[0] == '.') {
|
|
||||||
}
|
|
||||||
elseif (is_dir($path)) {
|
|
||||||
$todos[] = $path;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
closedir($dh);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* (Delegated) Implements hook_civicrm_managed().
|
|
||||||
*
|
|
||||||
* Find any *.mgd.php files, merge their content, and return.
|
|
||||||
*
|
|
||||||
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_managed
|
|
||||||
*/
|
|
||||||
function _civiproxy_civix_civicrm_managed(&$entities) {
|
|
||||||
$mgdFiles = _civiproxy_civix_find_files(__DIR__, '*.mgd.php');
|
|
||||||
sort($mgdFiles);
|
|
||||||
foreach ($mgdFiles as $file) {
|
|
||||||
$es = include $file;
|
|
||||||
foreach ($es as $e) {
|
|
||||||
if (empty($e['module'])) {
|
|
||||||
$e['module'] = E::LONG_NAME;
|
|
||||||
}
|
|
||||||
if (empty($e['params']['version'])) {
|
|
||||||
$e['params']['version'] = '3';
|
|
||||||
}
|
|
||||||
$entities[] = $e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* (Delegated) Implements hook_civicrm_caseTypes().
|
|
||||||
*
|
|
||||||
* Find any and return any files matching "xml/case/*.xml"
|
|
||||||
*
|
|
||||||
* Note: This hook only runs in CiviCRM 4.4+.
|
|
||||||
*
|
|
||||||
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_caseTypes
|
|
||||||
*/
|
|
||||||
function _civiproxy_civix_civicrm_caseTypes(&$caseTypes) {
|
|
||||||
if (!is_dir(__DIR__ . '/xml/case')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (_civiproxy_civix_glob(__DIR__ . '/xml/case/*.xml') as $file) {
|
|
||||||
$name = preg_replace('/\.xml$/', '', basename($file));
|
|
||||||
if ($name != CRM_Case_XMLProcessor::mungeCaseType($name)) {
|
|
||||||
$errorMessage = sprintf("Case-type file name is malformed (%s vs %s)", $name, CRM_Case_XMLProcessor::mungeCaseType($name));
|
|
||||||
throw new CRM_Core_Exception($errorMessage);
|
|
||||||
}
|
|
||||||
$caseTypes[$name] = [
|
|
||||||
'module' => E::LONG_NAME,
|
|
||||||
'name' => $name,
|
|
||||||
'file' => $file,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* (Delegated) Implements hook_civicrm_angularModules().
|
|
||||||
*
|
|
||||||
* Find any and return any files matching "ang/*.ang.php"
|
|
||||||
*
|
|
||||||
* Note: This hook only runs in CiviCRM 4.5+.
|
|
||||||
*
|
|
||||||
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_angularModules
|
|
||||||
*/
|
|
||||||
function _civiproxy_civix_civicrm_angularModules(&$angularModules) {
|
|
||||||
if (!is_dir(__DIR__ . '/ang')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$files = _civiproxy_civix_glob(__DIR__ . '/ang/*.ang.php');
|
|
||||||
foreach ($files as $file) {
|
|
||||||
$name = preg_replace(':\.ang\.php$:', '', basename($file));
|
|
||||||
$module = include $file;
|
|
||||||
if (empty($module['ext'])) {
|
|
||||||
$module['ext'] = E::LONG_NAME;
|
|
||||||
}
|
|
||||||
$angularModules[$name] = $module;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* (Delegated) Implements hook_civicrm_themes().
|
|
||||||
*
|
|
||||||
* Find any and return any files matching "*.theme.php"
|
|
||||||
*/
|
|
||||||
function _civiproxy_civix_civicrm_themes(&$themes) {
|
|
||||||
$files = _civiproxy_civix_glob(__DIR__ . '/*.theme.php');
|
|
||||||
foreach ($files as $file) {
|
|
||||||
$themeMeta = include $file;
|
|
||||||
if (empty($themeMeta['name'])) {
|
|
||||||
$themeMeta['name'] = preg_replace(':\.theme\.php$:', '', basename($file));
|
|
||||||
}
|
|
||||||
if (empty($themeMeta['ext'])) {
|
|
||||||
$themeMeta['ext'] = E::LONG_NAME;
|
|
||||||
}
|
|
||||||
$themes[$themeMeta['name']] = $themeMeta;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Glob wrapper which is guaranteed to return an array.
|
|
||||||
*
|
|
||||||
* The documentation for glob() says, "On some systems it is impossible to
|
|
||||||
* distinguish between empty match and an error." Anecdotally, the return
|
|
||||||
* result for an empty match is sometimes array() and sometimes FALSE.
|
|
||||||
* This wrapper provides consistency.
|
|
||||||
*
|
|
||||||
* @link http://php.net/glob
|
|
||||||
* @param string $pattern
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
function _civiproxy_civix_glob($pattern) {
|
|
||||||
$result = glob($pattern);
|
|
||||||
return is_array($result) ? $result : [];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inserts a navigation menu item at a given place in the hierarchy.
|
* Inserts a navigation menu item at a given place in the hierarchy.
|
||||||
*
|
*
|
||||||
|
|
@ -453,18 +296,6 @@ function _civiproxy_civix_fixNavigationMenuItems(&$nodes, &$maxNavID, $parentID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* (Delegated) Implements hook_civicrm_alterSettingsFolders().
|
|
||||||
*
|
|
||||||
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_alterSettingsFolders
|
|
||||||
*/
|
|
||||||
function _civiproxy_civix_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) {
|
|
||||||
$settingsDir = __DIR__ . DIRECTORY_SEPARATOR . 'settings';
|
|
||||||
if (!in_array($settingsDir, $metaDataFolders) && is_dir($settingsDir)) {
|
|
||||||
$metaDataFolders[] = $settingsDir;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (Delegated) Implements hook_civicrm_entityTypes().
|
* (Delegated) Implements hook_civicrm_entityTypes().
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -25,15 +25,6 @@ function civiproxy_civicrm_config(&$config) {
|
||||||
_civiproxy_civix_civicrm_config($config);
|
_civiproxy_civix_civicrm_config($config);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Implementation of hook_civicrm_xmlMenu
|
|
||||||
*
|
|
||||||
* @param $files array(string)
|
|
||||||
*/
|
|
||||||
function civiproxy_civicrm_xmlMenu(&$files) {
|
|
||||||
_civiproxy_civix_civicrm_xmlMenu($files);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of hook_civicrm_install
|
* Implementation of hook_civicrm_install
|
||||||
*/
|
*/
|
||||||
|
|
@ -75,41 +66,27 @@ function civiproxy_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) {
|
||||||
return _civiproxy_civix_civicrm_upgrade($op, $queue);
|
return _civiproxy_civix_civicrm_upgrade($op, $queue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Implementation of hook_civicrm_managed
|
|
||||||
*
|
|
||||||
* Generate a list of entities to create/deactivate/delete when this module
|
|
||||||
* is installed, disabled, uninstalled.
|
|
||||||
*/
|
|
||||||
function civiproxy_civicrm_managed(&$entities) {
|
|
||||||
return _civiproxy_civix_civicrm_managed($entities);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implementation of hook_civicrm_caseTypes
|
|
||||||
*
|
|
||||||
* Generate a list of case-types
|
|
||||||
*
|
|
||||||
* Note: This hook only runs in CiviCRM 4.4+.
|
|
||||||
*/
|
|
||||||
function civiproxy_civicrm_caseTypes(&$caseTypes) {
|
|
||||||
_civiproxy_civix_civicrm_caseTypes($caseTypes);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of hook_civicrm_alterSettingsFolders
|
* Implementation of hook_civicrm_alterSettingsFolders
|
||||||
*
|
*
|
||||||
* Scan for settings in custom folder and import them
|
* Scan for settings in custom folder and import them
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function civiproxy_civicrm_alterSettingsFolders(&$metaDataFolders = NULL){
|
|
||||||
static $configured = FALSE;
|
|
||||||
if ($configured) return;
|
|
||||||
$configured = TRUE;
|
|
||||||
|
|
||||||
$extRoot = dirname( __FILE__ ) . DIRECTORY_SEPARATOR;
|
/**
|
||||||
$extDir = $extRoot . 'settings';
|
* Implements hook_civicrm_postInstall().
|
||||||
if(!in_array($extDir, $metaDataFolders)){
|
*
|
||||||
$metaDataFolders[] = $extDir;
|
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_postInstall
|
||||||
}
|
*/
|
||||||
|
function civiproxy_civicrm_postInstall() {
|
||||||
|
_civiproxy_civix_civicrm_postInstall();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements hook_civicrm_entityTypes().
|
||||||
|
*
|
||||||
|
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_entityTypes
|
||||||
|
*/
|
||||||
|
function civiproxy_civicrm_entityTypes(&$entityTypes) {
|
||||||
|
_civiproxy_civix_civicrm_entityTypes($entityTypes);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,5 +23,10 @@
|
||||||
<comments>This is the companion extension to SYSTOPIA's CiviProxy security system</comments>
|
<comments>This is the companion extension to SYSTOPIA's CiviProxy security system</comments>
|
||||||
<civix>
|
<civix>
|
||||||
<namespace>CRM/Civiproxy</namespace>
|
<namespace>CRM/Civiproxy</namespace>
|
||||||
|
<format>22.05.2</format>
|
||||||
</civix>
|
</civix>
|
||||||
|
<mixins>
|
||||||
|
<mixin>menu-xml@1.0.0</mixin>
|
||||||
|
<mixin>setting-php@1.0.0</mixin>
|
||||||
|
</mixins>
|
||||||
</extension>
|
</extension>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-register "xml/Menu/*.xml" files.
|
||||||
|
*
|
||||||
|
* @mixinName menu-xml
|
||||||
|
* @mixinVersion 1.0.0
|
||||||
|
*
|
||||||
|
* @param CRM_Extension_MixInfo $mixInfo
|
||||||
|
* On newer deployments, this will be an instance of MixInfo. On older deployments, Civix may polyfill with a work-a-like.
|
||||||
|
* @param \CRM_Extension_BootCache $bootCache
|
||||||
|
* On newer deployments, this will be an instance of MixInfo. On older deployments, Civix may polyfill with a work-a-like.
|
||||||
|
*/
|
||||||
|
return function ($mixInfo, $bootCache) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \Civi\Core\Event\GenericHookEvent $e
|
||||||
|
* @see CRM_Utils_Hook::xmlMenu()
|
||||||
|
*/
|
||||||
|
Civi::dispatcher()->addListener('hook_civicrm_xmlMenu', function ($e) use ($mixInfo) {
|
||||||
|
if (!$mixInfo->isActive()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$files = (array) glob($mixInfo->getPath('xml/Menu/*.xml'));
|
||||||
|
foreach ($files as $file) {
|
||||||
|
$e->files[] = $file;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,101 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When deploying on systems that lack mixin support, fake it.
|
||||||
|
*
|
||||||
|
* @mixinFile polyfill.php
|
||||||
|
*
|
||||||
|
* This polyfill does some (persnickity) deduplication, but it doesn't allow upgrades or shipping replacements in core.
|
||||||
|
*
|
||||||
|
* Note: The polyfill.php is designed to be copied into extensions for interoperability. Consequently, this file is
|
||||||
|
* not used 'live' by `civicrm-core`. However, the file does need a canonical home, and it's convenient to keep it
|
||||||
|
* adjacent to the actual mixin files.
|
||||||
|
*
|
||||||
|
* @param string $longName
|
||||||
|
* @param string $shortName
|
||||||
|
* @param string $basePath
|
||||||
|
*/
|
||||||
|
return function ($longName, $shortName, $basePath) {
|
||||||
|
// Construct imitations of the mixin services. These cannot work as well (e.g. with respect to
|
||||||
|
// number of file-reads, deduping, upgrading)... but they should be OK for a few months while
|
||||||
|
// the mixin services become available.
|
||||||
|
|
||||||
|
// List of active mixins; deduped by version
|
||||||
|
$mixinVers = [];
|
||||||
|
foreach ((array) glob($basePath . '/mixin/*.mixin.php') as $f) {
|
||||||
|
[$name, $ver] = explode('@', substr(basename($f), 0, -10));
|
||||||
|
if (!isset($mixinVers[$name]) || version_compare($ver, $mixinVers[$name], '>')) {
|
||||||
|
$mixinVers[$name] = $ver;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$mixins = [];
|
||||||
|
foreach ($mixinVers as $name => $ver) {
|
||||||
|
$mixins[] = "$name@$ver";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Imitate CRM_Extension_MixInfo.
|
||||||
|
$mixInfo = new class() {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $longName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $shortName;
|
||||||
|
|
||||||
|
public $_basePath;
|
||||||
|
|
||||||
|
public function getPath($file = NULL) {
|
||||||
|
return $this->_basePath . ($file === NULL ? '' : (DIRECTORY_SEPARATOR . $file));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isActive() {
|
||||||
|
return \CRM_Extension_System::singleton()->getMapper()->isActiveModule($this->shortName);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
$mixInfo->longName = $longName;
|
||||||
|
$mixInfo->shortName = $shortName;
|
||||||
|
$mixInfo->_basePath = $basePath;
|
||||||
|
|
||||||
|
// Imitate CRM_Extension_BootCache.
|
||||||
|
$bootCache = new class() {
|
||||||
|
|
||||||
|
public function define($name, $callback) {
|
||||||
|
$envId = \CRM_Core_Config_Runtime::getId();
|
||||||
|
$oldExtCachePath = \Civi::paths()->getPath("[civicrm.compile]/CachedExtLoader.{$envId}.php");
|
||||||
|
$stat = stat($oldExtCachePath);
|
||||||
|
$file = Civi::paths()->getPath('[civicrm.compile]/CachedMixin.' . md5($name . ($stat['mtime'] ?? 0)) . '.php');
|
||||||
|
if (file_exists($file)) {
|
||||||
|
return include $file;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$data = $callback();
|
||||||
|
file_put_contents($file, '<' . "?php\nreturn " . var_export($data, 1) . ';');
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
// Imitate CRM_Extension_MixinLoader::run()
|
||||||
|
// Parse all live mixins before trying to scan any classes.
|
||||||
|
global $_CIVIX_MIXIN_POLYFILL;
|
||||||
|
foreach ($mixins as $mixin) {
|
||||||
|
// If the exact same mixin is defined by multiple exts, just use the first one.
|
||||||
|
if (!isset($_CIVIX_MIXIN_POLYFILL[$mixin])) {
|
||||||
|
$_CIVIX_MIXIN_POLYFILL[$mixin] = include_once $basePath . '/mixin/' . $mixin . '.mixin.php';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach ($mixins as $mixin) {
|
||||||
|
// If there's trickery about installs/uninstalls/resets, then we may need to register a second time.
|
||||||
|
if (!isset(\Civi::$statics[__FUNCTION__][$mixin])) {
|
||||||
|
\Civi::$statics[__FUNCTION__][$mixin] = 1;
|
||||||
|
$func = $_CIVIX_MIXIN_POLYFILL[$mixin];
|
||||||
|
$func($mixInfo, $bootCache);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-register "settings/*.setting.php" files.
|
||||||
|
*
|
||||||
|
* @mixinName setting-php
|
||||||
|
* @mixinVersion 1.0.0
|
||||||
|
*
|
||||||
|
* @param CRM_Extension_MixInfo $mixInfo
|
||||||
|
* On newer deployments, this will be an instance of MixInfo. On older deployments, Civix may polyfill with a work-a-like.
|
||||||
|
* @param \CRM_Extension_BootCache $bootCache
|
||||||
|
* On newer deployments, this will be an instance of MixInfo. On older deployments, Civix may polyfill with a work-a-like.
|
||||||
|
*/
|
||||||
|
return function ($mixInfo, $bootCache) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \Civi\Core\Event\GenericHookEvent $e
|
||||||
|
* @see CRM_Utils_Hook::alterSettingsFolders()
|
||||||
|
*/
|
||||||
|
Civi::dispatcher()->addListener('hook_civicrm_alterSettingsFolders', function ($e) use ($mixInfo) {
|
||||||
|
// When deactivating on a polyfill/pre-mixin system, listeners may not cleanup automatically.
|
||||||
|
if (!$mixInfo->isActive()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$settingsDir = $mixInfo->getPath('settings');
|
||||||
|
if (!in_array($settingsDir, $e->settingsFolders) && is_dir($settingsDir)) {
|
||||||
|
$e->settingsFolders[] = $settingsDir;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
||||||
|
|
@ -51,8 +51,8 @@ $target_url = $target_civicrm . '/civicrm/mailing/url';
|
||||||
$target_open = $target_civicrm . '/civicrm/mailing/open';
|
$target_open = $target_civicrm . '/civicrm/mailing/open';
|
||||||
|
|
||||||
// CAUTION: use the following for CiviCRM < 5.27 or "Extern URL Style" = "Standalone Scripts"
|
// CAUTION: use the following for CiviCRM < 5.27 or "Extern URL Style" = "Standalone Scripts"
|
||||||
#$target_url = $target_civicrm . '/sites/all/modules/civicrm/extern/url.php';
|
//$target_url = $target_civicrm . '/sites/all/modules/civicrm/extern/url.php';
|
||||||
#$target_open = $target_civicrm . '/sites/all/modules/civicrm/extern/open.php';
|
//$target_open = $target_civicrm . '/sites/all/modules/civicrm/extern/open.php';
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************
|
/****************************************************************
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ class Cache_Lite
|
||||||
* @var string $_file
|
* @var string $_file
|
||||||
*/
|
*/
|
||||||
var $_file;
|
var $_file;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* File name (without path)
|
* File name (without path)
|
||||||
*
|
*
|
||||||
|
|
@ -128,7 +128,7 @@ class Cache_Lite
|
||||||
* @var int $_pearErrorMode
|
* @var int $_pearErrorMode
|
||||||
*/
|
*/
|
||||||
var $_pearErrorMode = CACHE_LITE_ERROR_RETURN;
|
var $_pearErrorMode = CACHE_LITE_ERROR_RETURN;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Current cache id
|
* Current cache id
|
||||||
*
|
*
|
||||||
|
|
@ -146,7 +146,7 @@ class Cache_Lite
|
||||||
/**
|
/**
|
||||||
* Enable / Disable "Memory Caching"
|
* Enable / Disable "Memory Caching"
|
||||||
*
|
*
|
||||||
* NB : There is no lifetime for memory caching !
|
* NB : There is no lifetime for memory caching !
|
||||||
*
|
*
|
||||||
* @var boolean $_memoryCaching
|
* @var boolean $_memoryCaching
|
||||||
*/
|
*/
|
||||||
|
|
@ -180,7 +180,7 @@ class Cache_Lite
|
||||||
* @var int $memoryCachingLimit
|
* @var int $memoryCachingLimit
|
||||||
*/
|
*/
|
||||||
var $_memoryCachingLimit = 1000;
|
var $_memoryCachingLimit = 1000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* File Name protection
|
* File Name protection
|
||||||
*
|
*
|
||||||
|
|
@ -192,17 +192,17 @@ class Cache_Lite
|
||||||
* @var boolean $fileNameProtection
|
* @var boolean $fileNameProtection
|
||||||
*/
|
*/
|
||||||
var $_fileNameProtection = true;
|
var $_fileNameProtection = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable / disable automatic serialization
|
* Enable / disable automatic serialization
|
||||||
*
|
*
|
||||||
* it can be used to save directly datas which aren't strings
|
* it can be used to save directly datas which aren't strings
|
||||||
* (but it's slower)
|
* (but it's slower)
|
||||||
*
|
*
|
||||||
* @var boolean $_serialize
|
* @var boolean $_serialize
|
||||||
*/
|
*/
|
||||||
var $_automaticSerialization = false;
|
var $_automaticSerialization = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disable / Tune the automatic cleaning process
|
* Disable / Tune the automatic cleaning process
|
||||||
*
|
*
|
||||||
|
|
@ -215,45 +215,45 @@ class Cache_Lite
|
||||||
* @var int $_automaticCleaning
|
* @var int $_automaticCleaning
|
||||||
*/
|
*/
|
||||||
var $_automaticCleaningFactor = 0;
|
var $_automaticCleaningFactor = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Nested directory level
|
* Nested directory level
|
||||||
*
|
*
|
||||||
* Set the hashed directory structure level. 0 means "no hashed directory
|
* Set the hashed directory structure level. 0 means "no hashed directory
|
||||||
* structure", 1 means "one level of directory", 2 means "two levels"...
|
* structure", 1 means "one level of directory", 2 means "two levels"...
|
||||||
* This option can speed up Cache_Lite only when you have many thousands of
|
* This option can speed up Cache_Lite only when you have many thousands of
|
||||||
* cache file. Only specific benchs can help you to choose the perfect value
|
* cache file. Only specific benchs can help you to choose the perfect value
|
||||||
* for you. Maybe, 1 or 2 is a good start.
|
* for you. Maybe, 1 or 2 is a good start.
|
||||||
*
|
*
|
||||||
* @var int $_hashedDirectoryLevel
|
* @var int $_hashedDirectoryLevel
|
||||||
*/
|
*/
|
||||||
var $_hashedDirectoryLevel = 0;
|
var $_hashedDirectoryLevel = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Umask for hashed directory structure
|
* Umask for hashed directory structure
|
||||||
*
|
*
|
||||||
* @var int $_hashedDirectoryUmask
|
* @var int $_hashedDirectoryUmask
|
||||||
*/
|
*/
|
||||||
var $_hashedDirectoryUmask = 0700;
|
var $_hashedDirectoryUmask = 0700;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API break for error handling in CACHE_LITE_ERROR_RETURN mode
|
* API break for error handling in CACHE_LITE_ERROR_RETURN mode
|
||||||
*
|
*
|
||||||
* In CACHE_LITE_ERROR_RETURN mode, error handling was not good because
|
* In CACHE_LITE_ERROR_RETURN mode, error handling was not good because
|
||||||
* for example save() method always returned a boolean (a PEAR_Error object
|
* for example save() method always returned a boolean (a PEAR_Error object
|
||||||
* would be better in CACHE_LITE_ERROR_RETURN mode). To correct this without
|
* would be better in CACHE_LITE_ERROR_RETURN mode). To correct this without
|
||||||
* breaking the API, this option (false by default) can change this handling.
|
* breaking the API, this option (false by default) can change this handling.
|
||||||
*
|
*
|
||||||
* @var boolean
|
* @var boolean
|
||||||
*/
|
*/
|
||||||
var $_errorHandlingAPIBreak = false;
|
var $_errorHandlingAPIBreak = false;
|
||||||
|
|
||||||
var $_hashedDirectoryGroup = NULL;
|
var $_hashedDirectoryGroup = NULL;
|
||||||
|
|
||||||
var $_cacheFileMode = NULL;
|
var $_cacheFileMode = NULL;
|
||||||
|
|
||||||
var $_cacheFileGroup = NULL;
|
var $_cacheFileGroup = NULL;
|
||||||
|
|
||||||
// --- Public methods ---
|
// --- Public methods ---
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -282,12 +282,12 @@ class Cache_Lite
|
||||||
* 'cacheFileMode' => filesystem mode of newly created cache files (int)
|
* 'cacheFileMode' => filesystem mode of newly created cache files (int)
|
||||||
* 'cacheFileGroup' => group of newly created cache files (int | string) (see function chgrp)
|
* 'cacheFileGroup' => group of newly created cache files (int | string) (see function chgrp)
|
||||||
* );
|
* );
|
||||||
*
|
*
|
||||||
* If sys_get_temp_dir() is available and the
|
* If sys_get_temp_dir() is available and the
|
||||||
* 'cacheDir' option is not provided in the
|
* 'cacheDir' option is not provided in the
|
||||||
* constructor options array its output is used
|
* constructor options array its output is used
|
||||||
* to determine the suitable temporary directory.
|
* to determine the suitable temporary directory.
|
||||||
*
|
*
|
||||||
* @see http://de.php.net/sys_get_temp_dir
|
* @see http://de.php.net/sys_get_temp_dir
|
||||||
* @see http://pear.php.net/bugs/bug.php?id=18328
|
* @see http://pear.php.net/bugs/bug.php?id=18328
|
||||||
*
|
*
|
||||||
|
|
@ -313,7 +313,7 @@ class Cache_Lite
|
||||||
{
|
{
|
||||||
self::__construct($options);
|
self::__construct($options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generic way to set a Cache_Lite option
|
* Generic way to set a Cache_Lite option
|
||||||
*
|
*
|
||||||
|
|
@ -323,7 +323,7 @@ class Cache_Lite
|
||||||
* @var mixed $value value of the option
|
* @var mixed $value value of the option
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
function setOption($name, $value)
|
function setOption($name, $value)
|
||||||
{
|
{
|
||||||
$availableOptions = array('errorHandlingAPIBreak', 'hashedDirectoryUmask', 'hashedDirectoryLevel', 'automaticCleaningFactor', 'automaticSerialization', 'fileNameProtection', 'memoryCaching', 'onlyMemoryCaching', 'memoryCachingLimit', 'cacheDir', 'caching', 'lifeTime', 'fileLocking', 'writeControl', 'readControl', 'readControlType', 'pearErrorMode', 'hashedDirectoryGroup', 'cacheFileMode', 'cacheFileGroup');
|
$availableOptions = array('errorHandlingAPIBreak', 'hashedDirectoryUmask', 'hashedDirectoryLevel', 'automaticCleaningFactor', 'automaticSerialization', 'fileNameProtection', 'memoryCaching', 'onlyMemoryCaching', 'memoryCachingLimit', 'cacheDir', 'caching', 'lifeTime', 'fileLocking', 'writeControl', 'readControl', 'readControlType', 'pearErrorMode', 'hashedDirectoryGroup', 'cacheFileMode', 'cacheFileGroup');
|
||||||
if (in_array($name, $availableOptions)) {
|
if (in_array($name, $availableOptions)) {
|
||||||
|
|
@ -331,7 +331,7 @@ class Cache_Lite
|
||||||
$this->$property = $value;
|
$this->$property = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test if a cache is available and (if yes) return it
|
* Test if a cache is available and (if yes) return it
|
||||||
*
|
*
|
||||||
|
|
@ -359,7 +359,7 @@ class Cache_Lite
|
||||||
}
|
}
|
||||||
if ($this->_onlyMemoryCaching) {
|
if ($this->_onlyMemoryCaching) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (($doNotTestCacheValidity) || (is_null($this->_refreshTime))) {
|
if (($doNotTestCacheValidity) || (is_null($this->_refreshTime))) {
|
||||||
if (file_exists($this->_file)) {
|
if (file_exists($this->_file)) {
|
||||||
|
|
@ -380,7 +380,7 @@ class Cache_Lite
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save some data in a cache file
|
* Save some data in a cache file
|
||||||
*
|
*
|
||||||
|
|
@ -406,24 +406,24 @@ class Cache_Lite
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($this->_automaticCleaningFactor>0 && ($this->_automaticCleaningFactor==1 || mt_rand(1, $this->_automaticCleaningFactor)==1)) {
|
if ($this->_automaticCleaningFactor>0 && ($this->_automaticCleaningFactor==1 || mt_rand(1, $this->_automaticCleaningFactor)==1)) {
|
||||||
$this->clean(false, 'old');
|
$this->clean(false, 'old');
|
||||||
}
|
}
|
||||||
if ($this->_writeControl) {
|
if ($this->_writeControl) {
|
||||||
$res = $this->_writeAndControl($data);
|
$res = $this->_writeAndControl($data);
|
||||||
if (is_bool($res)) {
|
if (is_bool($res)) {
|
||||||
if ($res) {
|
if ($res) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// if $res if false, we need to invalidate the cache
|
// if $res if false, we need to invalidate the cache
|
||||||
@touch($this->_file, time() - 2*abs($this->_lifeTime));
|
@touch($this->_file, time() - 2*abs($this->_lifeTime));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$res = $this->_write($data);
|
$res = $this->_write($data);
|
||||||
}
|
}
|
||||||
if (is_object($res)) {
|
if (is_object($res)) {
|
||||||
// $res is a PEAR_Error object
|
// $res is a PEAR_Error object
|
||||||
if (!($this->_errorHandlingAPIBreak)) {
|
if (!($this->_errorHandlingAPIBreak)) {
|
||||||
return false; // we return false (old API)
|
return false; // we return false (old API)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -466,7 +466,7 @@ class Cache_Lite
|
||||||
* else only cache files of the specified group will be destroyed
|
* else only cache files of the specified group will be destroyed
|
||||||
*
|
*
|
||||||
* @param string $group name of the cache group
|
* @param string $group name of the cache group
|
||||||
* @param string $mode flush cache mode : 'old', 'ingroup', 'notingroup',
|
* @param string $mode flush cache mode : 'old', 'ingroup', 'notingroup',
|
||||||
* 'callback_myFunction'
|
* 'callback_myFunction'
|
||||||
* @return boolean true if no problem
|
* @return boolean true if no problem
|
||||||
* @access public
|
* @access public
|
||||||
|
|
@ -475,12 +475,12 @@ class Cache_Lite
|
||||||
{
|
{
|
||||||
return $this->_cleanDir($this->_cacheDir, $group, $mode);
|
return $this->_cleanDir($this->_cacheDir, $group, $mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set to debug mode
|
* Set to debug mode
|
||||||
*
|
*
|
||||||
* When an error is found, the script will stop and the message will be displayed
|
* When an error is found, the script will stop and the message will be displayed
|
||||||
* (in debug mode only).
|
* (in debug mode only).
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
|
|
@ -538,7 +538,7 @@ class Cache_Lite
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the cache last modification time
|
* Return the cache last modification time
|
||||||
*
|
*
|
||||||
|
|
@ -546,11 +546,11 @@ class Cache_Lite
|
||||||
*
|
*
|
||||||
* @return int last modification time
|
* @return int last modification time
|
||||||
*/
|
*/
|
||||||
function lastModified()
|
function lastModified()
|
||||||
{
|
{
|
||||||
return @filemtime($this->_file);
|
return @filemtime($this->_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trigger a PEAR error
|
* Trigger a PEAR error
|
||||||
*
|
*
|
||||||
|
|
@ -564,29 +564,29 @@ class Cache_Lite
|
||||||
*/
|
*/
|
||||||
function raiseError($msg, $code)
|
function raiseError($msg, $code)
|
||||||
{
|
{
|
||||||
error_log("[code] $msg");
|
return PEAR::raiseError($msg, $code, $this->_pearErrorMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extend the life of a valid cache file
|
* Extend the life of a valid cache file
|
||||||
*
|
*
|
||||||
* see http://pear.php.net/bugs/bug.php?id=6681
|
* see http://pear.php.net/bugs/bug.php?id=6681
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
function extendLife()
|
function extendLife()
|
||||||
{
|
{
|
||||||
@touch($this->_file);
|
@touch($this->_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Private methods ---
|
// --- Private methods ---
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compute & set the refresh time
|
* Compute & set the refresh time
|
||||||
*
|
*
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function _setRefreshTime()
|
function _setRefreshTime()
|
||||||
{
|
{
|
||||||
if (is_null($this->_lifeTime)) {
|
if (is_null($this->_lifeTime)) {
|
||||||
$this->_refreshTime = null;
|
$this->_refreshTime = null;
|
||||||
|
|
@ -594,10 +594,10 @@ class Cache_Lite
|
||||||
$this->_refreshTime = time() - $this->_lifeTime;
|
$this->_refreshTime = time() - $this->_lifeTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a file
|
* Remove a file
|
||||||
*
|
*
|
||||||
* @param string $file complete file path and name
|
* @param string $file complete file path and name
|
||||||
* @return boolean true if no problem
|
* @return boolean true if no problem
|
||||||
* @access private
|
* @access private
|
||||||
|
|
@ -607,7 +607,7 @@ class Cache_Lite
|
||||||
if (!@unlink($file)) {
|
if (!@unlink($file)) {
|
||||||
return $this->raiseError('Cache_Lite : Unable to remove cache !', -3);
|
return $this->raiseError('Cache_Lite : Unable to remove cache !', -3);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -620,7 +620,7 @@ class Cache_Lite
|
||||||
* @return boolean true if no problem
|
* @return boolean true if no problem
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function _cleanDir($dir, $group = false, $mode = 'ingroup')
|
function _cleanDir($dir, $group = false, $mode = 'ingroup')
|
||||||
{
|
{
|
||||||
if ($this->_fileNameProtection) {
|
if ($this->_fileNameProtection) {
|
||||||
$motif = ($group) ? 'cache_'.md5($group).'_' : 'cache_';
|
$motif = ($group) ? 'cache_'.md5($group).'_' : 'cache_';
|
||||||
|
|
@ -638,7 +638,7 @@ class Cache_Lite
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!($dh = opendir($dir))) {
|
if (!($dh = @opendir($dir))) {
|
||||||
return $this->raiseError('Cache_Lite : Unable to open cache directory !', -4);
|
return $this->raiseError('Cache_Lite : Unable to open cache directory !', -4);
|
||||||
}
|
}
|
||||||
$result = true;
|
$result = true;
|
||||||
|
|
@ -710,7 +710,7 @@ class Cache_Lite
|
||||||
$key = key($this->_memoryCachingArray);
|
$key = key($this->_memoryCachingArray);
|
||||||
next($this->_memoryCachingArray);
|
next($this->_memoryCachingArray);
|
||||||
unset($this->_memoryCachingArray[$key]);
|
unset($this->_memoryCachingArray[$key]);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$this->_memoryCachingCounter = $this->_memoryCachingCounter + 1;
|
$this->_memoryCachingCounter = $this->_memoryCachingCounter + 1;
|
||||||
}
|
}
|
||||||
|
|
@ -725,7 +725,7 @@ class Cache_Lite
|
||||||
*/
|
*/
|
||||||
function _setFileName($id, $group)
|
function _setFileName($id, $group)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ($this->_fileNameProtection) {
|
if ($this->_fileNameProtection) {
|
||||||
$suffix = 'cache_'.md5($group).'_'.md5($id);
|
$suffix = 'cache_'.md5($group).'_'.md5($id);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -736,12 +736,12 @@ class Cache_Lite
|
||||||
$hash = md5($suffix);
|
$hash = md5($suffix);
|
||||||
for ($i=0 ; $i<$this->_hashedDirectoryLevel ; $i++) {
|
for ($i=0 ; $i<$this->_hashedDirectoryLevel ; $i++) {
|
||||||
$root = $root . 'cache_' . substr($hash, 0, $i + 1) . '/';
|
$root = $root . 'cache_' . substr($hash, 0, $i + 1) . '/';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->_fileName = $suffix;
|
$this->_fileName = $suffix;
|
||||||
$this->_file = $root.$suffix;
|
$this->_file = $root.$suffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read the cache file and return the content
|
* Read the cache file and return the content
|
||||||
*
|
*
|
||||||
|
|
@ -781,7 +781,7 @@ class Cache_Lite
|
||||||
$hashData = $this->_hash($data, $this->_readControlType);
|
$hashData = $this->_hash($data, $this->_readControlType);
|
||||||
if ($hashData != $hashControl) {
|
if ($hashData != $hashControl) {
|
||||||
if (!(is_null($this->_lifeTime))) {
|
if (!(is_null($this->_lifeTime))) {
|
||||||
@touch($this->_file, time() - 2*abs($this->_lifeTime));
|
@touch($this->_file, time() - 2*abs($this->_lifeTime));
|
||||||
} else {
|
} else {
|
||||||
@unlink($this->_file);
|
@unlink($this->_file);
|
||||||
}
|
}
|
||||||
|
|
@ -790,9 +790,9 @@ class Cache_Lite
|
||||||
}
|
}
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
return $this->raiseError('Cache_Lite : Unable to read cache !', -2);
|
return $this->raiseError('Cache_Lite : Unable to read cache !', -2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write the given data in the cache file
|
* Write the given data in the cache file
|
||||||
*
|
*
|
||||||
|
|
@ -819,7 +819,7 @@ class Cache_Lite
|
||||||
}
|
}
|
||||||
// if both _cacheFileMode and _cacheFileGroup is null, then we don't need to call
|
// if both _cacheFileMode and _cacheFileGroup is null, then we don't need to call
|
||||||
// file_exists (see below: if ($is_newfile) ...)
|
// file_exists (see below: if ($is_newfile) ...)
|
||||||
$is_newfile = (! is_null($this->_cacheFileMode) || !is_null($this->_cacheFileGroup))
|
$is_newfile = (! is_null($this->_cacheFileMode) || !is_null($this->_cacheFileGroup))
|
||||||
&& ! @file_exists($this->_file);
|
&& ! @file_exists($this->_file);
|
||||||
$fp = @fopen($this->_file, "wb");
|
$fp = @fopen($this->_file, "wb");
|
||||||
if ($fp) {
|
if ($fp) {
|
||||||
|
|
@ -845,10 +845,10 @@ class Cache_Lite
|
||||||
if ($this->_fileLocking) @flock($fp, LOCK_UN);
|
if ($this->_fileLocking) @flock($fp, LOCK_UN);
|
||||||
@fclose($fp);
|
@fclose($fp);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return $this->raiseError('Cache_Lite : Unable to write cache file : '.$this->_file, -1);
|
return $this->raiseError('Cache_Lite : Unable to write cache file : '.$this->_file, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write the given data in the cache file and control it just after to avoir corrupted cache entries
|
* Write the given data in the cache file and control it just after to avoir corrupted cache entries
|
||||||
*
|
*
|
||||||
|
|
@ -867,11 +867,11 @@ class Cache_Lite
|
||||||
return $dataRead; # We return the PEAR_Error object
|
return $dataRead; # We return the PEAR_Error object
|
||||||
}
|
}
|
||||||
if ((is_bool($dataRead)) && (!$dataRead)) {
|
if ((is_bool($dataRead)) && (!$dataRead)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return ($dataRead==$data);
|
return ($dataRead==$data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a control key with the string containing datas
|
* Make a control key with the string containing datas
|
||||||
*
|
*
|
||||||
|
|
@ -893,5 +893,5 @@ class Cache_Lite
|
||||||
return $this->raiseError('Unknown controlType ! (available values are only \'md5\', \'crc32\', \'strlen\')', -5);
|
return $this->raiseError('Unknown controlType ! (available values are only \'md5\', \'crc32\', \'strlen\')', -5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue