aboutsummaryrefslogtreecommitdiffstats
path: root/maintenance/includes
diff options
context:
space:
mode:
authorReedy <reedy@wikimedia.org>2020-02-28 21:51:24 +0000
committerReedy <reedy@wikimedia.org>2020-02-28 21:51:24 +0000
commit2cdeb26d0c2bc6f3fb4d05d7b8b72c4a601b3da7 (patch)
treed8df652b52d1cd13b65608a70785357a137a72fe /maintenance/includes
parent80cba58c5a49acfd2688de038c236c50fb08ade2 (diff)
downloadmediawikicore-2cdeb26d0c2bc6f3fb4d05d7b8b72c4a601b3da7.tar.gz
mediawikicore-2cdeb26d0c2bc6f3fb4d05d7b8b72c4a601b3da7.zip
Split FakeMaintenance and LoggedUpdateMaintenance to their own files
Change-Id: I4c95f910993fffa060c2860847b8cfff1612ccf5
Diffstat (limited to 'maintenance/includes')
-rw-r--r--maintenance/includes/FakeMaintenance.php31
-rw-r--r--maintenance/includes/LoggedUpdateMaintenance.php77
2 files changed, 108 insertions, 0 deletions
diff --git a/maintenance/includes/FakeMaintenance.php b/maintenance/includes/FakeMaintenance.php
new file mode 100644
index 000000000000..1365141c18e4
--- /dev/null
+++ b/maintenance/includes/FakeMaintenance.php
@@ -0,0 +1,31 @@
+<?php
+/**
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup Maintenance
+ * @defgroup Maintenance Maintenance
+ */
+
+/**
+ * Fake maintenance wrapper, mostly used for the web installer/updater
+ */
+class FakeMaintenance extends Maintenance {
+ protected $mSelf = "FakeMaintenanceScript";
+
+ public function execute() {
+ }
+}
diff --git a/maintenance/includes/LoggedUpdateMaintenance.php b/maintenance/includes/LoggedUpdateMaintenance.php
new file mode 100644
index 000000000000..0e3f7c41bb7a
--- /dev/null
+++ b/maintenance/includes/LoggedUpdateMaintenance.php
@@ -0,0 +1,77 @@
+<?php
+/**
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup Maintenance
+ * @defgroup Maintenance Maintenance
+ */
+
+/**
+ * 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();
+}