public function __construct( $location = null, array $options = array() ) { eZExpiryHandler::registerShutdownFunction(); $this->expiryHandler = eZExpiryHandler::instance(); parent::__construct( $location, $options ); }
static function fetchIDListByUserID($userID) { if ($userID == eZUser::anonymousId()) { $userCache = eZUSer::getUserCacheByAnonymousId(); $ruleArray = $userCache['discount_rules']; } else { $http = eZHTTPTool::instance(); $handler = eZExpiryHandler::instance(); $expiredTimeStamp = 0; if ($handler->hasTimestamp('user-discountrules-cache')) { $expiredTimeStamp = $handler->timestamp('user-discountrules-cache'); } $ruleTimestamp =& $http->sessionVariable('eZUserDiscountRulesTimestamp'); $ruleArray = false; // check for cached version in session if ($ruleTimestamp > $expiredTimeStamp) { if ($http->hasSessionVariable('eZUserDiscountRules' . $userID)) { $ruleArray =& $http->sessionVariable('eZUserDiscountRules' . $userID); } } if (!is_array($ruleArray)) { $ruleArray = self::generateIDListByUserID((int) $userID); $http->setSessionVariable('eZUserDiscountRules' . $userID, $ruleArray); $http->setSessionVariable('eZUserDiscountRulesTimestamp', time()); } } $rules = array(); foreach ($ruleArray as $ruleRow) { $rules[] = $ruleRow['id']; } return $rules; }
/** * Force Route cache expiration, * so that APC cache will be flushed and regenerated next REST call */ public static function clearCache() { $expiryHandler = eZExpiryHandler::instance(); if ($expiryHandler->hasTimestamp(ezpRestRouter::ROUTE_CACHE_KEY)) { $expiryHandler->setTimestamp(ezpRestRouter::ROUTE_CACHE_KEY, 0); $expiryHandler->store(); } }
/** * Test scenario for issue #014897: Object/class name pattern and cache issues [patch] * * @result $phpCache->canRestore() returns true * @expected $phpCache->canRestore() should return false * * @link http://issues.ez.no/14897 */ public function testCanRestore() { $db = eZDB::instance(); $dbName = md5($db->DB); $cacheDir = eZSys::cacheDirectory(); $phpCache = new eZPHPCreator($cacheDir, 'classidentifiers_' . $dbName . '.php', '', array('clustering' => 'classidentifiers')); $handler = eZExpiryHandler::instance(); $expiryTime = 0; if ($handler->hasTimestamp('class-identifier-cache')) { $expiryTime = $handler->timestamp('class-identifier-cache'); } $this->assertFalse($phpCache->canRestore($expiryTime)); }
/** * Regression test for issue #15263 * Content object name/url of imported content classes aren't generated correctly * * @url http://issues.ez.no/15263 * * @outline * 1) Expire and force generation of class attribute cache * 2) Load a test package * 3) Install the package * 4) Publish an object of the imported class * 5) The object name / url alias shouldn't be the expected one **/ public function testIssue15263() { $adminUser = eZUser::fetchByName('admin'); $previousUser = eZUser::currentUser(); eZUser::setCurrentlyLoggedInUser($adminUser, $adminUser->attribute('contentobject_id')); // 1) Expire and force generation of class attribute cache $handler = eZExpiryHandler::instance(); $handler->setTimestamp('class-identifier-cache', time() - 1); $handler->store(); eZContentClassAttribute::classAttributeIdentifierByID(1); // 1) Load a test package $packageName = 'ezpackage_regression_testIssue15223.ezpkg'; $packageFilename = dirname(__FILE__) . DIRECTORY_SEPARATOR . $packageName; $packageImportTried = false; while (!$packageImportTried) { $package = eZPackage::import($packageFilename, $packageName); if (!$package instanceof eZPackage) { if ($package === eZPackage::STATUS_ALREADY_EXISTS) { $packageToRemove = eZPackage::fetch($packageName); $packageToRemove->remove(); } else { self::fail("An error occured loading the package '{$packageFilename}'"); } } $packageImportTried = true; } // 2) Install the package $installParameters = array('site_access_map' => array('*' => false), 'top_nodes_map' => array('*' => 2), 'design_map' => array('*' => false), 'restore_dates' => true, 'user_id' => $adminUser->attribute('contentobject_id'), 'non-interactive' => true, 'language_map' => $package->defaultLanguageMap()); $result = $package->install($installParameters); // 3) Publish an object of the imported class $object = new ezpObject('test_issue_15523', 2, $adminUser->attribute('contentobject_id'), 1); $object->myname = __METHOD__; $object->myothername = __METHOD__; $publishedObjectID = $object->publish(); unset($object); // 4) Test data from the publish object $publishedNodeArray = eZContentObjectTreeNode::fetchByContentObjectID($publishedObjectID); if (count($publishedNodeArray) != 1) { $this->fail("An error occured fetching node for object #{$publishedObjectID}"); } $publishedNode = $publishedNodeArray[0]; if (!$publishedNode instanceof eZContentObjectTreeNode) { $this->fail("An error occured fetching node for object #{$publishedObjectID}"); } else { $this->assertEquals("eZPackageRegression::testIssue15263", $publishedNode->attribute('name')); $this->assertEquals("eZPackageRegression-testIssue15263", $publishedNode->attribute('url_alias')); } // Remove the installed package & restore the logged in user $package->remove(); eZUser::setCurrentlyLoggedInUser($previousUser, $previousUser->attribute('contentobject_id')); }
/** * Returns true if the viewmode is a complex viewmode and the viewmode timestamp is expired. * * @param string $viewMode * @param int $timestamp UNIX Timestamp * @return bool */ static function isComplexViewModeCacheExpired( $viewMode, $timestamp ) { if ( !eZContentObject::isComplexViewMode( $viewMode ) ) return false; $handler = eZExpiryHandler::instance(); if ( !$handler->hasTimestamp( 'content-complex-viewmode-cache' ) ) return false; $expiryTime = $handler->timestamp( 'content-complex-viewmode-cache' ); if ( $expiryTime > $timestamp ) return true; return false; }
/** * Called at the end of execution and will store the data if it is modified. */ static function shutdown() { if (eZExpiryHandler::hasInstance()) { eZExpiryHandler::instance()->store(); } }
/** * Test for expireCache * * Outline: * 1. Manually set the cache expiry timestamp to a date in the past * 2. Check that it is not expired * 3. Call expireCache * 4. Check that the cache is expired */ public function testExpireCache() { $this->markTestSkipped("Needs to be rewritten due to the refactoring"); $expiryHandler = eZExpiryHandler::instance(); // 1. Manually set the cache expiry timestamp to a date in the past $expiryHandler->setTimestamp(eZURLWildcard::CACHE_SIGNATURE, time() - 3600); // 2. Check that it is not expired $this->assertFalse(eZURLWildcard::isCacheExpired(time() - 1), "Expiry timestamp is in the past, cache should not be expired"); // 3. Call expireCache eZURLWildcard::expireCache(); // 4. Check that the cache is expired $this->assertTrue(eZURLWildcard::isCacheExpired(time() - 1), "Cache should have been expired by expireCache()"); }
/** * Expire user access / info cache globally */ static function cleanupCache() { $handler = eZExpiryHandler::instance(); $handler->setTimestamp('user-info-cache', time()); $handler->store(); }
/** * Return an array with activated extensions. * * @note Default extensions are those who are loaded before a siteaccess are determined while access extensions * are loaded after siteaccess is set. * * @param false|string $extensionType Decides which extension to include in the list, the follow values are possible: * - false - Means add both default and access extensions * - 'default' - Add only default extensions * - 'access' - Add only access extensions * @param eZINI|null $siteINI Optional parameter to be able to only do change on specific instance of site.ini * @return array */ public static function activeExtensions( $extensionType = false, eZINI $siteINI = null ) { if ( $siteINI === null ) { $siteINI = eZINI::instance(); } $activeExtensions = array(); if ( !$extensionType || $extensionType === 'default' ) { $activeExtensions = $siteINI->variable( 'ExtensionSettings', 'ActiveExtensions' ); } if ( !$extensionType || $extensionType === 'access' ) { $activeExtensions = array_merge( $activeExtensions, $siteINI->variable( 'ExtensionSettings', 'ActiveAccessExtensions' ) ); } if ( isset( $GLOBALS['eZActiveExtensions'] ) ) { $activeExtensions = array_merge( $activeExtensions, $GLOBALS['eZActiveExtensions'] ); } // return empty array as is to avoid further unneeded overhead if ( !isset( $activeExtensions[0] ) ) { return $activeExtensions; } // return array as is if ordering is disabled to avoid cache overhead $activeExtensions = array_unique( $activeExtensions ); if ( $siteINI->variable( 'ExtensionSettings', 'ExtensionOrdering' ) !== 'enabled' ) { // @todo Introduce a debug setting or re use existing dev mods to check that all extensions exists return $activeExtensions; } $cacheIdentifier = md5( serialize( $activeExtensions ) ); if ( isset ( self::$activeExtensionsCache[$cacheIdentifier] ) ) { return self::$activeExtensionsCache[$cacheIdentifier]; } // cache has to be stored by siteaccess + $extensionType $extensionDirectory = self::baseDirectory(); $expiryHandler = eZExpiryHandler::instance(); $phpCache = new eZPHPCreator( self::CACHE_DIR, "active_extensions_{$cacheIdentifier}.php" ); $expiryTime = $expiryHandler->hasTimestamp( 'active-extensions-cache' ) ? $expiryHandler->timestamp( 'active-extensions-cache' ) : 0; if ( !$phpCache->canRestore( $expiryTime ) ) { self::$activeExtensionsCache[$cacheIdentifier] = self::extensionOrdering( $activeExtensions ); // Check that all extensions defined actually exists before storing cache foreach ( self::$activeExtensionsCache[$cacheIdentifier] as $activeExtension ) { if ( !file_exists( $extensionDirectory . '/' . $activeExtension ) ) { eZDebug::writeError( "Extension '$activeExtension' does not exist, looked for directory '" . $extensionDirectory . '/' . $activeExtension . "'", __METHOD__ ); } } $phpCache->addVariable( 'activeExtensions', self::$activeExtensionsCache[$cacheIdentifier] ); $phpCache->store(); } else { $data = $phpCache->restore( array( 'activeExtensions' => 'activeExtensions' ) ); self::$activeExtensionsCache[$cacheIdentifier] = $data['activeExtensions']; } return self::$activeExtensionsCache[$cacheIdentifier]; }
/** * Returns the expiry timestamp for wildcard cache from eZExpiryHandler * @return int|bool the timestamp if set, false otherwise */ protected static function expiryTimestamp() { $handler = eZExpiryHandler::instance(); if ( $handler->hasTimestamp( self::CACHE_SIGNATURE ) ) { $ret = $handler->timestamp( self::CACHE_SIGNATURE ); } else { $ret = false; } return $ret; }
/** * Expires the translation cache * * @param int $timestamp An optional timestamp cache should be exired from. Current timestamp used by default * @param string $locale Optional translation's locale to expire specifically. Expires global ts cache by default. * * @return void */ public static function expireCache( $timestamp = false, $locale = null ) { eZExpiryHandler::registerShutdownFunction(); if ( $timestamp === false ) $timestamp = time(); $handler = eZExpiryHandler::instance(); if ( $locale ) $handler->setTimestamp( self::EXPIRY_KEY . '-' . $locale, $timestamp ); else $handler->setTimestamp( self::EXPIRY_KEY, $timestamp ); $handler->store(); self::resetGlobals(); }
function isImageTimestampValid($timestamp) { $expiryHandler = eZExpiryHandler::instance(); if ($expiryHandler->hasTimestamp('image-manager-alias')) { $aliasTimestamp = $expiryHandler->timestamp('image-manager-alias'); return $timestamp > $aliasTimestamp; } return true; }
public function __construct($location = null, array $options = array()) { $this->expiryHandler = eZExpiryHandler::instance(); parent::__construct($location, $options); }
/** * Clears active extensions list cache */ static function clearActiveExtensions($cacheItem) { eZExpiryHandler::registerShutdownFunction(); $handler = eZExpiryHandler::instance(); $handler->setTimestamp($cacheItem['expiry-key'], time()); $handler->store(); eZExtension::clearActiveExtensionsMemoryCache(); }
/** * Returns an array of limitations useable by the policy system * * @return array */ public static function limitations() { static $limitations; if ($limitations === null) { $db = eZDB::instance(); $dbName = md5($db->DB); $cacheDir = eZSys::cacheDirectory(); $phpCache = new eZPHPCreator($cacheDir, 'statelimitations_' . $dbName . '.php', '', array('clustering' => 'statelimitations')); $handler = eZExpiryHandler::instance(); $storedTimeStamp = $handler->hasTimestamp('state-limitations') ? $handler->timestamp('state-limitations') : false; $expiryTime = $storedTimeStamp !== false ? $storedTimeStamp : 0; if ($phpCache->canRestore($expiryTime)) { $var = $phpCache->restore(array('state_limitations' => 'state_limitations')); $limitations = $var['state_limitations']; } else { $limitations = array(); $groups = self::fetchByConditions(array("identifier NOT LIKE 'ez%'"), false, false); foreach ($groups as $group) { $name = 'StateGroup_' . $group->attribute('identifier'); $limitations[$name] = array('name' => $name, 'values' => array(), 'class' => __CLASS__, 'function' => 'limitationValues', 'parameter' => array($group->attribute('id'))); } $phpCache->addVariable('state_limitations', $limitations); $phpCache->store(); } if ($storedTimeStamp === false) { $handler->setTimestamp('state-limitations', time()); } } return $limitations; }
function revertFromTemporaryVersion() { $temporaryVersion = eZRole::fetch(0, $this->attribute('id')); if ($temporaryVersion === null) { return 0; } $this->removePolicies(); $this->setAttribute('name', $temporaryVersion->attribute('name')); $this->setAttribute('is_new', 0); $db = eZDB::instance(); $db->begin(); $this->store(); $query = "UPDATE ezpolicy\n SET role_id = " . $this->attribute('id') . "\n WHERE role_id = " . $temporaryVersion->attribute('id'); $db->query($query); $temporaryVersion->removePolicies(false); $temporaryVersion->remove(); $db->commit(); // Expire role cache eZExpiryHandler::registerShutdownFunction(); $handler = eZExpiryHandler::instance(); $handler->setTimestamp('user-info-cache', time()); $handler->setTimestamp('user-class-cache', time()); $handler->store(); }
public static function fetchContentTreeMenuExpiry() { $expiryHandler = eZExpiryHandler::instance(); if (!$expiryHandler->hasTimestamp('content-tree-menu')) { $expiryHandler->setTimestamp('content-tree-menu', time()); $expiryHandler->store(); } return array('result' => $expiryHandler->timestamp('content-tree-menu')); }
/** * Expires the translation cache * * @param int $timestamp An optional timestamp cache should be exired from. Current timestamp used by default * * @return void */ public static function expireCache($timestamp = false) { eZExpiryHandler::registerShutdownFunction(); if ($timestamp === false) { $timestamp = time(); } $handler = eZExpiryHandler::instance(); $handler->setTimestamp(self::EXPIRY_KEY, $timestamp); $handler->store(); self::$expiryTimestamp = $timestamp; }
/** * Returns the class identifier hash for the current database. * If it is outdated or non-existent, the method updates/generates the file * * @static * @since Version 4.1 * @access protected * @return array Returns hash of classidentifier => classid */ protected static function classIdentifiersHash() { if (self::$identifierHash === null) { $db = eZDB::instance(); $dbName = md5($db->DB); $cacheDir = eZSys::cacheDirectory(); $phpCache = new eZPHPCreator($cacheDir, 'classidentifiers_' . $dbName . '.php', '', array('clustering' => 'classidentifiers')); eZExpiryHandler::registerShutdownFunction(); $handler = eZExpiryHandler::instance(); $expiryTime = 0; if ($handler->hasTimestamp('class-identifier-cache')) { $expiryTime = $handler->timestamp('class-identifier-cache'); } if ($phpCache->canRestore($expiryTime)) { $var = $phpCache->restore(array('identifierHash' => 'identifier_hash')); self::$identifierHash = $var['identifierHash']; } else { // Fetch identifier/id pair from db $query = "SELECT id, identifier FROM ezcontentclass where version=0"; $identifierArray = $db->arrayQuery($query); self::$identifierHash = array(); foreach ($identifierArray as $identifierRow) { self::$identifierHash[$identifierRow['identifier']] = $identifierRow['id']; } // Store identifier list to cache file $phpCache->addVariable('identifier_hash', self::$identifierHash); $phpCache->store(); } } return self::$identifierHash; }
/** * Clears all content class attribute related caches * * @param int $contentClassAttributeID Specific attribute ID to clear cache for * @param int $contentClassID Specific attribute ID to clear cache for * * @return void * @since 4.2 */ public static function expireCache( $contentClassAttributeID = false, $contentClassID = false) { unset( $GLOBALS['eZContentClassAttributeCacheListFull'] ); if ( $contentClassID !== false ) { if ( isset( $GLOBALS['eZContentClassAttributeCacheList'][$contentClassID] ) ) { unset( $GLOBALS['eZContentClassAttributeCacheList'][$contentClassID] ); } } else { unset( $GLOBALS['eZContentClassAttributeCacheList'] ); } if ( $contentClassAttributeID !== false ) { if ( isset( $GLOBALS['eZContentClassAttributeCache'][$contentClassAttributeID] ) ) { unset( $GLOBALS['eZContentClassAttributeCache'][$contentClassAttributeID] ); } } else { unset( $GLOBALS['eZContentClassAttributeCache'] ); } // expire cache file by timestamp $handler = eZExpiryHandler::instance(); $handler->setTimestamp( 'class-identifier-cache', time() + 1 ); $handler->store(); // expire local, in-memory cache self::$identifierHash = null; }
/** * Expire user access / info cache globally */ static function cleanupCache() { eZExpiryHandler::registerShutdownFunction(); $handler = eZExpiryHandler::instance(); $handler->setTimestamp('user-info-cache', time()); $handler->store(); }
/** * Expires the translation cache * * @param int $timestamp An optional timestamp cache should be exired from. Current timestamp used by default * @param string $locale Optional translation's locale to expire specifically. Expires global ts cache by default. * * @return void */ public static function expireCache($timestamp = false, $locale = null) { if ($timestamp === false) { $timestamp = time(); } $handler = eZExpiryHandler::instance(); if ($locale) { $handler->setTimestamp(self::EXPIRY_KEY . '-' . $locale, $timestamp); } else { $handler->setTimestamp(self::EXPIRY_KEY, $timestamp); } $handler->store(); self::resetGlobals(); }
function isImageTimestampValid( $timestamp ) { eZExpiryHandler::registerShutdownFunction(); $expiryHandler = eZExpiryHandler::instance(); if ( $expiryHandler->hasTimestamp( 'image-manager-alias' ) ) { $aliasTimestamp = $expiryHandler->timestamp( 'image-manager-alias' ); return ( $timestamp > $aliasTimestamp ); } return true; }
/** * Refreshes/reloads cache and other state information periodically. */ private function refreshCacheStateInfo() { if (time() < $this->lastRefreshTimestamp + $this->sleepInterval) { return; } // Reload expiry timestamps eZExpiryHandler::instance()->restore(); $this->lastRefreshTimestamp = time(); }