From 7def03fe809aa33512bb317a29e0410c9d5e99b6 Mon Sep 17 00:00:00 2001 From: Daimona Eaytoy Date: Tue, 3 Mar 2020 14:12:46 +0000 Subject: [PATCH] Revert "Split FakeMaintenance and LoggedUpdateMaintenance to their own files" This reverts commit 2cdeb26d0c2bc6f3fb4d05d7b8b72c4a601b3da7. Reason for revert: broke roughly all scripts extending LoggedUpdateMaintenance. Bug: T246754 Change-Id: Icfe3da924c364b4b4f9286871aeb0aa9f1bbff1a --- .phpcs.xml | 1 + autoload.php | 4 +- maintenance/Maintenance.php | 66 ++++++++++++++++ maintenance/includes/FakeMaintenance.php | 31 -------- .../includes/LoggedUpdateMaintenance.php | 77 ------------------- 5 files changed, 69 insertions(+), 110 deletions(-) delete mode 100644 maintenance/includes/FakeMaintenance.php delete mode 100644 maintenance/includes/LoggedUpdateMaintenance.php diff --git a/.phpcs.xml b/.phpcs.xml index dbef72b6948..2b8b3c8d9a8 100644 --- a/.phpcs.xml +++ b/.phpcs.xml @@ -195,6 +195,7 @@ any new occurrences. --> */maintenance/dumpIterator\.php + */maintenance/Maintenance\.php */maintenance/findDeprecated\.php */maintenance/storage/recompressTracked\.php */maintenance/preprocessorFuzzTest\.php diff --git a/autoload.php b/autoload.php index fa8b3ef5727..8dd14285b17 100644 --- a/autoload.php +++ b/autoload.php @@ -495,7 +495,7 @@ $wgAutoloadLocalClasses = [ 'FSFileOpHandle' => __DIR__ . '/includes/libs/filebackend/fileophandle/FSFileOpHandle.php', 'FSLockManager' => __DIR__ . '/includes/libs/lockmanager/FSLockManager.php', 'FakeConverter' => __DIR__ . '/languages/TrivialLanguageConverter.php', - 'FakeMaintenance' => __DIR__ . '/maintenance/includes/FakeMaintenance.php', + 'FakeMaintenance' => __DIR__ . '/maintenance/Maintenance.php', 'FakeResultWrapper' => __DIR__ . '/includes/libs/rdbms/database/resultwrapper/FakeResultWrapper.php', 'FatalError' => __DIR__ . '/includes/exception/FatalError.php', 'FauxRequest' => __DIR__ . '/includes/FauxRequest.php', @@ -800,7 +800,7 @@ $wgAutoloadLocalClasses = [ 'LogPage' => __DIR__ . '/includes/logging/LogPage.php', 'LogPager' => __DIR__ . '/includes/logging/LogPager.php', 'LoggedOutEditToken' => __DIR__ . '/includes/user/LoggedOutEditToken.php', - 'LoggedUpdateMaintenance' => __DIR__ . '/maintenance/includes/LoggedUpdateMaintenance.php', + 'LoggedUpdateMaintenance' => __DIR__ . '/maintenance/Maintenance.php', 'LoginHelper' => __DIR__ . '/includes/specials/helpers/LoginHelper.php', 'LoginSignupSpecialPage' => __DIR__ . '/includes/specialpage/LoginSignupSpecialPage.php', 'MSCompoundFileReader' => __DIR__ . '/includes/libs/mime/MSCompoundFileReader.php', diff --git a/maintenance/Maintenance.php b/maintenance/Maintenance.php index d88f7c997ba..b9242c5d780 100644 --- a/maintenance/Maintenance.php +++ b/maintenance/Maintenance.php @@ -1722,3 +1722,69 @@ abstract class Maintenance { require_once __DIR__ . '/../tests/common/TestsAutoLoader.php'; } } + +/** + * Fake maintenance wrapper, mostly used for the web installer/updater + */ +class FakeMaintenance extends Maintenance { + protected $mSelf = "FakeMaintenanceScript"; + + public function execute() { + } +} + +/** + * Class for scripts that perform database maintenance and want to log the + * update in `updatelog` so we can later skip it + */ +abstract class LoggedUpdateMaintenance extends Maintenance { + public function __construct() { + parent::__construct(); + $this->addOption( 'force', 'Run the update even if it was completed already' ); + $this->setBatchSize( 200 ); + } + + public function execute() { + $db = $this->getDB( DB_MASTER ); + $key = $this->getUpdateKey(); + + if ( !$this->hasOption( 'force' ) + && $db->selectRow( 'updatelog', '1', [ 'ul_key' => $key ], __METHOD__ ) + ) { + $this->output( "..." . $this->updateSkippedMessage() . "\n" ); + + return true; + } + + if ( !$this->doDBUpdates() ) { + return false; + } + + $db->insert( 'updatelog', [ 'ul_key' => $key ], __METHOD__, [ 'IGNORE' ] ); + + return true; + } + + /** + * Message to show that the update was done already and was just skipped + * @return string + */ + protected function updateSkippedMessage() { + $key = $this->getUpdateKey(); + + return "Update '{$key}' already logged as completed. Use --force to run it again."; + } + + /** + * Do the actual work. All child classes will need to implement this. + * Return true to log the update as done or false (usually on failure). + * @return bool + */ + abstract protected function doDBUpdates(); + + /** + * Get the update key name to go in the update log table + * @return string + */ + abstract protected function getUpdateKey(); +} diff --git a/maintenance/includes/FakeMaintenance.php b/maintenance/includes/FakeMaintenance.php deleted file mode 100644 index 1365141c18e..00000000000 --- a/maintenance/includes/FakeMaintenance.php +++ /dev/null @@ -1,31 +0,0 @@ -addOption( 'force', 'Run the update even if it was completed already' ); - $this->setBatchSize( 200 ); - } - - public function execute() { - $db = $this->getDB( DB_MASTER ); - $key = $this->getUpdateKey(); - - if ( !$this->hasOption( 'force' ) - && $db->selectRow( 'updatelog', '1', [ 'ul_key' => $key ], __METHOD__ ) - ) { - $this->output( "..." . $this->updateSkippedMessage() . "\n" ); - - return true; - } - - if ( !$this->doDBUpdates() ) { - return false; - } - - $db->insert( 'updatelog', [ 'ul_key' => $key ], __METHOD__, [ 'IGNORE' ] ); - - return true; - } - - /** - * Message to show that the update was done already and was just skipped - * @return string - */ - protected function updateSkippedMessage() { - $key = $this->getUpdateKey(); - - return "Update '{$key}' already logged as completed. Use --force to run it again."; - } - - /** - * Do the actual work. All child classes will need to implement this. - * Return true to log the update as done or false (usually on failure). - * @return bool - */ - abstract protected function doDBUpdates(); - - /** - * Get the update key name to go in the update log table - * @return string - */ - abstract protected function getUpdateKey(); -}