00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 include_once( 'lib/ezutils/classes/ezcli.php' );
00073 include_once( 'lib/ezdb/classes/ezdb.php' );
00074 include_once( 'access.php' );
00075
00076 class eZScript
00077 {
00078
00079
00080
00081 function eZScript( $settings = array() )
00082 {
00083 $settings = array_merge( array( 'debug-message' => false,
00084 'debug-output' => false,
00085 'debug-include' => false,
00086 'debug-levels' => false,
00087 'debug-accumulator' => false,
00088 'debug-timing' => false,
00089 'use-session' => false,
00090 'use-extensions' => false,
00091 'use-modules' => false,
00092 'user' => false,
00093 'description' => 'eZ publish script',
00094 'site-access' => false,
00095 'min_version' => false,
00096 'max_version' => false ),
00097 $settings );
00098 $this->DebugMessage = $settings['debug-message'];
00099 $this->UseDebugOutput = $settings['debug-output'];
00100 $this->AllowedDebugLevels = $settings['debug-levels'];
00101 $this->UseDebugAccumulators = $settings['debug-accumulator'];
00102 $this->UseDebugTimingPoints = $settings['debug-timing'];
00103 $this->UseIncludeFiles = $settings['debug-include'];
00104 $this->UseSession = $settings['use-session'];
00105 $this->UseModules = $settings['use-modules'];
00106 $this->UseExtensions = $settings['use-extensions'];
00107 $this->User = $settings['user'];
00108 $this->SiteAccess = $settings['site-access'];
00109 $this->Description = $settings['description'];
00110 $this->MinVersion = $settings['min_version'];
00111 $this->MaxVersion = $settings['max_version'];
00112 $this->ExitCode = false;
00113 $this->IsQuiet = false;
00114 $this->ShowVerbose = false;
00115 $this->IsInitialized = false;
00116 $this->CurrentOptions = false;
00117 $this->CurrentOptionConfig = false;
00118 $this->CurrentStandardOptions = false;
00119 $this->CurrentExcludeOptions = false;
00120 $this->CurrentOptionHelp = false;
00121
00122 $this->IterationTrueString = '.';
00123 $this->IterationFalseString = '~';
00124 $this->IterationNumericStrings = false;
00125 $this->IterationWrapNumeric = false;
00126 $this->IterationIndex = 0;
00127 $this->IterationColumn = 0;
00128 $this->IterationColumnMax = 70;
00129 $this->IterationMax = false;
00130 $this->InitializationErrorMessage = 'unknown error';
00131 }
00132
00133
00134
00135
00136 function validateVersion()
00137 {
00138 include_once( 'lib/version.php' );
00139 $versionValidated = false;
00140 $ezversion = eZPublishSDK::version();
00141 if ( $this->MinVersion !== false )
00142 {
00143 if ( $this->MaxVersion !== false )
00144 {
00145 if ( version_compare( $this->MinVersion, $ezversion , 'le' ) &&
00146 version_compare( $this->MaxVersion, $ezversion , 'ge' ) )
00147 {
00148 return true;
00149 }
00150 return false;
00151 }
00152 if ( version_compare( $this->MinVersion, $ezversion , 'le' ) )
00153 {
00154 return true;
00155 }
00156 return false;
00157 }
00158 else
00159 {
00160 if ( version_compare( $this->MaxVersion, $ezversion , 'ge' ) )
00161 {
00162 return true;
00163 }
00164 return false;
00165 }
00166 }
00167
00168
00169
00170
00171
00172
00173
00174 function startup()
00175 {
00176 error_reporting( E_ALL );
00177
00178 eZDebug::setHandleType( EZ_HANDLE_TO_PHP );
00179
00180 if ( php_sapi_name() != 'cli' )
00181 {
00182 $cli =& eZCLI::instance();
00183 $cli->output( "PHP is currently using the '" . php_sapi_name() . "' interface. Make sure it is using the 'cli' interface." );
00184 exit( 1 );
00185 }
00186
00187
00188 require_once( 'lib/compat.php' );
00189
00190 include_once( "lib/ezutils/classes/ezini.php" );
00191 $ini =& eZINI::instance();
00192 $phpLocale = trim( $ini->variable( 'RegionalSettings', 'SystemLocale' ) );
00193 if ( $phpLocale != '' )
00194 {
00195 setlocale( LC_ALL, explode( ',', $phpLocale ) );
00196 }
00197
00198
00199 $timezone = $ini->variable( "TimeZoneSettings", "TimeZone" );
00200 if ( $timezone )
00201 {
00202 putenv( "TZ=$timezone" );
00203 }
00204 }
00205
00206
00207
00208
00209
00210
00211
00212
00213 function initialize()
00214 {
00215 if( ob_get_length() != 0 )
00216 ob_end_clean();
00217 include_once( "lib/ezutils/classes/ezdebugsetting.php" );
00218
00219 $debugINI =& eZINI::instance( 'debug.ini' );
00220 eZDebugSetting::setDebugINI( $debugINI );
00221
00222
00223 $this->updateTextCodecSettings();
00224
00225
00226 $this->updateDebugSettings( $this->UseDebugOutput );
00227
00228
00229 include_once( 'lib/ezi18n/classes/ezcodepage.php' );
00230 $ini =& eZINI::instance();
00231 $iniFilePermission = $ini->variable( 'FileSettings', 'StorageFilePermissions' );
00232 $iniDirPermission = $ini->variable( 'FileSettings', 'StorageDirPermissions' );
00233 $iniVarDirectory = eZSys::cacheDirectory() ;
00234
00235 eZCodepage::setPermissionSetting( array( 'file_permission' => octdec( $iniFilePermission ),
00236 'dir_permission' => octdec( $iniDirPermission ),
00237 'var_directory' => $iniVarDirectory ) );
00238
00239 include_once( 'lib/ezutils/classes/ezexecution.php' );
00240
00241 eZExecution::addCleanupHandler( 'eZDBCleanup' );
00242 eZExecution::addFatalErrorHandler( 'eZFatalError' );
00243
00244 eZDebug::setHandleType( EZ_HANDLE_FROM_PHP );
00245
00246 if ( $this->UseExtensions )
00247 {
00248
00249 include_once( 'lib/ezutils/classes/ezextension.php' );
00250 include_once( 'kernel/common/ezincludefunctions.php' );
00251 eZExtension::activateExtensions( 'default' );
00252
00253 }
00254
00255 include_once( "access.php" );
00256 $siteaccess = $this->SiteAccess;
00257 if ( $siteaccess )
00258 {
00259 $access = array( 'name' => $siteaccess,
00260 'type' => EZ_ACCESS_TYPE_STATIC );
00261 }
00262 else
00263 {
00264 $ini =& eZINI::instance();
00265 $siteaccess = $ini->variable( 'SiteSettings', 'DefaultAccess' );
00266 $access = array( 'name' => $siteaccess,
00267 'type' => EZ_ACCESS_TYPE_DEFAULT );
00268 }
00269
00270 $access = changeAccess( $access );
00271
00272 if ( $this->UseExtensions )
00273 {
00274
00275 eZExtension::activateExtensions( 'access' );
00276
00277 }
00278
00279
00280 $GLOBALS['eZSiteBasics']['session-required'] = $this->UseSession;
00281
00282 if ( $this->UseSession )
00283 {
00284
00285 include_once( "lib/ezutils/classes/ezsession.php" );
00286 include_once( 'lib/ezdb/classes/ezdb.php' );
00287 $db =& eZDB::instance();
00288 if ( $db->isConnected() )
00289 {
00290 eZSessionStart();
00291 }
00292 else
00293 {
00294 $this->IsInitialized = false;
00295 $this->InitializationErrorMessage = 'database error: ' . $db->errorMessage();
00296 return;
00297 }
00298 }
00299
00300 if ( $this->User )
00301 {
00302 $userLogin = $this->User['login'];
00303 $userPassword = $this->User['password'];
00304 include_once( 'kernel/classes/datatypes/ezuser/ezuser.php' );
00305
00306 if ( $userLogin and $userPassword )
00307 {
00308 $userID = eZUser::loginUser( $userLogin, $userPassword );
00309 if ( !$userID )
00310 {
00311 $cli =& eZCLI::instance();
00312 if ( $this->isLoud() )
00313 $cli->warning( 'Failed to login with user ' . $userLogin );
00314 include_once( 'lib/ezutils/classes/ezexecution.php' );
00315 eZExecution::cleanup();
00316 eZExecution::setCleanExit();
00317 }
00318 }
00319 }
00320
00321
00322 if ( $this->UseModules )
00323 {
00324 include_once( 'lib/ezutils/classes/ezmodule.php' );
00325 $moduleRepositories = eZModule::activeModuleRepositories( $this->UseExtensions );
00326 eZModule::setGlobalPathList( $moduleRepositories );
00327 }
00328 $this->IsInitialized = true;
00329 }
00330
00331 function isInitialized()
00332 {
00333 return $this->IsInitialized;
00334 }
00335
00336 function initializationError()
00337 {
00338 return $this->InitializationErrorMessage;
00339 }
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351 function shutdown( $exitCode = false, $exitText = false )
00352 {
00353 $cli =& eZCLI::instance();
00354 if ( class_exists( 'ezdb' )
00355 and eZDB::hasInstance() )
00356 {
00357 $db =& eZDB::instance( false, array( 'show_errors' => false ) );
00358
00359 $transactionCounterCheck = eZDB::checkTransactionCounter();
00360 if ( isset( $transactionCounterCheck['error'] ) )
00361 $cli->error( $transactionCounterCheck['error'] );
00362
00363 if ( $this->UseSession and
00364 $db->isConnected() )
00365 {
00366 include_once( 'kernel/classes/datatypes/ezuser/ezuser.php' );
00367 eZUser::logoutCurrent();
00368 eZSessionRemove();
00369 }
00370 }
00371
00372 $webOutput = $cli->isWebOutput();
00373
00374 if ( $this->UseDebugOutput or
00375 eZDebug::isDebugEnabled() )
00376 {
00377 if ( $this->DebugMessage )
00378 fputs( STDERR, $this->DebugMessage );
00379 fputs( STDERR, eZDebug::printReport( false, $webOutput, true,
00380 $this->AllowedDebugLevels, $this->UseDebugAccumulators,
00381 $this->UseDebugTimingPoints, $this->UseIncludeFiles ) );
00382 }
00383
00384 include_once( 'lib/ezutils/classes/ezexecution.php' );
00385 eZExecution::cleanup();
00386 eZExecution::setCleanExit();
00387 $this->IsInitialized = false;
00388 if ( $exitCode !== false )
00389 $this->ExitCode = $exitCode;
00390 if ( $this->ExitCode !== false )
00391 {
00392 if ( $exitText !== false )
00393 $cli->output( $exitText );
00394 exit( $this->ExitCode );
00395 }
00396 }
00397
00398
00399
00400
00401
00402
00403
00404 function setDebugMessage( $message )
00405 {
00406 $this->DebugMessage = $message;
00407 }
00408
00409
00410
00411
00412
00413 function setUseDebugOutput( $useDebug )
00414 {
00415 $this->UseDebugOutput = $useDebug;
00416 }
00417
00418
00419
00420
00421
00422
00423 function setUseDebugAccumulators( $useAccumulators )
00424 {
00425 $this->UseDebugAccumulators = $useAccumulators;
00426 }
00427
00428
00429
00430
00431
00432
00433 function setUseDebugTimingPoints( $useTimingPoints )
00434 {
00435 $this->UseDebugTimingPoints = $useTimingPoints;
00436 }
00437
00438
00439
00440
00441
00442
00443 function setUseIncludeFiles( $useIncludeFiles )
00444 {
00445 $this->UseIncludeFiles = $useIncludeFiles;
00446 }
00447
00448
00449
00450
00451
00452
00453
00454 function setAllowedDebugLevels( $allowedDebugLevels )
00455 {
00456 $this->AllowedDebugLevels = $allowedDebugLevels;
00457 }
00458
00459
00460
00461
00462
00463
00464 function setUseSession( $useSession )
00465 {
00466 $this->UseSession = $useSession;
00467 }
00468
00469
00470
00471
00472
00473 function setUseExtensions( $useExtensions )
00474 {
00475 $this->UseExtensions = $useExtensions;
00476 }
00477
00478
00479
00480
00481
00482
00483 function setUseSiteAccess( $siteAccess )
00484 {
00485 $this->SiteAccess = $siteAccess;
00486 }
00487
00488
00489
00490
00491 function usedSiteAccess()
00492 {
00493 return $this->SiteAccess;
00494 }
00495
00496 function setUseModules( $useModules )
00497 {
00498 $this->UseModules = $useModules;
00499 }
00500
00501 function setUser( $userLogin, $userPassword )
00502 {
00503 $this->User = array( 'login' => $userLogin,
00504 'password' => $userPassword );
00505 }
00506
00507
00508
00509
00510
00511
00512
00513 function setShowVerboseOutput( $verbose )
00514 {
00515 if ( $verbose === true )
00516 $verbose = 1;
00517 $this->ShowVerbose = $verbose;
00518 }
00519
00520
00521
00522
00523 function verboseOutputLevel()
00524 {
00525 return $this->ShowVerbose;
00526 }
00527
00528
00529
00530
00531 function currentOptions()
00532 {
00533 return $this->CurrentOptions;
00534 }
00535
00536
00537
00538
00539 function currentOptionConfig()
00540 {
00541 return $this->CurrentOptionConfig;
00542 }
00543
00544
00545
00546
00547
00548 function setExitCode( $code = false )
00549 {
00550 $this->ExitCode = $code;
00551 }
00552
00553 function exitCode()
00554 {
00555 return $this->ExitCode;
00556 }
00557
00558
00559
00560
00561
00562
00563 function setIsQuiet( $isQuiet )
00564 {
00565 $cli =& eZCLI::instance();
00566 $this->IsQuiet = $isQuiet;
00567 $cli->setIsQuiet( $isQuiet );
00568 }
00569
00570
00571
00572
00573
00574 function isQuiet()
00575 {
00576 return $this->IsQuiet;
00577 }
00578
00579
00580
00581
00582
00583 function isLoud()
00584 {
00585 return !$this->IsQuiet;
00586 }
00587
00588 function setIterationData( $trueString, $falseString,
00589 $numericStrings = false, $wrapNumeric = false )
00590 {
00591 $this->IterationTrueString = $trueString;
00592 $this->IterationFalseString = $falseString;
00593 $this->IterationNumericStrings = $numericStrings;
00594 $this->IterationWrapNumeric = $wrapNumeric;
00595 }
00596
00597 function resetIteration( $iterationMax = false, $startIndex = 0 )
00598 {
00599 $this->IterationIndex = $startIndex;
00600 $this->IterationColumn = 0;
00601 $this->IterationMax = $iterationMax;
00602 }
00603
00604 function iterate( &$cli, $status, $text = false )
00605 {
00606 if ( !$this->IterationNumericStrings )
00607 $status = (bool)$status;
00608 if ( $this->verboseOutputLevel() === false or
00609 $text === false )
00610 {
00611 if ( is_bool( $status ) )
00612 {
00613 $statusText = $status ? $this->IterationTrueString : $this->IterationFalseString;
00614 }
00615 else
00616 {
00617 if ( $this->IterationWrapNumeric )
00618 $status = $status % count( $this->IterationNumericStrings );
00619 if ( $status < count( $this->IterationNumericStrings ) )
00620 $statusText = $this->IterationNumericStrings[$status];
00621 else
00622 $statusText = ' ';
00623 }
00624 $endLine = false;
00625 $changeLine = false;
00626 ++$this->IterationIndex;
00627 ++$this->IterationColumn;
00628 $iterationColumn = $this->IterationColumn;
00629 if ( $this->IterationColumn >= $this->IterationColumnMax )
00630 {
00631 $this->IterationColumn = 0;
00632 $changeLine = true;
00633 }
00634 if ( $this->IterationMax !== false )
00635 {
00636 if ( $this->IterationIndex >= $this->IterationMax )
00637 {
00638 $this->IterationColumn = 0;
00639 $changeLine = true;
00640 }
00641 }
00642 if ( $changeLine )
00643 {
00644 if ( $this->IterationMax !== false )
00645 {
00646 $spacing = $this->IterationColumnMax - $iterationColumn;
00647 $percent = ( $this->IterationIndex * 100 ) / $this->IterationMax;
00648 if ( $percent > 100.0 )
00649 $percent = 100;
00650 else
00651 $spacing += 1;
00652 $percentText = number_format( $percent, 2 ) . '%';
00653 $statusText .= str_repeat( ' ', $spacing );
00654 $statusText .= $percentText;
00655 }
00656 $endLine = true;
00657 }
00658 $cli->output( $statusText, $endLine );
00659 }
00660 else
00661 {
00662 $statusLevel = $status;
00663 if ( is_bool( $status ) )
00664 $statusLevel = $status ? 0 : 1;
00665 if ( $statusLevel > 0 )
00666 {
00667 --$statusLevel;
00668 $statusLevels = array( 'warning', 'failure' );
00669 if ( $statusLevel > count( $statusLevels ) )
00670 $statusLevel = count( $statusLevels ) - 1;
00671 $levelText = $statusLevels[$statusLevel];
00672 $cli->output( $cli->stylize( $levelText, $text ) );
00673 }
00674 else
00675 {
00676 $cli->output( $text );
00677 }
00678 }
00679 }
00680
00681 function showHelp( $useStandardOptions = false, $optionConfig = false, $optionHelp = false, $argumentConfig = false, $arguments = false )
00682 {
00683 if ( $useStandardOptions === false )
00684 {
00685 $useStandardOptions = $this->CurrentStandardOptions;
00686 }
00687 if ( $optionConfig === false )
00688 {
00689 $optionConfig = $this->CurrentOptionConfig;
00690 }
00691 if ( $optionHelp === false )
00692 {
00693 $optionHelp = $this->CurrentOptionHelp;
00694 }
00695 if ( $argumentConfig === false )
00696 {
00697 $argumentConfig = $this->ArgumentConfig;
00698 }
00699 $optionList = array();
00700 foreach ( $optionConfig['list'] as $configItem )
00701 {
00702 if ( in_array( $configItem['name'], $this->CurrentExcludeOptions ) )
00703 continue;
00704 $optionText = '-';
00705 if ( $configItem['is-long-option'] )
00706 $optionText .= '-';
00707 $optionText .= $configItem['name'];
00708 if ( $configItem['has-value'] and $configItem['is-long-option'] )
00709 $optionText .= "=VALUE";
00710 $hasMultipleValues = ( $configItem['quantifier']['min'] > 1 or
00711 $configItem['quantifier']['max'] === false or
00712 $configItem['quantifier']['max'] > 1 );
00713 if ( $hasMultipleValues )
00714 $optionText .= "...";
00715 $optionDescription = '';
00716 if ( isset( $optionHelp[$configItem['name']] ) )
00717 $optionDescription = $optionHelp[$configItem['name']];
00718 $optionList[] = array( $optionText, $optionDescription );
00719 }
00720 if ( $arguments === false )
00721 {
00722 $arguments = $_SERVER['argv'];
00723 $program = $arguments[0];
00724 }
00725 $cli =& eZCLI::instance();
00726 $generalOptionList = array();
00727 $generalOptionList = array();
00728 if ( $useStandardOptions )
00729 {
00730 $generalOptionList[] = array( '-h,--help', 'display this help and exit');
00731 $generalOptionList[] = array( '-q,--quiet', 'do not give any output except when errors occur' );
00732 if ( $useStandardOptions['siteaccess'] )
00733 $generalOptionList[] = array( '-s,--siteaccess', "selected siteaccess for operations,\nif not specified default siteaccess is used" );
00734 if ( $useStandardOptions['debug'] )
00735 $generalOptionList[] = array( '-d,--debug...', ( "display debug output at end of execution,\n" .
00736 "the following debug items can be controlled: \n" .
00737 "all, accumulator, include, timing, error, warning, debug or notice." ) );
00738 if ( $useStandardOptions['colors'] )
00739 {
00740 $generalOptionList[] = array( '-c,--colors', 'display output using ANSI colors (default)' );
00741 $generalOptionList[] = array( '--no-colors', 'do not use ANSI coloring' );
00742 }
00743 if ( $useStandardOptions['user'] )
00744 {
00745 $generalOptionList[] = array( '-l,--login USER', 'login with USER and use it for all operations' );
00746 $generalOptionList[] = array( '-p,--password PWD', 'use PWD as password for USER' );
00747 }
00748 if ( $useStandardOptions['log'] )
00749 {
00750 $generalOptionList[] = array( '--logfiles', 'create log files' );
00751 $generalOptionList[] = array( '--no-logfiles', 'do not create log files (default)' );
00752 }
00753 if ( $useStandardOptions['verbose'] )
00754 {
00755 $generalOptionList[] = array( '-v,--verbose...', "display more information, \nused multiple times will increase amount of information" );
00756 }
00757 }
00758 $description = $this->Description;
00759 $helpText = "Usage: " . $program;
00760 if ( count( $optionList ) > 0 or count( $generalOptionList ) > 0 )
00761 {
00762 $helpText .= " [OPTION]...";
00763 }
00764 if ( $argumentConfig && isset( $argumentConfig['list'] ) && is_array( $argumentConfig['list'] ) )
00765 {
00766 foreach ( $argumentConfig['list'] as $argumentItem )
00767 {
00768 $argumentName = strtoupper( $argumentItem['name'] );
00769 $quantifier = $argumentItem['quantifier'];
00770 if ( $quantifier['min'] > 1 or $quantifier['max'] === false or $quantifier['max'] > 1 )
00771 $helpText .= " [$argumentName]...";
00772 else
00773 $helpText .= " [$argumentName]";
00774 }
00775 }
00776 if ( $description )
00777 $helpText .= "\n" . $description . "\n";
00778 if ( count( $generalOptionList ) > 0 )
00779 {
00780 $helpText .= "\nGeneral options:\n";
00781 $maxLength = 0;
00782 foreach ( $generalOptionList as $optionItem )
00783 {
00784 $maxLength = max( strlen( $optionItem[0] ), $maxLength );
00785 }
00786 $spacingLength = $maxLength + 2;
00787 foreach ( $generalOptionList as $optionItem )
00788 {
00789 $option = $optionItem[0];
00790 $optionDescription = $optionItem[1];
00791 $optionLines = explode( "\n", $option );
00792 $optionDescriptionLines = explode( "\n", $optionDescription );
00793 $count = max( count( $optionLines ), count( $optionDescriptionLines ) );
00794 for ( $i = 0; $i < $count; ++$i )
00795 {
00796 $optionText = '';
00797 if ( isset( $optionLines[$i] ) )
00798 $optionText = $optionLines[$i];
00799 $optionDescriptionText = '';
00800 if ( isset( $optionDescriptionLines[$i] ) )
00801 $optionDescriptionText = $optionDescriptionLines[$i];
00802 $spacing = $spacingLength - strlen( $optionText );
00803 if ( $optionText or $optionDescriptionText )
00804 $helpText .= ' ';
00805 $helpText .= $optionText;
00806 if ( $i > 0 )
00807 $spacing += 2;
00808 if ( $optionDescriptionText )
00809 $helpText .= str_repeat( ' ', $spacing ) . $optionDescriptionText;
00810 $helpText .= "\n";
00811 }
00812 }
00813 }
00814 if ( count( $optionList ) > 0 )
00815 {
00816 $helpText .= "\nOptions:\n";
00817 $maxLength = 0;
00818 foreach ( $optionList as $optionItem )
00819 {
00820 $maxLength = max( strlen( $optionItem[0] ), $maxLength );
00821 }
00822 $spacingLength = $maxLength + 2;
00823 foreach ( $optionList as $optionItem )
00824 {
00825 $option = $optionItem[0];
00826 $optionDescription = $optionItem[1];
00827 $optionLines = explode( "\n", $option );
00828 $optionDescriptionLines = explode( "\n", $optionDescription );
00829 $count = max( count( $optionLines ), count( $optionDescriptionLines ) );
00830 for ( $i = 0; $i < $count; ++$i )
00831 {
00832 $optionText = '';
00833 if ( isset( $optionLines[$i] ) )
00834 $optionText = $optionLines[$i];
00835 $optionDescriptionText = '';
00836 if ( isset( $optionDescriptionLines[$i] ) )
00837 $optionDescriptionText = $optionDescriptionLines[$i];
00838 $spacing = $spacingLength - strlen( $optionText );
00839 if ( $optionText or $optionDescriptionText )
00840 $helpText .= ' ';
00841 $helpText .= $optionText;
00842 if ( $i > 0 )
00843 $spacing += 2;
00844 if ( $optionDescriptionText )
00845 $helpText .= str_repeat( ' ', $spacing ) . $optionDescriptionText;
00846 $helpText .= "\n";
00847 }
00848 }
00849 }
00850 $cli->output( $helpText );
00851 }
00852
00853 function getOptions( $config = '', $argumentConfig = '', $optionHelp = false,
00854 $arguments = false, $useStandardOptions = true )
00855 {
00856 if ( is_string( $config ) )
00857 $config = eZCLI::parseOptionString( $config, $optionConfig );
00858 if ( is_string( $argumentConfig ) )
00859 $argumentConfig = eZCLI::parseOptionString( $argumentConfig, $tmpArgumentConfig );
00860
00861 if ( $useStandardOptions )
00862 {
00863 if ( !is_array( $useStandardOptions ) )
00864 $useStandardOptions = array();
00865 $useStandardOptions = array_merge( array( 'debug' => true,
00866 'colors' => true,
00867 'log' => true,
00868 'siteaccess' => true,
00869 'verbose' => true,
00870 'user' => false ),
00871 $useStandardOptions );
00872 }
00873
00874 if ( $useStandardOptions )
00875 {
00876 $optionConfig = $config;
00877 $excludeOptions = array();
00878 $optionString = "[h|help][q|quiet]";
00879 $excludeOptions[] = 'h';
00880 $excludeOptions[] = 'help';
00881 $excludeOptions[] = 'q';
00882 $excludeOptions[] = 'quiet';
00883 if ( $useStandardOptions['debug'] )
00884 {
00885 $optionString .= "[d;*|debug;*]";
00886 $excludeOptions[] = 'd';
00887 $excludeOptions[] = 'debug';
00888 }
00889 if ( $useStandardOptions['colors'] )
00890 {
00891 $optionString .= "[c|colors][no-colors]";
00892 $excludeOptions[] = 'c';
00893 $excludeOptions[] = 'colors';
00894 $excludeOptions[] = 'no-colors';
00895 }
00896 if ( $useStandardOptions['log'] )
00897 {
00898 $optionString .= "[logfiles][no-logfiles]";
00899 $excludeOptions[] = 'logfiles';
00900 $excludeOptions[] = 'no-logfiles';
00901 }
00902 if ( $useStandardOptions['siteaccess'] )
00903 {
00904 $optionString .= "[s:|siteaccess:]";
00905 $excludeOptions[] = 's';
00906 $excludeOptions[] = 'siteaccess';
00907 }
00908 if ( $useStandardOptions['user'] )
00909 {
00910 $optionString .= "[l:|login:][p:|password:]";
00911 $excludeOptions[] = 'l';
00912 $excludeOptions[] = 'login';
00913 $excludeOptions[] = 'p';
00914 $excludeOptions[] = 'password';
00915 }
00916 if ( $useStandardOptions['verbose'] )
00917 {
00918 $optionString .= "[v*|verbose*]";
00919 $excludeOptions[] = 'v';
00920 $excludeOptions[] = 'verbose';
00921 }
00922 $config = eZCLI::parseOptionString( $optionString, $optionConfig );
00923 }
00924 $cli =& eZCLI::instance();
00925 $options = $cli->getOptions( $config, $argumentConfig, $arguments );
00926 $this->CurrentOptionConfig = $config;
00927 $this->CurrentOptions = $options;
00928 $this->CurrentStandardOptions = $useStandardOptions;
00929 $this->CurrentExcludeOptions = $excludeOptions;
00930 $this->CurrentOptionHelp = $optionHelp;
00931 $this->ArgumentConfig = $argumentConfig;
00932 if ( !$options )
00933 {
00934 if ( !$this->IsInitialized )
00935 $this->initialize();
00936 $this->shutdown( 1 );
00937 }
00938 if ( $useStandardOptions )
00939 {
00940 if ( $options['quiet'] )
00941 $this->setIsQuiet( true );
00942 $useColors = true;
00943 if ( $options['colors'] )
00944 $useColors = true;
00945 if ( $options['no-colors'] )
00946 $useColors = false;
00947 $cli->setUseStyles( $useColors );
00948 if ( $options['debug'] )
00949 {
00950 $levels = array();
00951 foreach ( $options['debug'] as $debugOption )
00952 {
00953 $levels = array_merge( $levels, explode( ',', $debugOption ) );
00954 }
00955 $allowedDebugLevels = array();
00956 $useDebugAccumulators = false;
00957 $useDebugTimingpoints = false;
00958 $useIncludeFiles = false;
00959 foreach ( $levels as $level )
00960 {
00961 if ( $level == 'all' )
00962 {
00963 $useDebugAccumulators = true;
00964 $allowedDebugLevels = false;
00965 $useDebugTimingpoints = true;
00966 break;
00967 }
00968 if ( $level == 'accumulator' )
00969 {
00970 $useDebugAccumulators = true;
00971 continue;
00972 }
00973 if ( $level == 'timing' )
00974 {
00975 $useDebugTimingpoints = true;
00976 continue;
00977 }
00978 if ( $level == 'include' )
00979 {
00980 $useIncludeFiles = true;
00981 }
00982 if ( $level == 'error' )
00983 $level = EZ_LEVEL_ERROR;
00984 else if ( $level == 'warning' )
00985 $level = EZ_LEVEL_WARNING;
00986 else if ( $level == 'debug' )
00987 $level = EZ_LEVEL_DEBUG;
00988 else if ( $level == 'notice' )
00989 $level = EZ_LEVEL_NOTICE;
00990 else if ( $level == 'timing' )
00991 $level = EZ_LEVEL_TIMING;
00992 $allowedDebugLevels[] = $level;
00993 }
00994 $this->setUseDebugOutput( true );
00995 $this->setAllowedDebugLevels( $allowedDebugLevels );
00996 $this->setUseDebugAccumulators( $useDebugAccumulators );
00997 $this->setUseDebugTimingPoints( $useDebugTimingpoints );
00998 $this->setUseIncludeFiles( $useIncludeFiles );
00999 $this->setDebugMessage( "\n\n" . str_repeat( '#', 36 ) . $cli->style( 'emphasize' ) . " DEBUG " . $cli->style( 'emphasize-end' ) . str_repeat( '#', 36 ) . "\n" );
01000 }
01001 if ( count( $options['verbose'] ) > 0 )
01002 {
01003 $this->setShowVerboseOutput( count( $options['verbose'] ) );
01004 }
01005 if ( $options['help'] )
01006 {
01007 if ( !$this->IsInitialized )
01008 $this->initialize();
01009 $this->showHelp();
01010 $this->shutdown( 0 );
01011 }
01012 if ( isset( $options['siteaccess'] ) and $options['siteaccess'] )
01013 $this->setUseSiteAccess( $options['siteaccess'] );
01014
01015 if ( isset( $options['login'] ) and $options['login'] )
01016 $this->setUser( $options['login'], isset( $options['password'] ) ? $options['password'] : false );
01017 }
01018 return $options;
01019 }
01020
01021 function &instance( $settings = array() )
01022 {
01023 $implementation =& $GLOBALS['eZScriptInstance'];
01024 if ( !isset( $implementation ) or
01025 get_class( $implementation ) != 'ezscript' )
01026 {
01027 $implementation = new eZScript( $settings );
01028 }
01029 return $implementation;
01030 }
01031
01032
01033
01034
01035
01036 function updateDebugSettings( $useDebug = null )
01037 {
01038 global $debugOutput;
01039 global $useLogFiles;
01040 $ini =& eZINI::instance();
01041 $cli =& eZCLI::instance();
01042 $debugSettings = array();
01043 $debugSettings['debug-enabled'] = ( $ini->variable( 'DebugSettings', 'DebugOutput' ) == 'enabled' and
01044 $ini->variable( 'DebugSettings', 'ScriptDebugOutput' ) == 'enabled' );
01045 if ( $useDebug !== null )
01046 $debugSettings['debug-enabled'] = $useDebug;
01047 $debugSettings['debug-by-ip'] = $ini->variable( 'DebugSettings', 'DebugByIP' ) == 'enabled';
01048 $debugSettings['debug-ip-list'] = $ini->variable( 'DebugSettings', 'DebugIPList' );
01049 if ( isset( $debugOutput ) )
01050 $debugSettings['debug-enabled'] = $debugOutput;
01051 $debugSettings['debug-log-files-enabled'] = $useLogFiles;
01052 if ( $cli->useStyles() and
01053 !$cli->isWebOutput() )
01054 {
01055 $debugSettings['debug-styles'] = $cli->terminalStyles();
01056 }
01057 $logList = $ini->variable( 'DebugSettings', 'AlwaysLog' );
01058 $logMap = array( 'notice' => EZ_LEVEL_NOTICE,
01059 'warning' => EZ_LEVEL_WARNING,
01060 'error' => EZ_LEVEL_ERROR,
01061 'debug' => EZ_LEVEL_DEBUG );
01062 $debugSettings['always-log'] = array();
01063 foreach ( $logMap as $name => $level )
01064 {
01065 $debugSettings['always-log'][$level] = in_array( $name, $logList );
01066 }
01067 eZDebug::updateSettings( $debugSettings );
01068 }
01069
01070
01071
01072
01073
01074 function updateTextCodecSettings()
01075 {
01076 $ini =& eZINI::instance( 'i18n.ini' );
01077 $i18nSettings = array();
01078 $i18nSettings['internal-charset'] = $ini->variable( 'CharacterSettings', 'Charset' );
01079 $i18nSettings['http-charset'] = $ini->variable( 'CharacterSettings', 'HTTPCharset' );
01080 $i18nSettings['mbstring-extension'] = $ini->variable( 'CharacterSettings', 'MBStringExtension' ) == 'enabled';
01081 include_once( 'lib/ezi18n/classes/eztextcodec.php' );
01082 eZTextCodec::updateSettings( $i18nSettings );
01083 }
01084
01085
01086 var $InitializationErrorMessage;
01087 var $DebugMessage;
01088 var $UseDebugOutput;
01089 var $UseSession;
01090 var $UseExtensions;
01091 var $UseModules;
01092 var $User;
01093 var $SiteAccess;
01094 var $ExitCode;
01095 var $IsQuiet;
01096 var $ShowVerbose;
01097 }
01098
01099 function eZDBCleanup()
01100 {
01101 if ( class_exists( 'ezdb' )
01102 and eZDB::hasInstance() )
01103 {
01104 $db =& eZDB::instance();
01105 $db->setIsSQLOutputEnabled( false );
01106 }
01107
01108 }
01109
01110 function eZFatalError()
01111 {
01112 $cli =& eZCLI::instance();
01113 $endl = $cli->endlineString();
01114 $webOutput = $cli->isWebOutput();
01115 $bold = $cli->style( 'bold' );
01116 $unbold = $cli->style( 'bold-end' );
01117 $par = $cli->style( 'paragraph' );
01118 $unpar = $cli->style( 'paragraph-end' );
01119
01120 $allowedDebugLevels = true;
01121 $useDebugAccumulators = true;
01122 $useDebugTimingpoints = true;
01123
01124 eZDebug::setHandleType( EZ_HANDLE_NONE );
01125 if ( !$webOutput )
01126 fputs( STDERR, $endl );
01127 fputs( STDERR, $bold . "Fatal error" . $unbold . ": eZ publish did not finish its request$endl" );
01128 fputs( STDERR, $par . "The execution of eZ publish was abruptly ended, the debug output is present below." . $unpar . $endl );
01129 fputs( STDERR, eZDebug::printReport( false, $webOutput, true ) );
01130 }
01131
01132
01133
01134
01135 function eZUpdateDebugSettings( $useDebug = null )
01136 {
01137 }
01138
01139
01140
01141
01142 function eZUpdateTextCodecSettings()
01143 {
01144 }
01145
01146 ?>