00001 <?php 00002 // 00003 // Definition of eZSubtreeCache class 00004 // 00005 // Created on: <21-Mar-2005 16:53:41 dl> 00006 // 00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00008 // SOFTWARE NAME: eZ publish 00009 // SOFTWARE RELEASE: 3.9.x 00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 00011 // SOFTWARE LICENSE: GNU General Public License v2.0 00012 // NOTICE: > 00013 // This program is free software; you can redistribute it and/or 00014 // modify it under the terms of version 2.0 of the GNU General 00015 // Public License as published by the Free Software Foundation. 00016 // 00017 // This program is distributed in the hope that it will be useful, 00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 // GNU General Public License for more details. 00021 // 00022 // You should have received a copy of version 2.0 of the GNU General 00023 // Public License along with this program; if not, write to the Free 00024 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00025 // MA 02110-1301, USA. 00026 // 00027 // 00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00029 // 00030 00031 /*! \file ezsubtreecache.php 00032 */ 00033 00034 /*! 00035 \class eZSubtreeCache ezsubtreecache.php 00036 \brief The class eZSubtreeCache does 00037 00038 */ 00039 00040 include_once( 'lib/eztemplate/classes/eztemplatecachefunction.php' ); 00041 00042 class eZSubtreeCache 00043 { 00044 /*! 00045 Constructor 00046 */ 00047 function eZSubtreeCache() 00048 { 00049 } 00050 00051 /*! 00052 \static 00053 Removes caches which were created using 'cache-block' operator with 'subtree_expiry' parameter. 00054 \a $nodeList is an array of node's ids. It is used to determine caches to remove. 00055 if $nodeList is not an array or if $nodeList is empty all 'subtree_expiry' caches will be removed. 00056 */ 00057 function cleanupByNodeIDs( &$nodeIDList ) 00058 { 00059 if ( !is_array( $nodeIDList ) || count( $nodeIDList ) === 0 ) 00060 { 00061 eZSubtreeCache::cleanupAll(); 00062 } 00063 else 00064 { 00065 include_once( 'kernel/classes/ezcontentobjecttreenode.php' ); 00066 $nodeList = eZContentObjectTreeNode::fetch( $nodeIDList ); 00067 if ( $nodeList ) 00068 { 00069 if ( !is_array( $nodeList ) ) 00070 $nodeList = array( $nodeList ); 00071 00072 eZSubtreeCache::cleanup( $nodeList ); 00073 } 00074 } 00075 } 00076 00077 /*! 00078 \static 00079 Clears template block caches with 'subtree_ezpiry' parameter for nodes in the $nodeList. 00080 Note: if 'DelayedCacheBlockCleanup' setting is enabled then expiried caches will be renamed only 00081 (removing from disk should be made, for example, by cronjob). 00082 */ 00083 function cleanup( &$nodeList ) 00084 { 00085 if ( !is_array( $nodeList ) ) 00086 return; 00087 00088 $cacheDir = eZTemplateCacheFunction::templateBlockCacheDir(); 00089 00090 $keys = array_keys( $nodeList ); 00091 foreach ( $keys as $key ) 00092 { 00093 $node =& $nodeList[$key]; 00094 $pathString = $node->attribute( 'path_string' ); 00095 $pathString = trim( $pathString, '/' ); 00096 $nodeListID = explode( '/', $pathString ); 00097 00098 foreach( $nodeListID as $nodeID ) 00099 { 00100 $cachePath = $cacheDir . eZTemplateCacheFunction::subtreeCacheSubDirForNode( $nodeID ); 00101 eZSubtreeCache::cleanupCacheDir( $cachePath ); 00102 } 00103 } 00104 } 00105 00106 /*! 00107 \static 00108 Removes all caches which were created using 'cache-block' operator with 'subtree_expiry' parameter. 00109 */ 00110 function cleanupAll() 00111 { 00112 $subtreeCacheDir = eZTemplateCacheFunction::templateBlockCacheDir() . eZTemplateCacheFunction::subtreeCacheBaseSubDir(); 00113 eZSubtreeCache::cleanupCacheDir( $subtreeCacheDir ); 00114 } 00115 00116 /*! 00117 \static 00118 If DelayedCacheBlockCleanup is enables just renames $cachDir, otherwise removes $cacheDir from disk. 00119 */ 00120 function cleanupCacheDir( $cacheDir ) 00121 { 00122 if ( file_exists( $cacheDir ) ) 00123 { 00124 include_once( 'lib/ezutils/classes/ezini.php' ); 00125 $ini =& eZINI::instance(); 00126 if ( $ini->variable( 'TemplateSettings', 'DelayedCacheBlockCleanup' ) === 'enabled' ) 00127 { 00128 // VS-DBFILE : FIXME: this will not work if clustering enabled 00129 eZSubtreeCache::renameDir( $cacheDir ); 00130 } 00131 else 00132 eZSubtreeCache::removeExpiryCacheFromDisk( $cacheDir ); 00133 } 00134 } 00135 00136 /*! 00137 \static 00138 $dir is a path to the cache directory which should be renamed. 00139 $dir is relative to the root directiry of 'subtree' cache. 00140 */ 00141 function renameDir( $dir ) 00142 { 00143 // just rename. Actual removing will be performed by cronjob. 00144 00145 if ( $dir ) 00146 { 00147 // VS-DBFILE : FIXME: this will not work if clustering enabled 00148 00149 include_once( 'lib/ezfile/classes/ezfile.php' ); 00150 $expiryCacheDir = eZTemplateCacheFunction::expiryTemplateBlockCacheDir(); 00151 00152 $uniqid = md5( uniqid( 'ezpsubtreecache'. getmypid(), true ) ); 00153 $expiryCacheDir .= '/' . $uniqid[0] . '/' . $uniqid[1] . '/' . $uniqid[2] . '/' . $uniqid; 00154 00155 if ( !file_exists( $expiryCacheDir ) ) 00156 { 00157 $ini =& eZINI::instance(); 00158 $perm = octdec( $ini->variable( 'FileSettings', 'StorageDirPermissions' ) ); 00159 eZDir::mkdir( $expiryCacheDir, $perm, true ); 00160 } 00161 eZFile::rename( $dir, $expiryCacheDir ); 00162 } 00163 else 00164 { 00165 eZDebug::writeWarning( "$dir should be a directory. Template-block caches for 'subtree_expiry' are not removed.", "eZSubtreeCache::renameDir" ); 00166 } 00167 } 00168 00169 /*! 00170 \static 00171 */ 00172 function removeAllExpiryCacheFromDisk() 00173 { 00174 $expiryCachePath = eZTemplateCacheFunction::expiryTemplateBlockCacheDir(); 00175 eZSubtreeCache::removeExpiryCacheFromDisk( $expiryCachePath ); 00176 } 00177 00178 /*! 00179 \static 00180 $expiryCachePath is a path to directory with cache that should be removed 00181 */ 00182 function removeExpiryCacheFromDisk( $expiryCachePath ) 00183 { 00184 require_once( 'kernel/classes/ezclusterfilehandler.php' ); 00185 $fileHandler = eZClusterFileHandler::instance(); 00186 $fileHandler->fileDelete( $expiryCachePath ); 00187 } 00188 } 00189 00190 ?>
1.6.3