[MediaWiki-commits] [Gerrit] mediawiki...MediaWikiFarm[master]: Improvement of CLI scripts
Seb35 has submitted this change and it was merged. Change subject: Improvement of CLI scripts .. Improvement of CLI scripts Code: * In case of error, exit codes in CLI were wrongly the same as HTTP return codes, but exit codes in CLI can only be between 0 and 255, so documented some standard codes and implemented it (0=success, 1=missing wiki, 4=user error, 5=internal error) * Deleted the method AbstractMediaWikiFarmScript::postmain which was not really useful * Now AbstractMediaWikiFarmScript::premain and ::main return a boolean about success (and detailled error is in status property) * Added methods AbstractMediaWikiFarmScript::rmdirr and ::copyr to recursively delete and copy directories, it will be useful to manage extensions with Composer * Removed the use of "new static", which is not PHP 5.2 compatible, this temporarily break the performance test Bugs: * When a global array does not exist and we add some elements, a warning was trigerred in MediaWikiFarm::loadMediaWikiConfig * Be sure wg* variables are syntactically correct for PHP, it was not the case for "wgUseExtensionConfirmEdit/QuestyCaptcha" but slash must be here in wfLoadExtension('ConfirmEdit/QuestyCaptcha') so remove the slash and any incorrect character after detecting extension loading mechanism Change-Id: I02db05b939b968fca4b63fe57ea1bd8804c25b78 --- M .gitignore M bin/mwscript.php M src/AbstractMediaWikiFarmScript.php M src/MediaWikiFarm.php M src/MediaWikiFarmScript.php M tests/phpunit/ConfigurationTest.php M tests/phpunit/InstallationIndependantTest.php M tests/phpunit/LoadingTest.php M tests/phpunit/MediaWikiFarmScriptTest.php M tests/phpunit/MediaWikiFarmTestCase.php M tests/phpunit/data/config/extensionssettings.php M tests/phpunit/data/config/settings.php 12 files changed, 298 insertions(+), 63 deletions(-) Approvals: Seb35: Verified; Looks good to me, approved diff --git a/.gitignore b/.gitignore index 49fc920..fa4674d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ .swp .*.swp *~ +.DS_Store +*.kate-swp # Composer & npm /composer.lock diff --git a/bin/mwscript.php b/bin/mwscript.php index 0cc21ee..14751bf 100644 --- a/bin/mwscript.php +++ b/bin/mwscript.php @@ -21,9 +21,7 @@ $wgMediaWikiFarmScript->load(); -$wgMediaWikiFarmScript->main(); - -if( $wgMediaWikiFarmScript->status == 200 ) { +if( $wgMediaWikiFarmScript->main() ) { # Execute the script require $wgMediaWikiFarmScript->argv[0]; diff --git a/src/AbstractMediaWikiFarmScript.php b/src/AbstractMediaWikiFarmScript.php index 1c0e972..328930b 100644 --- a/src/AbstractMediaWikiFarmScript.php +++ b/src/AbstractMediaWikiFarmScript.php @@ -16,6 +16,13 @@ * Using a class instead of a raw script it better for testability purposes and to use * less global variables (in fact none; the only global variable written are for * compatibility purposes, e.g. PHPUnit expects $_SERVER['argv']). + * + * It is recommended to use the following values for status (in CLI, it must be a number + * between 0 and 255) and explain it in long help: + * - 0 = success + * - 1 = missing wiki (similar to HTTP 404) + * - 4 = user error, like a missing parameter (similar to HTTP 400) + * - 5 = internal error in farm configuration (similar to HTTP 500) */ abstract class AbstractMediaWikiFarmScript { @@ -152,9 +159,7 @@ @include_once dirname( dirname( __FILE__ ) ) . '/config/MediaWikiFarmDirectories.php'; # Load MediaWikiFarm class symbol - // @codingStandardsIgnoreStart MediaWiki.Usage.DirUsage.FunctionFound require_once dirname( dirname( __FILE__ ) ) . '/src/MediaWikiFarm.php'; - // @codingStandardsIgnoreEnd } /** @@ -162,7 +167,7 @@ * * NB: although it can be seen as superfluous, this is required in some cases to wipe off * the presence of MediaWikiFarm. The MediaWiki script 'tests/phpunit/phpunit.php' and PHPUnit -* need it (precisely $_SERVER['argv']; the other are for consistency). +* need it (precisely $_SERVER['argv']; the others are for consistency). * Perhaps in the future some other globals will be changed, like in $_SERVER: PWD, PHP_SELF, * SCRIPT_NAME, SCRIPT_FILENAME, PATH_TRANSLATED, if it is needed. * @@ -182,42 +187,28 @@ /** * Main program for the script, preliminary part. * -* Although it returns void, the 'status' property can say if there was an error or not, -* and if it becomes different than 0, the main program will (should) return. -* -* @return void. +* @return bool If false, the main program should return. */ function premain() { # Return usage if( $this->argc == 2 && ( $this->argv[1] == '-h' || $this->argv[1] == '--help' ) ) {
[MediaWiki-commits] [Gerrit] mediawiki...MediaWikiFarm[master]: Improvement of CLI scripts
Seb35 has uploaded a new change for review. https://gerrit.wikimedia.org/r/311624 Change subject: Improvement of CLI scripts .. Improvement of CLI scripts Code: * In case of error, exit codes in CLI were wrongly the same as HTTP return codes, but exit codes in CLI can only be between 0 and 255, so documented some standard codes and implemented it (0=success, 1=missing wiki, 4=user error, 5=internal error) * Deleted the method AbstractMediaWikiFarmScript::postmain which was not really useful * Now AbstractMediaWikiFarmScript::premain and ::main return a boolean about success (and detailled error is in status property) * Added methods AbstractMediaWikiFarmScript::rmdirr and ::copyr to recursively delete and copy directories, it will be useful to manage extensions with Composer * Removed the use of "new static", which is not PHP 5.2 compatible, this temporarily break the performance test Bugs: * When a global array does not exist and we add some elements, a warning was trigerred in MediaWikiFarm::loadMediaWikiConfig * Be sure wg* variables are syntactically correct for PHP, it was not the case for "wgUseExtensionConfirmEdit/QuestyCaptcha" but slash must be here in wfLoadExtension('ConfirmEdit/QuestyCaptcha') so remove the slash and any incorrect character after detecting extension loading mechanism Change-Id: I02db05b939b968fca4b63fe57ea1bd8804c25b78 --- M .gitignore M bin/mwscript.php M src/AbstractMediaWikiFarmScript.php M src/MediaWikiFarm.php M src/MediaWikiFarmScript.php M tests/phpunit/ConfigurationTest.php M tests/phpunit/InstallationIndependantTest.php M tests/phpunit/LoadingTest.php M tests/phpunit/MediaWikiFarmScriptTest.php M tests/phpunit/MediaWikiFarmTestCase.php M tests/phpunit/data/config/extensionssettings.php M tests/phpunit/data/config/settings.php 12 files changed, 298 insertions(+), 63 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MediaWikiFarm refs/changes/24/311624/1 diff --git a/.gitignore b/.gitignore index 49fc920..fa4674d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ .swp .*.swp *~ +.DS_Store +*.kate-swp # Composer & npm /composer.lock diff --git a/bin/mwscript.php b/bin/mwscript.php index 0cc21ee..14751bf 100644 --- a/bin/mwscript.php +++ b/bin/mwscript.php @@ -21,9 +21,7 @@ $wgMediaWikiFarmScript->load(); -$wgMediaWikiFarmScript->main(); - -if( $wgMediaWikiFarmScript->status == 200 ) { +if( $wgMediaWikiFarmScript->main() ) { # Execute the script require $wgMediaWikiFarmScript->argv[0]; diff --git a/src/AbstractMediaWikiFarmScript.php b/src/AbstractMediaWikiFarmScript.php index 1c0e972..328930b 100644 --- a/src/AbstractMediaWikiFarmScript.php +++ b/src/AbstractMediaWikiFarmScript.php @@ -16,6 +16,13 @@ * Using a class instead of a raw script it better for testability purposes and to use * less global variables (in fact none; the only global variable written are for * compatibility purposes, e.g. PHPUnit expects $_SERVER['argv']). + * + * It is recommended to use the following values for status (in CLI, it must be a number + * between 0 and 255) and explain it in long help: + * - 0 = success + * - 1 = missing wiki (similar to HTTP 404) + * - 4 = user error, like a missing parameter (similar to HTTP 400) + * - 5 = internal error in farm configuration (similar to HTTP 500) */ abstract class AbstractMediaWikiFarmScript { @@ -152,9 +159,7 @@ @include_once dirname( dirname( __FILE__ ) ) . '/config/MediaWikiFarmDirectories.php'; # Load MediaWikiFarm class symbol - // @codingStandardsIgnoreStart MediaWiki.Usage.DirUsage.FunctionFound require_once dirname( dirname( __FILE__ ) ) . '/src/MediaWikiFarm.php'; - // @codingStandardsIgnoreEnd } /** @@ -162,7 +167,7 @@ * * NB: although it can be seen as superfluous, this is required in some cases to wipe off * the presence of MediaWikiFarm. The MediaWiki script 'tests/phpunit/phpunit.php' and PHPUnit -* need it (precisely $_SERVER['argv']; the other are for consistency). +* need it (precisely $_SERVER['argv']; the others are for consistency). * Perhaps in the future some other globals will be changed, like in $_SERVER: PWD, PHP_SELF, * SCRIPT_NAME, SCRIPT_FILENAME, PATH_TRANSLATED, if it is needed. * @@ -182,42 +187,28 @@ /** * Main program for the script, preliminary part. * -* Although it returns void, the 'status' property can say if there was an error or not, -* and if it becomes different than 0, the main program will (should) return. -* -* @return void. +* @return bool If false, the main program should return. */ function premain() { # Return usage if( $this->