Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
    static function handle( $cachePath, $nodeID, $ttl, $useGlobalExpiry = true )
    {
        $globalExpiryTime = -1;
        eZExpiryHandler::registerShutdownFunction();
        if ( $useGlobalExpiry )
        {
            $globalExpiryTime = eZExpiryHandler::getTimestamp( 'template-block-cache', -1 );
        }

        $cacheHandler = eZClusterFileHandler::instance( $cachePath );

        $subtreeExpiry = -1;
        // Perform an extra check if the DB handler is in use,
        // get the modified_subnode value from the specified node ($nodeID)
        // and use it as an extra expiry value.
        if ( $cacheHandler instanceof eZDBFileHandler or $cacheHandler instanceof eZDFSFileHandler )
        {
            $subtreeExpiry = eZTemplateCacheBlock::getSubtreeModification( $nodeID );
        }
        $globalExpiryTime = max( eZExpiryHandler::getTimestamp( 'global-template-block-cache', -1 ), // This expiry value is the true global expiry for cache-blocks
                                 $globalExpiryTime,
                                 $subtreeExpiry );

        if ( $ttl == 0 )
            $ttl = -1;
        return array( &$cacheHandler,
                      $cacheHandler->processCache( array( 'eZTemplateCacheBlock', 'retrieveContent' ), null,
                                                   $ttl, $globalExpiryTime ) );
    }
 /**
  * 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();
     }
 }
Ejemplo n.º 4
0
 /**
  * Direct store instruction.
  * Makes the registry to be stored
  * @see lib/ezc/Cache/src/storage/ezcCacheStorageMemory::store()
  */
 public function store($id, $data, $attributes = array())
 {
     $this->forceStoreRegistry = true;
     $storeResult = parent::store($id, $data, $attributes);
     // Update clustered expiry timestamp
     $expiryTime = time() + $this->properties['options']['ttl'];
     $this->expiryHandler->setTimestamp(ezpRestRouter::ROUTE_CACHE_KEY, $expiryTime);
     return $storeResult;
 }
 /**
  * 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'));
 }
 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'));
 }
Ejemplo n.º 8
0
 /**
  * Runs the shutdown process
  */
 protected function shutdown($reInitialize = true)
 {
     eZExecution::cleanup();
     eZExecution::setCleanExit();
     eZExpiryHandler::shutdown();
     if ($reInitialize) {
         $this->isInitialized = false;
     }
 }
Ejemplo n.º 9
0
 /**
  * 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;
 }
Ejemplo n.º 10
0
 /**
  * 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;
 }
Ejemplo n.º 12
0
    /**
     * 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();
    }
Ejemplo n.º 13
0
 function shutdown($exitCode = false, $exitText = false)
 {
     $cli = eZCLI::instance();
     if (class_exists('eZDB') and eZDB::hasInstance()) {
         $db = eZDB::instance(false, array('show_errors' => false));
         // Perform transaction check
         $transactionCounterCheck = eZDB::checkTransactionCounter();
         if (isset($transactionCounterCheck['error'])) {
             $cli->error($transactionCounterCheck['error']);
         }
         if ($this->UseSession and $db->isConnected()) {
             eZUser::logoutCurrent();
             eZSession::remove();
         }
     }
     $webOutput = $cli->isWebOutput();
     if ($this->UseDebugOutput or eZDebug::isDebugEnabled()) {
         if ($this->DebugMessage) {
             fputs(STDERR, $this->DebugMessage);
         }
         fputs(STDERR, eZDebug::printReport(false, $webOutput, true, $this->AllowedDebugLevels, $this->UseDebugAccumulators, $this->UseDebugTimingPoints, $this->UseIncludeFiles));
     }
     eZExecution::cleanup();
     eZExecution::setCleanExit();
     eZExpiryHandler::shutdown();
     $this->setIsInitialized(false);
     if ($exitCode !== false) {
         $this->ExitCode = $exitCode;
     }
     if ($this->ExitCode !== false) {
         if ($exitText !== false) {
             $cli->output($exitText);
         }
         exit($this->ExitCode);
     }
 }
Ejemplo n.º 14
0
 /**
  * Expire user access / info cache globally
  */
 static function cleanupCache()
 {
     $handler = eZExpiryHandler::instance();
     $handler->setTimestamp('user-info-cache', time());
     $handler->store();
 }
 function processCached($tpl, $functionChildren, $rootNamespace, $currentNamespace, $placementString, $keys, $subtreeExpiry, $expiry, $ignoreContentExpiry)
 {
     // Fetch the current siteaccess
     $accessName = false;
     if (isset($GLOBALS['eZCurrentAccess']['name'])) {
         $accessName = $GLOBALS['eZCurrentAccess']['name'];
     }
     if ($keys === null) {
         $keyArray = array($placementString, $accessName);
     } else {
         $keyArray = array($keys, $placementString, $accessName);
     }
     $nodeID = $subtreeExpiry ? eZTemplateCacheBlock::decodeNodeID($subtreeExpiry) : false;
     $phpPath = eZTemplateCacheBlock::cachePath(eZTemplateCacheBlock::keyString($keyArray), $nodeID);
     $ttl = $expiry > 0 ? $expiry : null;
     if ($subtreeExpiry !== null) {
         $ignoreContentExpiry = true;
     } else {
         if ($ignoreContentExpiry === null) {
             $ignoreContentExpiry = false;
         }
     }
     $globalExpiryTime = -1;
     if ($ignoreContentExpiry == false) {
         $globalExpiryTime = eZExpiryHandler::getTimestamp('template-block-cache', -1);
     }
     $globalExpiryTime = max(eZExpiryHandler::getTimestamp('global-template-block-cache', -1), $globalExpiryTime);
     // Check if we can restore
     $cacheFile = eZClusterFileHandler::instance($phpPath);
     $args = array("tpl" => $tpl, "functionChildren" => $functionChildren, "rootNamespace" => $rootNamespace, "currentNamespace" => $currentNamespace);
     return $cacheFile->processCache(array('eZTemplateCacheBlock', 'retrieveContent'), array($this, 'generateProcessedContent'), $ttl, $globalExpiryTime, $args);
 }
