$script = eZScript::instance( array( 'description' => ( "eZ Publish static cache generator\n" . "\n" . "./bin/makestaticcache.php --siteaccess user" ), 'use-session' => false, 'use-modules' => true, 'use-extensions' => true ) ); $script->startup(); $options = $script->getOptions( "[f|force]", "", array( 'force' => "Force generation of cache files even if they already exist." ) ); $force = $options['force']; $script->initialize(); $staticCache = new eZStaticCache(); $staticCache->generateCache( $force, false, $cli, false ); if ( !$force ) { $staticCache->generateAlwaysUpdatedCache( false, $cli, false ); } eZStaticCache::executeActions(); $script->shutdown(); ?>
static function clearObjectViewCache( $objectIDList, $versionNum = true, $additionalNodeList = false ) { eZDebug::accumulatorStart( 'node_cleanup_list', '', 'Node cleanup list' ); $nodeList = array(); foreach ($objectIDList as $objectID) { $tmp = eZContentCacheManager::nodeList( $objectID, $versionNum ); if (is_array($tmp) ) { $nodeList = array_merge($nodeList, $tmp); } } if ( $nodeList === false and !is_array( $additionalNodeList ) ) { return false; } if ( $nodeList === false ) { $nodeList = array(); } if ( is_array( $additionalNodeList ) ) { array_splice( $nodeList, count( $nodeList ), 0, $additionalNodeList ); } if ( count( $nodeList ) == 0 ) { return false; } $nodeList = array_unique( $nodeList ); eZDebug::accumulatorStop( 'node_cleanup_list' ); eZDebugSetting::writeDebug( 'kernel-content-edit', count( $nodeList ), "count in nodeList" ); $ini = eZINI::instance(); if ( $ini->variable( 'ContentSettings', 'StaticCache' ) == 'enabled' ) { $staticCache = new eZStaticCache(); $staticCache->generateAlwaysUpdatedCache(); $staticCache->generateNodeListCache( $nodeList ); } eZDebug::accumulatorStart( 'node_cleanup', '', 'Node cleanup' ); eZContentObject::expireComplexViewModeCache(); $cleanupValue = eZContentCache::calculateCleanupValue( count( $nodeList ) ); if ( eZContentCache::inCleanupThresholdRange( $cleanupValue ) ) { eZContentCache::cleanup( $nodeList ); } else { eZContentObject::expireAllViewCache(); } eZDebug::accumulatorStop( 'node_cleanup' ); return true; }
function removeThis() { $ini = eZINI::instance(); $object = $this->object(); $nodeID = $this->attribute('node_id'); if (eZAudit::isAuditEnabled()) { // Set audit params. $objectID = $object->attribute('id'); $objectName = $object->attribute('name'); eZAudit::writeAudit('content-delete', array('Node ID' => $nodeID, 'Object ID' => $objectID, 'Content Name' => $objectName, 'Comment' => 'Removed the current node: eZContentObjectTreeNode::removeNode()')); } $db = eZDB::instance(); $db->begin(); $nodePath = $this->attribute('path_string'); $childrensPath = $nodePath; $pathString = " path_string like '{$childrensPath}%' "; $urlAlias = $this->attribute('url_alias'); // Remove static cache if ($ini->variable('ContentSettings', 'StaticCache') == 'enabled') { $staticCache = new eZStaticCache(); $staticCache->removeURL("/" . $urlAlias); $staticCache->generateAlwaysUpdatedCache(); $parent = $this->fetchParent(); } $db->query("DELETE FROM ezcontentobject_tree\n WHERE {$pathString} OR\n path_string = '{$nodePath}'"); // Re-cache parent node if ($ini->variable('ContentSettings', 'StaticCache') == 'enabled') { if ($parent) { $staticCache->cacheURL("/" . $parent->urlAlias()); } } // Clean up URL alias entries eZURLAliasML::removeByAction('eznode', $nodeID); // Clean up content cache eZContentCacheManager::clearContentCacheIfNeeded($this->attribute('contentobject_id')); // clean up user cache if (in_array($object->attribute('contentclass_id'), eZUser::contentClassIDs())) { eZUser::removeSessionData($object->attribute('id')); eZUser::purgeUserCacheByUserId($object->attribute('id')); } $parentNode = $this->attribute('parent'); if (is_object($parentNode)) { eZContentCacheManager::clearContentCacheIfNeeded($parentNode->attribute('contentobject_id')); $parentNode->updateAndStoreModified(); } // Clean up policies and limitations eZRole::cleanupByNode($this); // Clean up recent items eZContentBrowseRecent::removeRecentByNodeID($nodeID); // Clean up bookmarks eZContentBrowseBookmark::removeByNodeID($nodeID); // Clean up tip-a-friend counter eZTipafriendCounter::removeForNode($nodeID); // Clean up view counter eZViewCounter::removeCounter($nodeID); $db->commit(); }
static function generateObjectViewCache($objectID) { // Generate the view cache $ini = eZINI::instance(); $object = eZContentObject::fetch($objectID); $user = eZUser::currentUser(); eZDebug::accumulatorStart('generate_cache', '', 'Generating view cache'); if ($ini->variable('ContentSettings', 'PreViewCache') == 'enabled') { $preCacheSiteaccessArray = $ini->variable('ContentSettings', 'PreCacheSiteaccessArray'); $currentSiteAccess = $GLOBALS['eZCurrentAccess']; // This is the default view parameters for content/view $viewParameters = array('offset' => 0, 'year' => false, 'month' => false, 'day' => false, 'namefilter' => false); if (is_array($preCacheSiteaccessArray) && count($preCacheSiteaccessArray) > 0) { foreach ($preCacheSiteaccessArray as $changeToSiteAccess) { $newSiteAccess = $currentSiteAccess; $newSiteAccess['name'] = $changeToSiteAccess; unset($newSiteAccess['uri_part']); //eZSiteAccess::load() will take care of setting correct one eZSiteAccess::load($newSiteAccess); $tpl = eZTemplate::factory(); // Get the sitedesign and cached view preferences for this siteaccess $siteini = eZINI::instance('site.ini'); $cachedViewPreferences = $siteini->variable('ContentSettings', 'CachedViewPreferences'); $language = false; // Needs to be specified if you want to generate the cache for a specific language $viewMode = 'full'; $assignedNodes = $object->assignedNodes(); foreach ($assignedNodes as $node) { // We want to generate the cache for the specified user $previewCacheUsers = $ini->variable('ContentSettings', 'PreviewCacheUsers'); foreach ($previewCacheUsers as $previewCacheUserID) { // If the text is 'anon' we need to fetch the Anonymous user ID. if ($previewCacheUserID === 'anonymous') { $previewCacheUserID = $siteini->variable("UserSettings", "AnonymousUserID"); $previewCacheUser = eZUser::fetch($previewCacheUserID); } else { if ($previewCacheUserID === 'current') { $previewCacheUser = $user; } else { $previewCacheUser = eZUser::fetch($previewCacheUserID); } } if (!$previewCacheUser) { continue; } // Before we generate the view cache we must change the currently logged in user to $previewCacheUser // If not the templates might read in wrong personalized data (preferences etc.) eZUser::setCurrentlyLoggedInUser($previewCacheUser, $previewCacheUser->attribute('contentobject_id')); // Cache the current node $cacheFileArray = eZNodeviewfunctions::generateViewCacheFile($previewCacheUser, $node->attribute('node_id'), 0, false, $language, $viewMode, $viewParameters, $cachedViewPreferences); $tmpRes = eZNodeviewfunctions::generateNodeView($tpl, $node, $node->attribute('object'), $language, $viewMode, 0, $cacheFileArray['cache_dir'], $cacheFileArray['cache_path'], true, $viewParameters); // Cache the parent node $parentNode = $node->attribute('parent'); $objectID = $parentNode->attribute('contentobject_id'); // if parent objectID is null or is 0 we should not create cache. if ($objectID) { $cacheFileArray = eZNodeviewfunctions::generateViewCacheFile($previewCacheUser, $parentNode->attribute('node_id'), 0, false, $language, $viewMode, $viewParameters, $cachedViewPreferences); $tmpRes = eZNodeviewfunctions::generateNodeView($tpl, $parentNode, $parentNode->attribute('object'), $language, $viewMode, 0, $cacheFileArray['cache_dir'], $cacheFileArray['cache_path'], true, $viewParameters); } } } } // Restore the old user as the current one eZUser::setCurrentlyLoggedInUser($user, $user->attribute('contentobject_id')); // restore siteaccess eZSiteAccess::load($currentSiteAccess); } } if ($ini->variable('ContentSettings', 'StaticCache') == 'enabled') { $nodes = array(); $ini = eZINI::instance(); $staticCache = new eZStaticCache(); $useURLAlias =& $GLOBALS['eZContentObjectTreeNodeUseURLAlias']; $pathPrefix = $ini->variable('SiteAccessSettings', 'PathPrefix'); if (!isset($useURLAlias)) { $useURLAlias = $ini->variable('URLTranslator', 'Translation') == 'enabled'; } eZContentCacheManager::nodeListForObject($object, true, self::CLEAR_DEFAULT, $nodes, $handledObjectList); // If no nodes returns it means that ClearCacheMethod = self::CLEAR_NO_CACHE if (count($nodes)) { foreach ($nodes as $nodeID) { if ($useURLAlias) { $oNode = eZContentObjectTreeNode::fetch($nodeID, false, true); if (!isset($oNode)) { continue; } $urlAlias = $oNode->urlAlias(); if ($pathPrefix != '') { $tempAlias = substr($pathPrefix, strlen($pathPrefix) - 1) == '/' ? $urlAlias . '/' : $urlAlias; if (strncmp($tempAlias, $pathPrefix, strlen($tempAlias)) == 0) { $urlAlias = substr($tempAlias, strlen($pathPrefix)); } } } else { $urlAlias = 'content/view/full/' . $nodeID; } $staticCache->cacheURL('/' . $urlAlias, $nodeID); } $staticCache->generateAlwaysUpdatedCache(); } } eZDebug::accumulatorStop('generate_cache'); }