|
eZ Publish
[4.0]
|
00001 #!/usr/bin/env php 00002 <?php 00003 // 00004 // Created on: <19-Jul-2004 10:51:17 amos> 00005 // 00006 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00007 // SOFTWARE NAME: eZ Publish 00008 // SOFTWARE RELEASE: 4.0.x 00009 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS 00010 // SOFTWARE LICENSE: GNU General Public License v2.0 00011 // NOTICE: > 00012 // This program is free software; you can redistribute it and/or 00013 // modify it under the terms of version 2.0 of the GNU General 00014 // Public License as published by the Free Software Foundation. 00015 // 00016 // This program is distributed in the hope that it will be useful, 00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 // GNU General Public License for more details. 00020 // 00021 // You should have received a copy of version 2.0 of the GNU General 00022 // Public License along with this program; if not, write to the Free 00023 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00024 // MA 02110-1301, USA. 00025 // 00026 // 00027 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00028 // 00029 00030 //include_once( 'lib/ezutils/classes/ezcli.php' ); 00031 //include_once( 'kernel/classes/ezscript.php' ); 00032 00033 require 'autoload.php'; 00034 00035 $cli = eZCLI::instance(); 00036 $script = eZScript::instance( array( 'description' => ( "eZ Publish Content Cache Handler\n" . 00037 "Allows for easy clearing of Content Caches\n" . 00038 "\n" . 00039 "Clearing node for content and users tree\n" . 00040 "./bin/ezcontentcache.php --clear-node=/,5\n" . 00041 "Clearing subtree for content tree\n" . 00042 "./bin/ezcontentcache.php --clear-subtree=/" ), 00043 'use-session' => false, 00044 'use-modules' => false, 00045 'use-extensions' => true ) ); 00046 00047 $script->startup(); 00048 00049 $options = $script->getOptions( "[clear-node:][clear-subtree:]", 00050 "", 00051 array( 'clear-node' => ( "Clears all content caches related to a given node,\n" . 00052 "pass either node ID or nice url of node.\n" . 00053 "Separate multiple nodes with a comma." ), 00054 'clear-subtree' => ( "Clears all content caches related to a given node subtree,\n" . 00055 "subtree expects a nice url as input.\n" . 00056 "Separate multiple subtrees with a comma" ) ) ); 00057 $sys = eZSys::instance(); 00058 00059 $script->initialize(); 00060 00061 //include_once( 'kernel/classes/ezcontentcachemanager.php' ); 00062 //include_once( 'kernel/classes/ezcontentobjecttreenode.php' ); 00063 00064 // Max nodes to fetch at a time 00065 $limit = 50; 00066 00067 if ( $options['clear-node'] ) 00068 { 00069 $idList = explode( ',', $options['clear-node'] ); 00070 foreach ( $idList as $nodeID ) 00071 { 00072 if ( is_numeric( $nodeID ) ) 00073 { 00074 $node = eZContentObjectTreeNode::fetch( $nodeID ); 00075 if ( !$node ) 00076 { 00077 $cli->output( "Node with ID $nodeID does not exist, skipping" ); 00078 continue; 00079 } 00080 } 00081 else 00082 { 00083 $nodeSubtree = trim( $nodeID, '/' ); 00084 $node = eZContentObjectTreeNode::fetchByURLPath( $nodeSubtree ); 00085 if ( !$node ) 00086 { 00087 $cli->output( "Node with subtree " . $cli->stylize( 'emphasize', $nodeSubtree ) . " does not exist, skipping" ); 00088 continue; 00089 } 00090 } 00091 $nodeSubtree = $node->attribute( 'path_identification_string' ); 00092 $nodeName = false; 00093 $object = $node->attribute( 'object' ); 00094 if ( $object ) 00095 { 00096 $nodeName = $object->attribute( 'name' ); 00097 } 00098 $objectID = $node->attribute( 'contentobject_id' ); 00099 $cli->output( "Clearing cache for $nodeName ($nodeSubtree)" ); 00100 eZContentCacheManager::clearContentCache( $objectID ); 00101 } 00102 $script->shutdown( 0 ); 00103 } 00104 else if ( $options['clear-subtree'] ) 00105 { 00106 $subtreeList = explode( ',', $options['clear-subtree'] ); 00107 foreach ( $subtreeList as $nodeSubtree ) 00108 { 00109 if ( is_numeric( $nodeSubtree ) ) 00110 { 00111 $nodeID = (int)$nodeSubtree; 00112 $node = eZContentObjectTreeNode::fetch( $nodeID ); 00113 if ( !$node ) 00114 { 00115 $cli->output( "Node with ID " . $cli->stylize( 'emphasize', $nodeID ) . " does not exist, skipping" ); 00116 continue; 00117 } 00118 } 00119 else 00120 { 00121 $nodeSubtree = trim( $nodeSubtree, '/' ); 00122 $node = eZContentObjectTreeNode::fetchByURLPath( $nodeSubtree ); 00123 if ( !$node ) 00124 { 00125 $cli->output( "Node with subtree " . $cli->stylize( 'emphasize', $nodeSubtree ) . " does not exist, skipping" ); 00126 continue; 00127 } 00128 } 00129 $nodeSubtree = $node->attribute( 'path_identification_string' ); 00130 $nodeName = false; 00131 $object = $node->attribute( 'object' ); 00132 if ( $object ) 00133 { 00134 $nodeName = $object->attribute( 'name' ); 00135 } 00136 $cli->output( "Clearing cache for subtree $nodeName ($nodeSubtree)" ); 00137 $objectID = $node->attribute( 'contentobject_id' ); 00138 $offset = 0; 00139 $params = array( 'AsObject' => false, 00140 'Depth' => false, 00141 'Limitation' => array() ); // Empty array means no permission checking 00142 00143 $subtreeCount = $node->subTreeCount( $params ); 00144 $script->resetIteration( $subtreeCount ); 00145 while ( $offset < $subtreeCount ) 00146 { 00147 $params['Offset'] = $offset; 00148 $params['Limit'] = $limit; 00149 $subtree =& $node->subTree( $params ); 00150 $offset += count( $subtree ); 00151 if ( count( $subtree ) == 0 ) 00152 { 00153 break; 00154 } 00155 00156 $objectIDList = array(); 00157 foreach ( $subtree as $subtreeNode ) 00158 { 00159 $objectIDList[] = $subtreeNode['contentobject_id']; 00160 } 00161 $objectIDList = array_unique( $objectIDList ); 00162 unset( $subtree ); 00163 00164 foreach ( $objectIDList as $objectID ) 00165 { 00166 $status = eZContentCacheManager::clearContentCache( $objectID ); 00167 $script->iterate( $cli, $status, "Cleared view cache for object $objectID" ); 00168 } 00169 } 00170 } 00171 $script->shutdown( 0 ); 00172 } 00173 $cli->output( "You will need to specify what to clear, either with --clear-node or --clear-subtree" ); 00174 00175 $script->shutdown( 1 ); 00176 00177 ?>