[ Index ]
 

Code source de eZ Publish 3.9.0

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

title

Body

[fermer]

/bin/php/ -> ezcontentcache.php (source)

   1  #!/usr/bin/env php
   2  <?php
   3  //
   4  // Created on: <19-Jul-2004 10:51:17 amos>
   5  //
   6  // SOFTWARE NAME: eZ publish
   7  // SOFTWARE RELEASE: 3.9.0
   8  // BUILD VERSION: 17785
   9  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
  10  // SOFTWARE LICENSE: GNU General Public License v2.0
  11  // NOTICE: >
  12  //   This program is free software; you can redistribute it and/or
  13  //   modify it under the terms of version 2.0  of the GNU General
  14  //   Public License as published by the Free Software Foundation.
  15  //
  16  //   This program is distributed in the hope that it will be useful,
  17  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  18  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19  //   GNU General Public License for more details.
  20  //
  21  //   You should have received a copy of version 2.0 of the GNU General
  22  //   Public License along with this program; if not, write to the Free
  23  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  24  //   MA 02110-1301, USA.
  25  //
  26  //
  27  
  28  include_once ( 'lib/ezutils/classes/ezcli.php' );
  29  include_once ( 'kernel/classes/ezscript.php' );
  30  
  31  $cli =& eZCLI::instance();
  32  $script =& eZScript::instance( array( 'description' => ( "eZ publish Content Cache Handler\n" .
  33                                                           "Allows for easy clearing of Content Caches\n" .
  34                                                           "\n" .
  35                                                           "Clearing node for content and users tree\n" .
  36                                                           "./bin/ezcontentcache.php --clear-node=/,5\n" .
  37                                                           "Clearing subtree for content tree\n" .
  38                                                           "./bin/ezcontentcache.php --clear-subtree=/" ),
  39                                        'use-session' => false,
  40                                        'use-modules' => false,
  41                                        'use-extensions' => true ) );
  42  
  43  $script->startup();
  44  
  45  $options = $script->getOptions( "[clear-node:][clear-subtree:]",
  46                                  "",
  47                                  array( 'clear-node' => ( "Clears all content caches related to a given node,\n" .
  48                                                           "pass either node ID or nice url of node.\n" .
  49                                                           "Separate multiple nodes with a comma." ),
  50                                         'clear-subtree' => ( "Clears all content caches related to a given node subtree,\n" .
  51                                                              "subtree expects a nice url as input.\n" .
  52                                                              "Separate multiple subtrees with a comma" ) ) );
  53  $sys =& eZSys::instance();
  54  
  55  $script->initialize();
  56  
  57  include_once ( 'kernel/classes/ezcontentcachemanager.php' );
  58  include_once ( 'kernel/classes/ezcontentobjecttreenode.php' );
  59  
  60  // Max nodes to fetch at a time
  61  $limit = 50;
  62  
  63  if ( $options['clear-node'] )
  64  {
  65      $idList = explode( ',', $options['clear-node'] );
  66      foreach ( $idList as $nodeID )
  67      {
  68          if ( is_numeric( $nodeID ) )
  69          {
  70              $node = eZContentObjectTreeNode::fetch( $nodeID );
  71              if ( !$node )
  72              {
  73                  $cli->output( "Node with ID $nodeID does not exist, skipping" );
  74                  continue;
  75              }
  76          }
  77          else
  78          {
  79              $nodeSubtree = trim( $nodeID, '/' );
  80              $node = eZContentObjectTreeNode::fetchByURLPath( $nodeSubtree );
  81              if ( !$node )
  82              {
  83                  $cli->output( "Node with subtree " . $cli->stylize( 'emphasize', $nodeSubtree ) . " does not exist, skipping" );
  84                  continue;
  85              }
  86          }
  87          $nodeSubtree = $node->attribute( 'path_identification_string' );
  88          $nodeName = false;
  89          $object = $node->attribute( 'object' );
  90          if ( $object )
  91          {
  92              $nodeName = $object->attribute( 'name' );
  93          }
  94          $objectID = $node->attribute( 'contentobject_id' );
  95          $cli->output( "Clearing cache for $nodeName ($nodeSubtree)" );
  96          eZContentCacheManager::clearContentCache( $objectID );
  97      }
  98      return $script->shutdown();
  99  }
 100  else if ( $options['clear-subtree'] )
 101  {
 102      $subtreeList = explode( ',', $options['clear-subtree'] );
 103      foreach ( $subtreeList as $nodeSubtree )
 104      {
 105          if ( is_numeric( $nodeSubtree ) )
 106          {
 107              $nodeID = (int)$nodeSubtree;
 108              $node = eZContentObjectTreeNode::fetch( $nodeID );
 109              if ( !$node )
 110              {
 111                  $cli->output( "Node with ID " . $cli->stylize( 'emphasize', $nodeID ) . " does not exist, skipping" );
 112                  continue;
 113              }
 114          }
 115          else
 116          {
 117              $nodeSubtree = trim( $nodeSubtree, '/' );
 118              $node = eZContentObjectTreeNode::fetchByURLPath( $nodeSubtree );
 119              if ( !$node )
 120              {
 121                  $cli->output( "Node with subtree " . $cli->stylize( 'emphasize', $nodeSubtree ) . " does not exist, skipping" );
 122                  continue;
 123              }
 124          }
 125          $nodeSubtree = $node->attribute( 'path_identification_string' );
 126          $nodeName = false;
 127          $object = $node->attribute( 'object' );
 128          if ( $object )
 129          {
 130              $nodeName = $object->attribute( 'name' );
 131          }
 132          $cli->output( "Clearing cache for subtree $nodeName ($nodeSubtree)" );
 133          $objectID = $node->attribute( 'contentobject_id' );
 134          $offset = 0;
 135          $params = array( 'AsObject' => false,
 136                           'Depth' => false,
 137                           'Limitation' => array() ); // Empty array means no permission checking
 138  
 139          $subtreeCount = $node->subTreeCount( $params );
 140          $script->resetIteration( $subtreeCount );
 141          while ( $offset < $subtreeCount )
 142          {
 143              $params['Offset'] = $offset;
 144              $params['Limit'] = $limit;
 145              $subtree =& $node->subTree( $params );
 146              $offset += count( $subtree );
 147              if ( count( $subtree ) == 0 )
 148              {
 149                  break;
 150              }
 151  
 152              $objectIDList = array();
 153              foreach ( $subtree as $subtreeNode )
 154              {
 155                  $objectIDList[] = $subtreeNode['contentobject_id'];
 156              }
 157              $objectIDList = array_unique( $objectIDList );
 158              unset( $subtree );
 159  
 160              foreach ( $objectIDList as $objectID )
 161              {
 162                  $status = eZContentCacheManager::clearContentCache( $objectID );
 163                  $script->iterate( $cli, $status, "Cleared view cache for object $objectID" );
 164              }
 165          }
 166      }
 167      return $script->shutdown();
 168  }
 169  $cli->output( "You will need to specify what to clear, either with --clear-node or --clear-subtree" );
 170  
 171  $script->shutdown( 1 );
 172  
 173  ?>


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