/** * Scan $basedir for a list of extension-keys * * @return array * ($key => $relPath) */ protected function getRelPaths() { if (!is_array($this->relPaths)) { if ($this->cache) { $this->relPaths = $this->cache->get($this->cacheKey); } if (!is_array($this->relPaths)) { $this->relPaths = array(); $infoPaths = CRM_Utils_File::findFiles($this->baseDir, 'info.xml'); foreach ($infoPaths as $infoPath) { $relPath = CRM_Utils_File::relativize(dirname($infoPath), $this->baseDir); try { $info = CRM_Extension_Info::loadFromFile($infoPath); } catch (CRM_Extension_Exception_ParseException $e) { CRM_Core_Session::setStatus(ts('Parse error in extension: %1', array(1 => $e->getMessage())), '', 'error'); CRM_Core_Error::debug_log_message("Parse error in extension: " . $e->getMessage()); continue; } $this->relPaths[$info->key] = $relPath; } if ($this->cache) { $this->cache->set($this->cacheKey, $this->relPaths); } } } return $this->relPaths; }
/** * Get the strings from a file, using a cache if available. * * @param string $bucket * The name of a cache-row which includes strings for this file. * @param string $file * File path. * @param string $format * Type of file (e.g. 'text/javascript', 'text/html'). * @return array * List of translatable strings. */ public function get($bucket, $file, $format) { $stringsByFile = $this->cache->get($bucket); // array($file => array(...strings...)) if (!$stringsByFile) { $stringsByFile = array(); } if (!isset($stringsByFile[$file])) { if ($file && is_readable($file)) { $stringsByFile[$file] = $this->extract($file, $format); } else { $stringsByFile[$file] = array(); } $this->cache->set($bucket, $stringsByFile); } return $stringsByFile[$file]; }
public function refresh() { $this->infos = array(); $this->moduleExtensions = NULL; if ($this->cache) { $this->cache->delete($this->cacheKey . '/moduleFiles'); } }
public function refresh() { $this->infos = array(); $this->moduleExtensions = NULL; if ($this->cache) { $this->cache->delete($this->cacheKey . '/moduleFiles'); } // FIXME: How can code so code wrong be so right? CRM_Extension_System::singleton()->getClassLoader()->refresh(); }
/** * @param $civiModules * @param $fnSuffix * @param array $numParams * @param $arg1 * @param $arg2 * @param $arg3 * @param $arg4 * @param $arg5 * @param $arg6 * * @return array|bool */ public function runHooks($civiModules, $fnSuffix, $numParams, &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6) { // $civiModules is *not* passed by reference because runHooks // must be reentrant. PHP is finicky about running // multiple loops over the same variable. The circumstances // to reproduce the issue are pretty intricate. $result = array(); $fnNames = $this->cache->get($fnSuffix); if (!is_array($fnNames)) { $fnNames = array(); if ($civiModules !== NULL) { foreach ($civiModules as $module) { $fnName = "{$module}_{$fnSuffix}"; if (function_exists($fnName)) { $fnNames[] = $fnName; } } $this->cache->set($fnSuffix, $fnNames); } } foreach ($fnNames as $fnName) { $fResult = array(); switch ($numParams) { case 0: $fResult = $fnName(); break; case 1: $fResult = $fnName($arg1); break; case 2: $fResult = $fnName($arg1, $arg2); break; case 3: $fResult = $fnName($arg1, $arg2, $arg3); break; case 4: $fResult = $fnName($arg1, $arg2, $arg3, $arg4); break; case 5: $fResult = $fnName($arg1, $arg2, $arg3, $arg4, $arg5); break; case 6: $fResult = $fnName($arg1, $arg2, $arg3, $arg4, $arg5, $arg6); break; default: CRM_Core_Error::fatal(ts('Invalid hook invocation')); break; } if (!empty($fResult) && is_array($fResult)) { $result = array_merge($result, $fResult); } } return empty($result) ? TRUE : $result; }
/** * @param string $verb * @param string $url * @param string $blob * @param array $headers * Array of headers (e.g. "Content-type" => "text/plain"). * @return array * array($headers, $blob, $code) */ public function send($verb, $url, $blob, $headers = array()) { $lowVerb = strtolower($verb); if ($lowVerb === 'get' && $this->cache) { $cachePath = 'get/' . md5($url); $cacheLine = $this->cache->get($cachePath); if ($cacheLine && $cacheLine['expires'] > CRM_Utils_Time::getTimeRaw()) { return $cacheLine['data']; } } $result = parent::send($verb, $url, $blob, $headers); if ($lowVerb === 'get' && $this->cache) { $expires = CRM_Utils_Http::parseExpiration($result[0]); if ($expires !== NULL) { $cachePath = 'get/' . md5($url); $cacheLine = array('url' => $url, 'expires' => $expires, 'data' => $result); $this->cache->set($cachePath, $cacheLine); } } return $result; }
/** * Get the messages document (either from the cache or by downloading) * * @return NULL|array */ public function getDocument() { $isChanged = FALSE; $document = $this->cache->get('communityMessages'); if (empty($document) || !is_array($document)) { $document = array('messages' => array(), 'expires' => 0, 'ttl' => self::DEFAULT_RETRY, 'retry' => self::DEFAULT_RETRY); $isChanged = TRUE; } if ($document['expires'] <= CRM_Utils_Time::getTimeRaw()) { $newDocument = $this->fetchDocument(); if ($newDocument && $this->validateDocument($newDocument)) { $document = $newDocument; $document['expires'] = CRM_Utils_Time::getTimeRaw() + $document['ttl']; } else { // keep the old messages for now, try again later $document['expires'] = CRM_Utils_Time::getTimeRaw() + $document['retry']; } $isChanged = TRUE; } if ($isChanged) { $this->cache->set('communityMessages', $document); } return $document; }
/** * Flush all in-memory and persistent caches related to settings. * * @return $this */ public function flush() { $this->mandatory = NULL; $this->cache->flush(); \Civi::cache('settings')->flush(); // SettingsMetadata; not guaranteed to use same cache. foreach ($this->bagsByDomain as $bag) { /** @var SettingsBag $bag */ $bag->loadValues(); $bag->loadDefaults($this->getDefaults('domain')); $bag->loadMandatory($this->getMandatory('domain')); } foreach ($this->bagsByContact as $bag) { /** @var SettingsBag $bag */ $bag->loadValues(); $bag->loadDefaults($this->getDefaults('contact')); $bag->loadMandatory($this->getMandatory('contact')); } return $this; }
/** * Get a list of all keys in these containers -- and the * name of the container which defines each key. * * @return array * ($key => $containerName) */ public function getKeysToContainer() { if ($this->cache) { $k2c = $this->cache->get($this->cacheKey); } if (!isset($k2c) || !is_array($k2c)) { $k2c = array(); $containerNames = array_reverse(array_keys($this->containers)); foreach ($containerNames as $name) { $keys = $this->containers[$name]->getKeys(); foreach ($keys as $key) { $k2c[$key] = $name; } } if ($this->cache) { $this->cache->set($this->cacheKey, $k2c); } } return $k2c; }
/** * Translate strings in a javascript file * * @param $ext string, extension name * @param $file string, file path * @return void */ private function translateScript($ext, $file) { // For each extension, maintain one cache record which // includes parsed (translatable) strings for all its JS files. $stringsByFile = $this->cache->get($ext); // array($file => array(...strings...)) if (!$stringsByFile) { $stringsByFile = array(); } if (!isset($stringsByFile[$file])) { $filePath = $this->getPath($ext, $file); if ($filePath && is_readable($filePath)) { $stringsByFile[$file] = CRM_Utils_JS::parseStrings(file_get_contents($filePath)); } else { $stringsByFile[$file] = array(); } $this->cache->set($ext, $stringsByFile); } $this->addString($stringsByFile[$file]); }