From: Tim Starling Date: Sun, 20 May 2018 14:26:46 +0000 (+0200) Subject: Exit maintenance script with non-zero status if execute() returns false X-Git-Tag: 1.34.0-rc.0~5226^2 X-Git-Url: http://git.cyclocoop.org/data/%24self?a=commitdiff_plain;h=72f2e984992b2beb174b2b91761bd36311f5c260;p=lhc%2Fweb%2Fwiklou.git Exit maintenance script with non-zero status if execute() returns false There's a whole lot of shutdown code in doMaintenance.php that is skipped when you use exit() directly. In HHVM by default, destructors are not even called. There are a few cases where maintenance scripts want to do something after doMaintenance.php returns, so returning null should continue to mean no exit. Change-Id: I0891e2ee3af7ef2c64c03b70edcf9e281ce1e7ba --- diff --git a/maintenance/Maintenance.php b/maintenance/Maintenance.php index 13fee9c6ca..80fd7b9f70 100644 --- a/maintenance/Maintenance.php +++ b/maintenance/Maintenance.php @@ -202,6 +202,11 @@ abstract class Maintenance { /** * Do the actual work. All child classes will need to implement this + * + * @return bool|null True for success, false for failure. Not returning + * a value, or returning null, is also interpreted as success. Returning + * false for failure will cause doMaintenance.php to exit the process + * with a non-zero exit status. */ abstract public function execute(); diff --git a/maintenance/doMaintenance.php b/maintenance/doMaintenance.php index f3fb32ce62..1f1a4c721b 100644 --- a/maintenance/doMaintenance.php +++ b/maintenance/doMaintenance.php @@ -91,7 +91,7 @@ $maintenance->checkRequiredExtensions(); $maintenance->setAgentAndTriggers(); // Do the work -$maintenance->execute(); +$success = $maintenance->execute(); // Potentially debug globals $maintenance->globals(); @@ -111,3 +111,8 @@ if ( isset( $lbFactory ) ) { $lbFactory->commitMasterChanges( 'doMaintenance' ); $lbFactory->shutdown( $lbFactory::SHUTDOWN_NO_CHRONPROT ); } + +// Exit with an error status if execute() returned false +if ( $success === false ) { + exit( 1 ); +}