[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/kernel/classes/ -> ezsubtreecache.php (source)

   1  <?php
   2  //
   3  // Definition of eZSubtreeCache class
   4  //
   5  // Created on: <21-Mar-2005 16:53:41 dl>
   6  //
   7  // SOFTWARE NAME: eZ publish
   8  // SOFTWARE RELEASE: 3.9.0
   9  // BUILD VERSION: 17785
  10  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
  11  // SOFTWARE LICENSE: GNU General Public License v2.0
  12  // NOTICE: >
  13  //   This program is free software; you can redistribute it and/or
  14  //   modify it under the terms of version 2.0  of the GNU General
  15  //   Public License as published by the Free Software Foundation.
  16  //
  17  //   This program is distributed in the hope that it will be useful,
  18  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  19  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20  //   GNU General Public License for more details.
  21  //
  22  //   You should have received a copy of version 2.0 of the GNU General
  23  //   Public License along with this program; if not, write to the Free
  24  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  25  //   MA 02110-1301, USA.
  26  //
  27  //
  28  
  29  /*! \file ezsubtreecache.php
  30  */
  31  
  32  /*!
  33    \class eZSubtreeCache ezsubtreecache.php
  34    \brief The class eZSubtreeCache does
  35  
  36  */
  37  
  38  include_once ( 'lib/eztemplate/classes/eztemplatecachefunction.php' );
  39  
  40  class eZSubtreeCache
  41  {
  42      /*!
  43       Constructor
  44      */
  45      function eZSubtreeCache()
  46      {
  47      }
  48  
  49      /*!
  50       \static
  51       Removes caches which were created using 'cache-block' operator with 'subtree_expiry' parameter.
  52       \a $nodeList is an array of node's ids. It is used to determine caches to remove.
  53       if $nodeList is not an array or if $nodeList is empty all 'subtree_expiry' caches will be removed.
  54      */
  55      function cleanupByNodeIDs( &$nodeIDList )
  56      {
  57          if ( !is_array( $nodeIDList ) || count( $nodeIDList ) === 0 )
  58          {
  59              eZSubtreeCache::cleanupAll();
  60          }
  61          else
  62          {
  63              include_once ( 'kernel/classes/ezcontentobjecttreenode.php' );
  64              $nodeList = eZContentObjectTreeNode::fetch( $nodeIDList );
  65              if ( $nodeList )
  66              {
  67                  if ( !is_array( $nodeList ) )
  68                      $nodeList = array( $nodeList );
  69  
  70                  eZSubtreeCache::cleanup( $nodeList );
  71              }
  72          }
  73      }
  74  
  75      /*!
  76       \static
  77       Clears template block caches with 'subtree_ezpiry' parameter for nodes in the $nodeList.
  78       Note: if 'DelayedCacheBlockCleanup' setting is enabled then expiried caches will be renamed only
  79       (removing from disk should be made, for example, by cronjob).
  80      */
  81      function cleanup( &$nodeList )
  82      {
  83          if ( !is_array( $nodeList ) )
  84              return;
  85  
  86          $cacheDir = eZTemplateCacheFunction::templateBlockCacheDir();
  87  
  88          $keys = array_keys( $nodeList );
  89          foreach ( $keys as $key )
  90          {
  91              $node =& $nodeList[$key];
  92              $pathString = $node->attribute( 'path_string' );
  93              $pathString = trim( $pathString, '/' );
  94              $nodeListID = explode( '/', $pathString );
  95  
  96              foreach( $nodeListID as $nodeID )
  97              {
  98                  $cachePath = $cacheDir . eZTemplateCacheFunction::subtreeCacheSubDirForNode( $nodeID );
  99                  eZSubtreeCache::cleanupCacheDir( $cachePath );
 100              }
 101          }
 102      }
 103  
 104      /*!
 105       \static
 106       Removes all caches which were created using 'cache-block' operator with 'subtree_expiry' parameter.
 107      */
 108      function cleanupAll()
 109      {
 110          $subtreeCacheDir = eZTemplateCacheFunction::templateBlockCacheDir() . eZTemplateCacheFunction::subtreeCacheBaseSubDir();
 111          eZSubtreeCache::cleanupCacheDir( $subtreeCacheDir );
 112      }
 113  
 114      /*!
 115       \static
 116       If DelayedCacheBlockCleanup is enables just renames $cachDir, otherwise removes $cacheDir from disk.
 117      */
 118      function cleanupCacheDir( $cacheDir )
 119      {
 120          if ( file_exists( $cacheDir ) )
 121          {
 122              include_once ( 'lib/ezutils/classes/ezini.php' );
 123              $ini =& eZINI::instance();
 124              if ( $ini->variable( 'TemplateSettings', 'DelayedCacheBlockCleanup' ) === 'enabled' )
 125              {
 126                  // VS-DBFILE : FIXME: this will not work if clustering enabled
 127                  eZSubtreeCache::renameDir( $cacheDir );
 128              }
 129              else
 130                  eZSubtreeCache::removeExpiryCacheFromDisk( $cacheDir );
 131          }
 132      }
 133  
 134      /*!
 135       \static
 136       $dir is a path to the cache directory which should be renamed.
 137       $dir is relative to the root directiry of 'subtree' cache.
 138      */
 139      function renameDir( $dir )
 140      {
 141          // just rename. Actual removing will be performed by cronjob.
 142  
 143          if ( $dir )
 144          {
 145              // VS-DBFILE : FIXME: this will not work if clustering enabled
 146  
 147              include_once ( 'lib/ezfile/classes/ezfile.php' );
 148              $expiryCacheDir = eZTemplateCacheFunction::expiryTemplateBlockCacheDir();
 149  
 150              $uniqid = md5( uniqid( 'ezpsubtreecache'. getmypid(), true ) );
 151              $expiryCacheDir .= '/' . $uniqid[0] . '/' . $uniqid[1] . '/' . $uniqid[2] . '/' . $uniqid;
 152  
 153              if ( !file_exists( $expiryCacheDir ) )
 154              {
 155                  $ini =& eZINI::instance();
 156                  $perm = octdec( $ini->variable( 'FileSettings', 'StorageDirPermissions' ) );
 157                  eZDir::mkdir( $expiryCacheDir, $perm, true );
 158              }
 159              eZFile::rename( $dir, $expiryCacheDir );
 160          }
 161          else
 162          {
 163              eZDebug::writeWarning( "$dir should be a directory. Template-block caches for 'subtree_expiry' are not removed.", "eZSubtreeCache::renameDir" );
 164          }
 165      }
 166  
 167      /*!
 168       \static
 169      */
 170      function removeAllExpiryCacheFromDisk()
 171      {
 172          $expiryCachePath = eZTemplateCacheFunction::expiryTemplateBlockCacheDir();
 173          eZSubtreeCache::removeExpiryCacheFromDisk( $expiryCachePath );
 174      }
 175  
 176      /*!
 177       \static
 178       $expiryCachePath is a path to directory with cache that should be removed
 179      */
 180      function removeExpiryCacheFromDisk( $expiryCachePath )
 181      {
 182          require_once ( 'kernel/classes/ezclusterfilehandler.php' );
 183          $fileHandler = eZClusterFileHandler::instance();
 184          $fileHandler->fileDelete( $expiryCachePath );
 185      }
 186  }
 187  
 188  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7