[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 #!/usr/bin/env php 2 <?php 3 // 4 // Created on: <18-Mar-2003 17:06:45 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 29 include_once ( "lib/ezutils/classes/ezextension.php" ); 30 include_once ( "lib/ezutils/classes/ezmodule.php" ); 31 include_once ( 'lib/ezutils/classes/ezcli.php' ); 32 include_once ( 'kernel/classes/ezscript.php' ); 33 include_once ( 'kernel/classes/ezcontentlanguage.php' ); 34 35 eZContentLanguage::setCronjobMode(); 36 37 $cli =& eZCLI::instance(); 38 $script =& eZScript::instance( array( 'debug-message' => '', 39 'use-session' => true, 40 'use-modules' => true, 41 'use-extensions' => true ) ); 42 43 $script->startup(); 44 45 $endl = $cli->endlineString(); 46 $webOutput = $cli->isWebOutput(); 47 48 function help() 49 { 50 $argv = $_SERVER['argv']; 51 $cli =& eZCLI::instance(); 52 $cli->output( "Usage: " . $argv[0] . " [OPTION]... [PART]\n" . 53 "Executes eZ publish cronjobs.\n" . 54 "\n" . 55 "General options:\n" . 56 " -h,--help display this help and exit \n" . 57 " -q,--quiet do not give any output except when errors occur\n" . 58 " -s,--siteaccess selected siteaccess for operations, if not specified default siteaccess is used\n" . 59 " -d,--debug display debug output at end of execution\n" . 60 " -c,--colors display output using ANSI colors\n" . 61 " --sql display sql queries\n" . 62 " --logfiles create log files\n" . 63 " --no-logfiles do not create log files (default)\n" . 64 " --no-colors do not use ANSI coloring (default)\n" ); 65 } 66 67 function changeSiteAccessSetting( &$siteaccess, $optionData ) 68 { 69 global $isQuiet; 70 $cli =& eZCLI::instance(); 71 if ( file_exists( 'settings/siteaccess/' . $optionData ) ) 72 { 73 $siteaccess = $optionData; 74 if ( !$isQuiet ) 75 $cli->notice( "Using siteaccess $siteaccess for cronjob" ); 76 } 77 else 78 { 79 if ( !$isQuiet ) 80 $cli->notice( "Siteaccess $optionData does not exist, using default siteaccess" ); 81 } 82 } 83 84 $siteaccess = false; 85 $debugOutput = false; 86 $allowedDebugLevels = false; 87 $useDebugAccumulators = false; 88 $useDebugTimingpoints = false; 89 $useIncludeFiles = false; 90 $useColors = false; 91 $isQuiet = false; 92 $useLogFiles = false; 93 $showSQL = false; 94 $cronPart = false; 95 96 $optionsWithData = array( 's' ); 97 $longOptionsWithData = array( 'siteaccess' ); 98 99 $readOptions = true; 100 101 for ( $i = 1; $i < count( $argv ); ++$i ) 102 { 103 $arg = $argv[$i]; 104 if ( $readOptions and 105 strlen( $arg ) > 0 and 106 $arg[0] == '-' ) 107 { 108 if ( strlen( $arg ) > 1 and 109 $arg[1] == '-' ) 110 { 111 $flag = substr( $arg, 2 ); 112 if ( in_array( $flag, $longOptionsWithData ) ) 113 { 114 $optionData = $argv[$i+1]; 115 ++$i; 116 } 117 if ( $flag == 'help' ) 118 { 119 help(); 120 exit(); 121 } 122 else if ( $flag == 'siteaccess' ) 123 { 124 changeSiteAccessSetting( $siteaccess, $optionData ); 125 } 126 else if ( $flag == 'debug' ) 127 { 128 $debugOutput = true; 129 } 130 else if ( $flag == 'quiet' ) 131 { 132 $isQuiet = true; 133 } 134 else if ( $flag == 'colors' ) 135 { 136 $useColors = true; 137 } 138 else if ( $flag == 'no-colors' ) 139 { 140 $useColors = false; 141 } 142 else if ( $flag == 'no-logfiles' ) 143 { 144 $useLogFiles = false; 145 } 146 else if ( $flag == 'logfiles' ) 147 { 148 $useLogFiles = true; 149 } 150 else if ( $flag == 'sql' ) 151 { 152 $showSQL = true; 153 } 154 } 155 else 156 { 157 $flag = substr( $arg, 1, 1 ); 158 $optionData = false; 159 if ( in_array( $flag, $optionsWithData ) ) 160 { 161 if ( strlen( $arg ) > 2 ) 162 { 163 $optionData = substr( $arg, 2 ); 164 } 165 else 166 { 167 $optionData = $argv[$i+1]; 168 ++$i; 169 } 170 } 171 if ( $flag == 'h' ) 172 { 173 help(); 174 exit(); 175 } 176 else if ( $flag == 'q' ) 177 { 178 $isQuiet = true; 179 } 180 else if ( $flag == 'c' ) 181 { 182 $useColors = true; 183 } 184 else if ( $flag == 'd' ) 185 { 186 $debugOutput = true; 187 if ( strlen( $arg ) > 2 ) 188 { 189 $levels = explode( ',', substr( $arg, 2 ) ); 190 $allowedDebugLevels = array(); 191 foreach ( $levels as $level ) 192 { 193 if ( $level == 'all' ) 194 { 195 $useDebugAccumulators = true; 196 $allowedDebugLevels = false; 197 $useDebugTimingpoints = true; 198 break; 199 } 200 if ( $level == 'accumulator' ) 201 { 202 $useDebugAccumulators = true; 203 continue; 204 } 205 if ( $level == 'timing' ) 206 { 207 $useDebugTimingpoints = true; 208 continue; 209 } 210 if ( $level == 'include' ) 211 { 212 $useIncludeFiles = true; 213 } 214 if ( $level == 'error' ) 215 $level = EZ_LEVEL_ERROR; 216 else if ( $level == 'warning' ) 217 $level = EZ_LEVEL_WARNING; 218 else if ( $level == 'debug' ) 219 $level = EZ_LEVEL_DEBUG; 220 else if ( $level == 'notice' ) 221 $level = EZ_LEVEL_NOTICE; 222 else if ( $level == 'timing' ) 223 $level = EZ_LEVEL_TIMING; 224 $allowedDebugLevels[] = $level; 225 } 226 } 227 } 228 else if ( $flag == 's' ) 229 { 230 changeSiteAccessSetting( $siteaccess, $optionData ); 231 } 232 } 233 } 234 else 235 { 236 if ( $cronPart === false ) 237 { 238 $readOptions = false; 239 $cronPart = $arg; 240 } 241 } 242 } 243 $script->setUseDebugOutput( $debugOutput ); 244 $script->setAllowedDebugLevels( $allowedDebugLevels ); 245 $script->setUseDebugAccumulators( $useDebugAccumulators ); 246 $script->setUseDebugTimingPoints( $useDebugTimingpoints ); 247 $script->setUseIncludeFiles( $useIncludeFiles ); 248 249 if ( $webOutput ) 250 $useColors = true; 251 252 $cli->setUseStyles( $useColors ); 253 $script->setDebugMessage( "\n\n" . str_repeat( '#', 36 ) . $cli->style( 'emphasize' ) . " DEBUG " . $cli->style( 'emphasize-end' ) . str_repeat( '#', 36 ) . "\n" ); 254 255 $script->setUseSiteAccess( $siteaccess ); 256 257 $script->initialize(); 258 if ( !$script->isInitialized() ) 259 { 260 $cli->error( 'Error initializing script: ' . $script->initializationError() . '.' ); 261 $script->shutdown(); 262 exit(); 263 } 264 265 if ( $cronPart ) 266 { 267 if ( !$isQuiet ) 268 print( "Running cronjob part '$cronPart'$endl" ); 269 } 270 271 272 $ini =& eZINI::instance( 'cronjob.ini' ); 273 $scriptDirectories = $ini->variable( 'CronjobSettings', 'ScriptDirectories' ); 274 275 /* Include extension directories */ 276 include_once ( 'lib/ezutils/classes/ezextension.php' ); 277 $extensionDirectories = $ini->variable( 'CronjobSettings', 'ExtensionDirectories' ); 278 $scriptDirectories = array_merge( $scriptDirectories, eZExtension::expandedPathList( $extensionDirectories, 'cronjobs' ) ); 279 280 $scriptGroup = 'CronjobSettings'; 281 if ( $cronPart !== false ) 282 $scriptGroup = "CronjobPart-$cronPart"; 283 $scripts = $ini->variable( $scriptGroup, 'Scripts' ); 284 285 if ( !is_array( $scripts ) or count( $scripts ) == 0 and !$isQuiet ) 286 { 287 $cli->notice( 'Notice: No scripts found for execution.' ); 288 $script->shutdown(); 289 exit(); 290 } 291 292 $index = 0; 293 294 foreach ( $scripts as $cronScript ) 295 { 296 foreach ( $scriptDirectories as $scriptDirectory ) 297 { 298 $scriptFile = $scriptDirectory . '/' . $cronScript; 299 if ( file_exists( $scriptFile ) ) 300 break; 301 } 302 if ( file_exists( $scriptFile ) ) 303 { 304 if ( !$isQuiet ) 305 { 306 if ( $index > 0 ) 307 print( $endl ); 308 $cli->output( "Running " . $cli->stylize( 'emphasize', $scriptFile ) ); 309 } 310 eZDebug::addTimingPoint( "Script $scriptFile starting" ); 311 include( $scriptFile ); 312 eZDebug::addTimingPoint( "Script $scriptFile done" ); 313 ++$index; 314 // The transaction check 315 $transactionCounterCheck = eZDB::checkTransactionCounter(); 316 if ( isset( $transactionCounterCheck['error'] ) ) 317 $cli->error( $transactionCounterCheck['error'] ); 318 } 319 } 320 321 $script->shutdown(); 322 323 ?>
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 |