Ejemplo n.º 16
0
 /**
  * Registers the shutdown function.
  * @see eZExpiryHandler::shutdown()
  */
 public static function registerShutdownFunction()
 {
     if (!eZExpiryHandler::$isShutdownFunctionRegistered) {
         register_shutdown_function(array('eZExpiryHandler', 'shutdown'));
         eZExpiryHandler::$isShutdownFunctionRegistered = true;
     }
 }
Ejemplo n.º 17
0
 /**
  * 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()");
 }
Ejemplo n.º 18
0
    /**
     * 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;
    }
Ejemplo n.º 19
0
 /**
  * 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;
 }
Ejemplo n.º 20
0
 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();
 }
Ejemplo n.º 21
0
    /**
     * 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];
    }
 /**
  * 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();
 }
Ejemplo n.º 23
0
 /**
  * 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;
 }
Ejemplo n.º 24
0
 function isImageTimestampValid($timestamp)
 {
     $expiryHandler = eZExpiryHandler::instance();
     if ($expiryHandler->hasTimestamp('image-manager-alias')) {
         $aliasTimestamp = $expiryHandler->timestamp('image-manager-alias');
         return $timestamp > $aliasTimestamp;
     }
     return true;
 }
Ejemplo n.º 25
0
 /**
  * Expire user access / info cache globally
  */
 static function cleanupCache()
 {
     eZExpiryHandler::registerShutdownFunction();
     $handler = eZExpiryHandler::instance();
     $handler->setTimestamp('user-info-cache', time());
     $handler->store();
 }
Ejemplo n.º 26
0
 /**
  * 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();
 }
Ejemplo n.º 27
0
//   This program is free software; you can redistribute it and/or
//   modify it under the terms of version 2.0  of the GNU General
//   Public License as published by the Free Software Foundation.
//
//   This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   GNU General Public License for more details.
//
//   You should have received a copy of version 2.0 of the GNU General
//   Public License along with this program; if not, write to the Free
//   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
//   MA 02110-1301, USA.
// ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
//
eZExpiryHandler::registerShutdownFunction();
if (!defined('MAX_AGE')) {
    define('MAX_AGE', 86400);
}
function washJS($string)
{
    return str_replace(array("\\", "/", "\n", "\t", "\r", "\\b", "\f", '"'), array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\\"'), $string);
}
function arrayToJSON($array)
{
    if ($array) {
        $result = array();
        $resultDict = array();
        $isDict = false;
        $index = 0;
        foreach ($array as $key => $value) {
 /**
  * Called at the end of execution and will store the data if it is modified.
  */
 static function shutdown()
 {
     if (eZExpiryHandler::hasInstance()) {
         eZExpiryHandler::instance()->store();
     }
 }
Ejemplo n.º 29
0
 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;
 }
 /**
  * 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;
 }