[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 #!/usr/bin/env php 2 <?php 3 // 4 // Created on: <28-Nov-2002 12:45:40 bf> 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 set_time_limit( 0 ); 29 30 include_once ( "lib/ezutils/classes/ezextension.php" ); 31 include_once ( "lib/ezutils/classes/ezmodule.php" ); 32 include_once ( 'lib/ezutils/classes/ezcli.php' ); 33 include_once ( 'kernel/classes/ezscript.php' ); 34 35 $cli =& eZCLI::instance(); 36 $script =& eZScript::instance( array( 'debug-message' => '', 37 'use-session' => true, 38 'use-modules' => true, 39 'use-extensions' => true ) ); 40 41 $script->startup(); 42 43 $endl = $cli->endlineString(); 44 $webOutput = $cli->isWebOutput(); 45 46 function help() 47 { 48 $argv = $_SERVER['argv']; 49 $cli =& eZCLI::instance(); 50 $cli->output( "Usage: " . $argv[0] . " [OPTION]...\n" . 51 "eZ publish content object name update.\n" . 52 "Goes trough all objects and updates all content object names\n" . 53 "\n" . 54 "General options:\n" . 55 " -h,--help display this help and exit \n" . 56 " -q,--quiet do not give any output except when errors occur\n" . 57 " -s,--siteaccess selected siteaccess for operations, if not specified default siteaccess is used\n" . 58 " -d,--debug display debug output at end of execution\n" . 59 " --db-host=HOST Use database host HOST\n" . 60 " --db-user=USER Use database user USER\n" . 61 " --db-password=PWD Use database password PWD\n" . 62 " --db-database=DB Use database named DB\n" . 63 " --db-driver=DRIVER Use database driver DRIVER\n" . 64 " -c,--colors display output using ANSI colors\n" . 65 " --sql display sql queries\n" . 66 " --logfiles create log files\n" . 67 " --no-logfiles do not create log files (default)\n" . 68 " --no-colors do not use ANSI coloring (default)\n" ); 69 } 70 71 function changeSiteAccessSetting( &$siteaccess, $optionData ) 72 { 73 global $isQuiet; 74 $cli =& eZCLI::instance(); 75 if ( file_exists( 'settings/siteaccess/' . $optionData ) ) 76 { 77 $siteaccess = $optionData; 78 if ( !$isQuiet ) 79 $cli->notice( "Using siteaccess $siteaccess for content object name update" ); 80 } 81 else 82 { 83 if ( !$isQuiet ) 84 $cli->notice( "Siteaccess $optionData does not exist, using default siteaccess" ); 85 } 86 } 87 88 $siteaccess = false; 89 $debugOutput = false; 90 $allowedDebugLevels = false; 91 $useDebugAccumulators = false; 92 $useDebugTimingpoints = false; 93 $useIncludeFiles = false; 94 $useColors = false; 95 $isQuiet = false; 96 $useLogFiles = false; 97 $showSQL = false; 98 99 $dbUser = false; 100 $dbPassword = false; 101 $dbHost = false; 102 $dbName = false; 103 $dbImpl = false; 104 105 $optionsWithData = array( 's' ); 106 $longOptionsWithData = array( 'siteaccess' ); 107 108 $readOptions = true; 109 110 for ( $i = 1; $i < count( $argv ); ++$i ) 111 { 112 $arg = $argv[$i]; 113 if ( $readOptions and 114 strlen( $arg ) > 0 and 115 $arg[0] == '-' ) 116 { 117 if ( strlen( $arg ) > 1 and 118 $arg[1] == '-' ) 119 { 120 $flag = substr( $arg, 2 ); 121 if ( in_array( $flag, $longOptionsWithData ) ) 122 { 123 $optionData = $argv[$i+1]; 124 ++$i; 125 } 126 if ( $flag == 'help' ) 127 { 128 help(); 129 exit(); 130 } 131 else if ( $flag == 'siteaccess' ) 132 { 133 changeSiteAccessSetting( $siteaccess, $optionData ); 134 } 135 else if ( preg_match( "/^db-host=(.*)$/", $flag, $matches ) ) 136 { 137 $dbHost = $matches[1]; 138 } 139 else if ( preg_match( "/^db-user=(.*)$/", $flag, $matches ) ) 140 { 141 $dbUser = $matches[1]; 142 } 143 else if ( preg_match( "/^db-password=(.*)$/", $flag, $matches ) ) 144 { 145 $dbPassword = $matches[1]; 146 } 147 else if ( preg_match( "/^db-database=(.*)$/", $flag, $matches ) ) 148 { 149 $dbName = $matches[1]; 150 } 151 else if ( preg_match( "/^db-driver=(.*)$/", $flag, $matches ) ) 152 { 153 $dbImpl = $matches[1]; 154 } 155 else if ( $flag == 'debug' ) 156 { 157 $debugOutput = true; 158 } 159 else if ( $flag == 'quiet' ) 160 { 161 $isQuiet = true; 162 } 163 else if ( $flag == 'colors' ) 164 { 165 $useColors = true; 166 } 167 else if ( $flag == 'no-colors' ) 168 { 169 $useColors = false; 170 } 171 else if ( $flag == 'no-logfiles' ) 172 { 173 $useLogFiles = false; 174 } 175 else if ( $flag == 'logfiles' ) 176 { 177 $useLogFiles = true; 178 } 179 else if ( $flag == 'sql' ) 180 { 181 $showSQL = true; 182 } 183 } 184 else 185 { 186 $flag = substr( $arg, 1, 1 ); 187 $optionData = false; 188 if ( in_array( $flag, $optionsWithData ) ) 189 { 190 if ( strlen( $arg ) > 2 ) 191 { 192 $optionData = substr( $arg, 2 ); 193 } 194 else 195 { 196 $optionData = $argv[$i+1]; 197 ++$i; 198 } 199 } 200 if ( $flag == 'h' ) 201 { 202 help(); 203 exit(); 204 } 205 else if ( $flag == 'q' ) 206 { 207 $isQuiet = true; 208 } 209 else if ( $flag == 'c' ) 210 { 211 $useColors = true; 212 } 213 else if ( $flag == 'd' ) 214 { 215 $debugOutput = true; 216 if ( strlen( $arg ) > 2 ) 217 { 218 $levels = explode( ',', substr( $arg, 2 ) ); 219 $allowedDebugLevels = array(); 220 foreach ( $levels as $level ) 221 { 222 if ( $level == 'all' ) 223 { 224 $useDebugAccumulators = true; 225 $allowedDebugLevels = false; 226 $useDebugTimingpoints = true; 227 break; 228 } 229 if ( $level == 'accumulator' ) 230 { 231 $useDebugAccumulators = true; 232 continue; 233 } 234 if ( $level == 'timing' ) 235 { 236 $useDebugTimingpoints = true; 237 continue; 238 } 239 if ( $level == 'include' ) 240 { 241 $useIncludeFiles = true; 242 } 243 if ( $level == 'error' ) 244 $level = EZ_LEVEL_ERROR; 245 else if ( $level == 'warning' ) 246 $level = EZ_LEVEL_WARNING; 247 else if ( $level == 'debug' ) 248 $level = EZ_LEVEL_DEBUG; 249 else if ( $level == 'notice' ) 250 $level = EZ_LEVEL_NOTICE; 251 else if ( $level == 'timing' ) 252 $level = EZ_LEVEL_TIMING; 253 $allowedDebugLevels[] = $level; 254 } 255 } 256 } 257 else if ( $flag == 's' ) 258 { 259 changeSiteAccessSetting( $siteaccess, $optionData ); 260 } 261 } 262 } 263 } 264 $script->setUseDebugOutput( $debugOutput ); 265 $script->setAllowedDebugLevels( $allowedDebugLevels ); 266 $script->setUseDebugAccumulators( $useDebugAccumulators ); 267 $script->setUseDebugTimingPoints( $useDebugTimingpoints ); 268 $script->setUseIncludeFiles( $useIncludeFiles ); 269 270 if ( $webOutput ) 271 $useColors = true; 272 273 $cli->setUseStyles( $useColors ); 274 $script->setDebugMessage( "\n\n" . str_repeat( '#', 36 ) . $cli->style( 'emphasize' ) . " DEBUG " . $cli->style( 'emphasize-end' ) . str_repeat( '#', 36 ) . "\n" ); 275 276 $script->setUseSiteAccess( $siteaccess ); 277 278 $script->initialize(); 279 280 print( "Starting object re-indexing\n" ); 281 282 //eZDebug::setHandleType( EZ_HANDLE_FROM_PHP ); 283 284 include_once ( "lib/ezutils/classes/ezmodule.php" ); 285 // eZModule::setGlobalPathList( array( "kernel" ) ); 286 include_once ( 'lib/ezutils/classes/ezexecution.php' ); 287 include_once ( "lib/ezutils/classes/ezdebug.php" ); 288 289 include_once ( 'kernel/classes/ezcontentobjecttreenode.php' ); 290 291 $db =& eZDB::instance(); 292 293 if ( $dbHost or $dbName or $dbUser or $dbImpl ) 294 { 295 $params = array(); 296 if ( $dbHost !== false ) 297 $params['server'] = $dbHost; 298 if ( $dbUser !== false ) 299 { 300 $params['user'] = $dbUser; 301 $params['password'] = ''; 302 } 303 if ( $dbPassword !== false ) 304 $params['password'] = $dbPassword; 305 if ( $dbName !== false ) 306 $params['database'] = $dbName; 307 $db =& eZDB::instance( $dbImpl, $params, true ); 308 eZDB::setInstance( $db ); 309 } 310 311 $db->setIsSQLOutputEnabled( $showSQL ); 312 313 // Get top node 314 $topNodeArray = eZPersistentObject::fetchObjectList( eZContentObjectTreeNode::definition(), 315 null, 316 array( 'parent_node_id' => 1, 317 'depth' => 1 ) ); 318 $subTreeCount = 0; 319 foreach ( array_keys ( $topNodeArray ) as $key ) 320 { 321 $subTreeCount += $topNodeArray[$key]->subTreeCount( array( 'Limitation' => false ) ); 322 } 323 324 print( "Number of objects to index: $subTreeCount $endl" ); 325 326 $i = 0; 327 $dotMax = 70; 328 $dotCount = 0; 329 $limit = 50; 330 331 foreach ( array_keys ( $topNodeArray ) as $key ) 332 { 333 $node =& $topNodeArray[$key]; 334 $offset = 0; 335 $subTree =& $node->subTree( array( 'Offset' => $offset, 'Limit' => $limit, 336 'Limitation' => array() ) ); 337 while ( $subTree != null ) 338 { 339 foreach ( $subTree as $innerNode ) 340 { 341 $object =& $innerNode->attribute( 'object' ); 342 $class =& $object->contentClass(); 343 $object->setName( $class->contentObjectName( $object ) ); 344 $object->store(); 345 unset( $object ); 346 unset( $class ); 347 348 // show progress bar 349 ++$i; 350 ++$dotCount; 351 print( "." ); 352 if ( $dotCount >= $dotMax or $i >= $subTreeCount ) 353 { 354 $dotCount = 0; 355 $percent = (float)( ($i*100.0) / $subTreeCount ); 356 print( " " . $percent . "%" . $endl ); 357 } 358 } 359 $offset += $limit; 360 unset( $subTree ); 361 $subTree =& $node->subTree( array( 'Offset' => $offset, 'Limit' => $limit, 362 'Limitation' => array() ) ); 363 } 364 } 365 366 print( $endl . "done" . $endl ); 367 368 $script->shutdown(); 369 370 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |