2010-07-08 14:57:19 +00:00
|
|
|
<?php
|
2010-08-21 18:20:09 +00:00
|
|
|
/**
|
|
|
|
|
* DBMS-specific updater helper.
|
|
|
|
|
*
|
2012-05-06 05:50:15 +00:00
|
|
|
* 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
|
|
|
|
|
*
|
2010-08-21 18:20:09 +00:00
|
|
|
* @file
|
|
|
|
|
* @ingroup Deployment
|
|
|
|
|
*/
|
2017-02-07 04:49:57 +00:00
|
|
|
use Wikimedia\Rdbms\Database;
|
2017-02-10 18:09:05 +00:00
|
|
|
use Wikimedia\Rdbms\IDatabase;
|
2016-09-23 03:42:38 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2010-10-31 19:07:05 +00:00
|
|
|
|
2013-05-07 23:00:15 +00:00
|
|
|
require_once __DIR__ . '/../../maintenance/Maintenance.php';
|
2010-10-31 19:07:05 +00:00
|
|
|
|
2011-10-11 18:30:50 +00:00
|
|
|
/**
|
2010-07-08 14:57:19 +00:00
|
|
|
* Class for handling database updates. Roughly based off of updaters.inc, with
|
|
|
|
|
* a few improvements :)
|
2010-12-16 11:20:39 +00:00
|
|
|
*
|
2010-07-29 18:36:39 +00:00
|
|
|
* @ingroup Deployment
|
|
|
|
|
* @since 1.17
|
2010-07-08 14:57:19 +00:00
|
|
|
*/
|
2010-07-20 22:28:50 +00:00
|
|
|
abstract class DatabaseUpdater {
|
2010-07-20 11:35:38 +00:00
|
|
|
/**
|
|
|
|
|
* Array of updates to perform on the database
|
2010-07-20 22:28:50 +00:00
|
|
|
*
|
2010-07-20 11:35:38 +00:00
|
|
|
* @var array
|
|
|
|
|
*/
|
2016-02-17 09:09:32 +00:00
|
|
|
protected $updates = [];
|
2010-07-08 14:57:19 +00:00
|
|
|
|
2012-11-22 03:53:24 +00:00
|
|
|
/**
|
|
|
|
|
* Array of updates that were skipped
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
2016-02-17 09:09:32 +00:00
|
|
|
protected $updatesSkipped = [];
|
2012-11-22 03:53:24 +00:00
|
|
|
|
2011-01-31 20:00:59 +00:00
|
|
|
/**
|
|
|
|
|
* List of extension-provided database updates
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
2016-02-17 09:09:32 +00:00
|
|
|
protected $extensionUpdates = [];
|
2010-09-11 08:23:26 +00:00
|
|
|
|
2010-12-27 13:56:20 +00:00
|
|
|
/**
|
|
|
|
|
* Handle to the database subclass
|
|
|
|
|
*
|
2016-09-28 22:53:02 +00:00
|
|
|
* @var Database
|
2010-12-27 13:56:20 +00:00
|
|
|
*/
|
2010-07-20 11:35:38 +00:00
|
|
|
protected $db;
|
2010-07-08 14:57:19 +00:00
|
|
|
|
2017-03-06 21:06:43 +00:00
|
|
|
/**
|
|
|
|
|
* @var Maintenance
|
|
|
|
|
*/
|
|
|
|
|
protected $maintenance;
|
|
|
|
|
|
2010-08-15 18:13:23 +00:00
|
|
|
protected $shared = false;
|
|
|
|
|
|
2012-10-12 18:52:29 +00:00
|
|
|
/**
|
2016-03-14 15:54:50 +00:00
|
|
|
* @var string[] Scripts to run after database update
|
2012-10-12 18:52:29 +00:00
|
|
|
* Should be a subclass of LoggedUpdateMaintenance
|
|
|
|
|
*/
|
2016-02-17 09:09:32 +00:00
|
|
|
protected $postDatabaseUpdateMaintenance = [
|
2016-03-14 15:54:50 +00:00
|
|
|
DeleteDefaultMessages::class,
|
|
|
|
|
PopulateRevisionLength::class,
|
|
|
|
|
PopulateRevisionSha1::class,
|
|
|
|
|
PopulateImageSha1::class,
|
|
|
|
|
FixExtLinksProtocolRelative::class,
|
|
|
|
|
PopulateFilearchiveSha1::class,
|
|
|
|
|
PopulateBacklinkNamespace::class,
|
|
|
|
|
FixDefaultJsonContentPages::class,
|
2016-07-13 15:30:37 +00:00
|
|
|
CleanupEmptyCategories::class,
|
2016-10-06 02:55:46 +00:00
|
|
|
AddRFCAndPMIDInterwiki::class,
|
2017-04-21 16:17:59 +00:00
|
|
|
PopulatePPSortKey::class,
|
|
|
|
|
PopulateIpChanges::class,
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2010-08-16 14:23:28 +00:00
|
|
|
|
2012-11-22 03:53:24 +00:00
|
|
|
/**
|
|
|
|
|
* File handle for SQL output.
|
|
|
|
|
*
|
2013-10-08 16:20:08 +00:00
|
|
|
* @var resource
|
2012-11-22 03:53:24 +00:00
|
|
|
*/
|
|
|
|
|
protected $fileHandle = null;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Flag specifying whether or not to skip schema (e.g. SQL-only) updates.
|
|
|
|
|
*
|
|
|
|
|
* @var bool
|
|
|
|
|
*/
|
|
|
|
|
protected $skipSchema = false;
|
|
|
|
|
|
2013-11-01 18:24:18 +00:00
|
|
|
/**
|
|
|
|
|
* Hold the value of $wgContentHandlerUseDB during the upgrade.
|
|
|
|
|
*/
|
|
|
|
|
protected $holdContentHandlerUseDB = true;
|
|
|
|
|
|
2010-09-07 14:33:11 +00:00
|
|
|
/**
|
2017-08-11 00:23:16 +00:00
|
|
|
* @param Database &$db To perform updates on
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param bool $shared Whether to perform updates on shared tables
|
2013-10-08 16:20:08 +00:00
|
|
|
* @param Maintenance $maintenance Maintenance object which created us
|
2010-09-07 14:33:11 +00:00
|
|
|
*/
|
2016-09-26 22:40:07 +00:00
|
|
|
protected function __construct( Database &$db, $shared, Maintenance $maintenance = null ) {
|
2010-07-08 14:57:19 +00:00
|
|
|
$this->db = $db;
|
2011-01-06 19:25:47 +00:00
|
|
|
$this->db->setFlag( DBO_DDLMODE ); // For Oracle's handling of schema files
|
2010-08-15 18:13:23 +00:00
|
|
|
$this->shared = $shared;
|
2010-10-27 14:38:31 +00:00
|
|
|
if ( $maintenance ) {
|
|
|
|
|
$this->maintenance = $maintenance;
|
2012-11-22 03:53:24 +00:00
|
|
|
$this->fileHandle = $maintenance->fileHandle;
|
2010-10-27 14:38:31 +00:00
|
|
|
} else {
|
|
|
|
|
$this->maintenance = new FakeMaintenance;
|
|
|
|
|
}
|
2011-06-01 08:27:51 +00:00
|
|
|
$this->maintenance->setDB( $db );
|
2010-09-07 14:33:11 +00:00
|
|
|
$this->initOldGlobals();
|
2011-06-05 19:52:03 +00:00
|
|
|
$this->loadExtensions();
|
2016-02-17 09:09:32 +00:00
|
|
|
Hooks::run( 'LoadExtensionSchemaUpdates', [ $this ] );
|
2010-09-07 14:33:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Initialize all of the old globals. One day this should all become
|
|
|
|
|
* something much nicer
|
|
|
|
|
*/
|
|
|
|
|
private function initOldGlobals() {
|
2010-09-12 16:48:03 +00:00
|
|
|
global $wgExtNewTables, $wgExtNewFields, $wgExtPGNewFields,
|
2010-09-07 14:33:11 +00:00
|
|
|
$wgExtPGAlteredFields, $wgExtNewIndexes, $wgExtModifiedFields;
|
|
|
|
|
|
|
|
|
|
# For extensions only, should be populated via hooks
|
|
|
|
|
# $wgDBtype should be checked to specifiy the proper file
|
2016-02-17 09:09:32 +00:00
|
|
|
$wgExtNewTables = []; // table, dir
|
|
|
|
|
$wgExtNewFields = []; // table, column, dir
|
|
|
|
|
$wgExtPGNewFields = []; // table, column, column attributes; for PostgreSQL
|
|
|
|
|
$wgExtPGAlteredFields = []; // table, column, new type, conversion method; for PostgreSQL
|
|
|
|
|
$wgExtNewIndexes = []; // table, index, dir
|
|
|
|
|
$wgExtModifiedFields = []; // table, index, dir
|
2010-07-20 22:28:50 +00:00
|
|
|
}
|
|
|
|
|
|
2011-06-05 19:52:03 +00:00
|
|
|
/**
|
2013-10-23 12:16:03 +00:00
|
|
|
* Loads LocalSettings.php, if needed, and initialises everything needed for
|
|
|
|
|
* LoadExtensionSchemaUpdates hook.
|
2011-06-05 19:52:03 +00:00
|
|
|
*/
|
|
|
|
|
private function loadExtensions() {
|
|
|
|
|
if ( !defined( 'MEDIAWIKI_INSTALL' ) ) {
|
|
|
|
|
return; // already loaded
|
|
|
|
|
}
|
|
|
|
|
$vars = Installer::getExistingLocalSettings();
|
2015-06-08 00:04:07 +00:00
|
|
|
|
|
|
|
|
$registry = ExtensionRegistry::getInstance();
|
|
|
|
|
$queue = $registry->getQueue();
|
|
|
|
|
// Don't accidentally load extensions in the future
|
|
|
|
|
$registry->clearQueue();
|
|
|
|
|
|
|
|
|
|
// This will automatically add "AutoloadClasses" to $wgAutoloadClasses
|
|
|
|
|
$data = $registry->readFromQueue( $queue );
|
2016-02-17 09:09:32 +00:00
|
|
|
$hooks = [ 'wgHooks' => [ 'LoadExtensionSchemaUpdates' => [] ] ];
|
2015-06-08 00:04:07 +00:00
|
|
|
if ( isset( $data['globals']['wgHooks']['LoadExtensionSchemaUpdates'] ) ) {
|
|
|
|
|
$hooks = $data['globals']['wgHooks']['LoadExtensionSchemaUpdates'];
|
2011-06-05 19:52:03 +00:00
|
|
|
}
|
2015-06-08 00:04:07 +00:00
|
|
|
if ( $vars && isset( $vars['wgHooks']['LoadExtensionSchemaUpdates'] ) ) {
|
|
|
|
|
$hooks = array_merge_recursive( $hooks, $vars['wgHooks']['LoadExtensionSchemaUpdates'] );
|
2011-06-05 19:52:03 +00:00
|
|
|
}
|
|
|
|
|
global $wgHooks, $wgAutoloadClasses;
|
2015-06-08 00:04:07 +00:00
|
|
|
$wgHooks['LoadExtensionSchemaUpdates'] = $hooks;
|
|
|
|
|
if ( $vars && isset( $vars['wgAutoloadClasses'] ) ) {
|
|
|
|
|
$wgAutoloadClasses += $vars['wgAutoloadClasses'];
|
|
|
|
|
}
|
2011-06-05 19:52:03 +00:00
|
|
|
}
|
|
|
|
|
|
2011-01-02 08:33:47 +00:00
|
|
|
/**
|
2016-09-21 20:39:00 +00:00
|
|
|
* @param Database $db
|
2011-01-02 08:33:47 +00:00
|
|
|
* @param bool $shared
|
2017-12-28 15:31:56 +00:00
|
|
|
* @param Maintenance|null $maintenance
|
2014-04-09 10:33:55 +00:00
|
|
|
*
|
|
|
|
|
* @throws MWException
|
2011-01-31 20:00:59 +00:00
|
|
|
* @return DatabaseUpdater
|
2011-01-02 08:33:47 +00:00
|
|
|
*/
|
2017-12-28 15:31:56 +00:00
|
|
|
public static function newForDB( Database $db, $shared = false, Maintenance $maintenance = null ) {
|
2010-08-15 18:55:08 +00:00
|
|
|
$type = $db->getType();
|
2013-04-17 14:52:47 +00:00
|
|
|
if ( in_array( $type, Installer::getDBTypes() ) ) {
|
2010-08-15 18:55:08 +00:00
|
|
|
$class = ucfirst( $type ) . 'Updater';
|
2013-10-08 11:43:42 +00:00
|
|
|
|
2010-10-27 14:38:31 +00:00
|
|
|
return new $class( $db, $shared, $maintenance );
|
2010-08-15 18:55:08 +00:00
|
|
|
} else {
|
|
|
|
|
throw new MWException( __METHOD__ . ' called for unsupported $wgDBtype' );
|
2010-07-08 14:57:19 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-11 08:23:26 +00:00
|
|
|
/**
|
|
|
|
|
* Get a database connection to run updates
|
|
|
|
|
*
|
2016-09-28 22:53:02 +00:00
|
|
|
* @return Database
|
2010-09-11 08:23:26 +00:00
|
|
|
*/
|
|
|
|
|
public function getDB() {
|
|
|
|
|
return $this->db;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-01 15:11:06 +00:00
|
|
|
/**
|
2010-12-17 15:31:01 +00:00
|
|
|
* Output some text. If we're running from web, escape the text first.
|
2010-10-01 15:11:06 +00:00
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $str Text to output
|
2010-10-01 15:11:06 +00:00
|
|
|
*/
|
2010-12-17 15:17:13 +00:00
|
|
|
public function output( $str ) {
|
2010-10-27 14:38:31 +00:00
|
|
|
if ( $this->maintenance->isQuiet() ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2010-12-17 15:31:01 +00:00
|
|
|
global $wgCommandLineMode;
|
2013-04-17 14:52:47 +00:00
|
|
|
if ( !$wgCommandLineMode ) {
|
2010-12-17 15:31:01 +00:00
|
|
|
$str = htmlspecialchars( $str );
|
|
|
|
|
}
|
|
|
|
|
echo $str;
|
|
|
|
|
flush();
|
2010-10-01 15:11:06 +00:00
|
|
|
}
|
|
|
|
|
|
2010-09-11 08:23:26 +00:00
|
|
|
/**
|
|
|
|
|
* Add a new update coming from an extension. This should be called by
|
|
|
|
|
* extensions while executing the LoadExtensionSchemaUpdates hook.
|
|
|
|
|
*
|
2012-01-06 15:36:17 +00:00
|
|
|
* @since 1.17
|
|
|
|
|
*
|
2016-10-18 01:12:08 +00:00
|
|
|
* @param array $update The update to run. Format is [ $callback, $params... ]
|
|
|
|
|
* $callback is the method to call; either a DatabaseUpdater method name or a callable.
|
|
|
|
|
* Must be serializable (ie. no anonymous functions allowed). The rest of the parameters
|
|
|
|
|
* (if any) will be passed to the callback. The first parameter passed to the callback
|
|
|
|
|
* is always this object.
|
2010-09-11 08:23:26 +00:00
|
|
|
*/
|
2012-10-05 14:11:18 +00:00
|
|
|
public function addExtensionUpdate( array $update ) {
|
2010-09-11 08:23:26 +00:00
|
|
|
$this->extensionUpdates[] = $update;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-03 23:56:49 +00:00
|
|
|
/**
|
|
|
|
|
* Convenience wrapper for addExtensionUpdate() when adding a new table (which
|
|
|
|
|
* is the most common usage of updaters in an extension)
|
2012-01-06 15:36:17 +00:00
|
|
|
*
|
|
|
|
|
* @since 1.18
|
|
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $tableName Name of table to create
|
|
|
|
|
* @param string $sqlPath Full path to the schema file
|
2011-01-03 23:56:49 +00:00
|
|
|
*/
|
|
|
|
|
public function addExtensionTable( $tableName, $sqlPath ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->extensionUpdates[] = [ 'addTable', $tableName, $sqlPath, true ];
|
2011-01-03 23:56:49 +00:00
|
|
|
}
|
|
|
|
|
|
2011-10-11 03:57:53 +00:00
|
|
|
/**
|
2012-01-06 15:36:17 +00:00
|
|
|
* @since 1.19
|
|
|
|
|
*
|
2014-04-19 11:55:27 +00:00
|
|
|
* @param string $tableName
|
|
|
|
|
* @param string $indexName
|
|
|
|
|
* @param string $sqlPath
|
2011-10-11 03:57:53 +00:00
|
|
|
*/
|
|
|
|
|
public function addExtensionIndex( $tableName, $indexName, $sqlPath ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->extensionUpdates[] = [ 'addIndex', $tableName, $indexName, $sqlPath, true ];
|
2011-10-11 03:57:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2012-01-06 15:36:17 +00:00
|
|
|
*
|
|
|
|
|
* @since 1.19
|
|
|
|
|
*
|
2014-04-19 11:55:27 +00:00
|
|
|
* @param string $tableName
|
|
|
|
|
* @param string $columnName
|
|
|
|
|
* @param string $sqlPath
|
2011-10-11 03:57:53 +00:00
|
|
|
*/
|
|
|
|
|
public function addExtensionField( $tableName, $columnName, $sqlPath ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->extensionUpdates[] = [ 'addField', $tableName, $columnName, $sqlPath, true ];
|
2011-10-11 03:57:53 +00:00
|
|
|
}
|
2011-11-14 21:14:31 +00:00
|
|
|
|
2012-03-14 20:16:32 +00:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @since 1.20
|
|
|
|
|
*
|
2014-04-19 11:55:27 +00:00
|
|
|
* @param string $tableName
|
|
|
|
|
* @param string $columnName
|
|
|
|
|
* @param string $sqlPath
|
2012-03-14 20:16:32 +00:00
|
|
|
*/
|
|
|
|
|
public function dropExtensionField( $tableName, $columnName, $sqlPath ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->extensionUpdates[] = [ 'dropField', $tableName, $columnName, $sqlPath, true ];
|
2012-03-14 20:16:32 +00:00
|
|
|
}
|
|
|
|
|
|
2012-12-18 01:03:44 +00:00
|
|
|
/**
|
|
|
|
|
* Drop an index from an extension table
|
|
|
|
|
*
|
|
|
|
|
* @since 1.21
|
|
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $tableName The table name
|
|
|
|
|
* @param string $indexName The index name
|
|
|
|
|
* @param string $sqlPath The path to the SQL change path
|
2012-12-18 01:03:44 +00:00
|
|
|
*/
|
|
|
|
|
public function dropExtensionIndex( $tableName, $indexName, $sqlPath ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->extensionUpdates[] = [ 'dropIndex', $tableName, $indexName, $sqlPath, true ];
|
2012-12-18 01:03:44 +00:00
|
|
|
}
|
|
|
|
|
|
2012-03-14 20:16:32 +00:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @since 1.20
|
|
|
|
|
*
|
2014-04-19 11:55:27 +00:00
|
|
|
* @param string $tableName
|
|
|
|
|
* @param string $sqlPath
|
2012-03-14 20:16:32 +00:00
|
|
|
*/
|
2012-03-14 21:53:30 +00:00
|
|
|
public function dropExtensionTable( $tableName, $sqlPath ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->extensionUpdates[] = [ 'dropTable', $tableName, $sqlPath, true ];
|
2012-03-14 20:16:32 +00:00
|
|
|
}
|
|
|
|
|
|
2012-12-18 01:03:44 +00:00
|
|
|
/**
|
|
|
|
|
* Rename an index on an extension table
|
|
|
|
|
*
|
|
|
|
|
* @since 1.21
|
|
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $tableName The table name
|
|
|
|
|
* @param string $oldIndexName The old index name
|
|
|
|
|
* @param string $newIndexName The new index name
|
2014-08-13 19:41:39 +00:00
|
|
|
* @param string $sqlPath The path to the SQL change path
|
2014-04-19 11:55:27 +00:00
|
|
|
* @param bool $skipBothIndexExistWarning Whether to warn if both the old
|
2013-10-23 12:16:03 +00:00
|
|
|
* and the new indexes exist. [facultative; by default, false]
|
2012-12-18 01:03:44 +00:00
|
|
|
*/
|
2013-10-23 12:16:03 +00:00
|
|
|
public function renameExtensionIndex( $tableName, $oldIndexName, $newIndexName,
|
|
|
|
|
$sqlPath, $skipBothIndexExistWarning = false
|
|
|
|
|
) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->extensionUpdates[] = [
|
2013-10-23 12:16:03 +00:00
|
|
|
'renameIndex',
|
|
|
|
|
$tableName,
|
|
|
|
|
$oldIndexName,
|
|
|
|
|
$newIndexName,
|
|
|
|
|
$skipBothIndexExistWarning,
|
|
|
|
|
$sqlPath,
|
|
|
|
|
true
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2012-12-18 01:03:44 +00:00
|
|
|
}
|
|
|
|
|
|
2013-01-06 03:03:36 +00:00
|
|
|
/**
|
|
|
|
|
* @since 1.21
|
|
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $tableName The table name
|
|
|
|
|
* @param string $fieldName The field to be modified
|
2017-11-14 02:31:23 +00:00
|
|
|
* @param string $sqlPath The path to the SQL patch
|
2013-01-06 03:03:36 +00:00
|
|
|
*/
|
2013-03-24 10:01:51 +00:00
|
|
|
public function modifyExtensionField( $tableName, $fieldName, $sqlPath ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->extensionUpdates[] = [ 'modifyField', $tableName, $fieldName, $sqlPath, true ];
|
2013-01-06 03:03:36 +00:00
|
|
|
}
|
|
|
|
|
|
2017-11-14 02:31:23 +00:00
|
|
|
/**
|
|
|
|
|
* @since 1.31
|
|
|
|
|
*
|
|
|
|
|
* @param string $tableName The table name
|
|
|
|
|
* @param string $sqlPath The path to the SQL patch
|
|
|
|
|
*/
|
|
|
|
|
public function modifyExtensionTable( $tableName, $sqlPath ) {
|
|
|
|
|
$this->extensionUpdates[] = [ 'modifyTable', $tableName, $sqlPath, true ];
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-14 21:41:37 +00:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @since 1.20
|
|
|
|
|
*
|
2014-04-19 11:55:27 +00:00
|
|
|
* @param string $tableName
|
2012-04-27 15:40:14 +00:00
|
|
|
* @return bool
|
2012-03-14 21:41:37 +00:00
|
|
|
*/
|
2012-03-17 08:22:58 +00:00
|
|
|
public function tableExists( $tableName ) {
|
2012-03-14 21:41:37 +00:00
|
|
|
return ( $this->db->tableExists( $tableName, __METHOD__ ) );
|
|
|
|
|
}
|
2012-03-14 20:16:32 +00:00
|
|
|
|
2011-11-12 09:55:28 +00:00
|
|
|
/**
|
2011-12-07 23:54:51 +00:00
|
|
|
* Add a maintenance script to be run after the database updates are complete.
|
2012-07-08 08:00:36 +00:00
|
|
|
*
|
2012-10-12 18:52:29 +00:00
|
|
|
* Script should subclass LoggedUpdateMaintenance
|
|
|
|
|
*
|
2011-12-07 23:54:51 +00:00
|
|
|
* @since 1.19
|
2012-07-08 08:00:36 +00:00
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $class Name of a Maintenance subclass
|
2011-11-12 09:55:28 +00:00
|
|
|
*/
|
|
|
|
|
public function addPostDatabaseUpdateMaintenance( $class ) {
|
|
|
|
|
$this->postDatabaseUpdateMaintenance[] = $class;
|
|
|
|
|
}
|
2011-10-11 03:57:53 +00:00
|
|
|
|
2010-09-11 08:23:26 +00:00
|
|
|
/**
|
|
|
|
|
* Get the list of extension-defined updates
|
|
|
|
|
*
|
2014-04-19 11:55:27 +00:00
|
|
|
* @return array
|
2010-09-11 08:23:26 +00:00
|
|
|
*/
|
|
|
|
|
protected function getExtensionUpdates() {
|
|
|
|
|
return $this->extensionUpdates;
|
|
|
|
|
}
|
2010-08-15 18:55:08 +00:00
|
|
|
|
2011-10-11 03:57:53 +00:00
|
|
|
/**
|
2011-12-07 23:54:51 +00:00
|
|
|
* @since 1.17
|
2012-07-08 08:00:36 +00:00
|
|
|
*
|
2016-03-14 15:54:50 +00:00
|
|
|
* @return string[]
|
2011-10-11 03:57:53 +00:00
|
|
|
*/
|
2010-08-16 14:23:28 +00:00
|
|
|
public function getPostDatabaseUpdateMaintenance() {
|
|
|
|
|
return $this->postDatabaseUpdateMaintenance;
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-22 03:53:24 +00:00
|
|
|
/**
|
|
|
|
|
* @since 1.21
|
|
|
|
|
*
|
|
|
|
|
* Writes the schema updates desired to a file for the DB Admin to run.
|
2014-04-19 11:55:27 +00:00
|
|
|
* @param array $schemaUpdate
|
2012-11-22 03:53:24 +00:00
|
|
|
*/
|
2017-03-06 12:36:57 +00:00
|
|
|
private function writeSchemaUpdateFile( array $schemaUpdate = [] ) {
|
2012-11-22 03:53:24 +00:00
|
|
|
$updates = $this->updatesSkipped;
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->updatesSkipped = [];
|
2012-11-22 03:53:24 +00:00
|
|
|
|
2013-04-17 14:52:47 +00:00
|
|
|
foreach ( $updates as $funcList ) {
|
2012-11-22 03:53:24 +00:00
|
|
|
$func = $funcList[0];
|
|
|
|
|
$arg = $funcList[1];
|
2012-12-03 20:24:37 +00:00
|
|
|
$origParams = $funcList[2];
|
2012-12-09 03:27:02 +00:00
|
|
|
call_user_func_array( $func, $arg );
|
2012-11-22 03:53:24 +00:00
|
|
|
flush();
|
2012-12-03 20:24:37 +00:00
|
|
|
$this->updatesSkipped[] = $origParams;
|
2012-11-22 03:53:24 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 20:39:00 +00:00
|
|
|
/**
|
|
|
|
|
* Get appropriate schema variables in the current database connection.
|
|
|
|
|
*
|
|
|
|
|
* This should be called after any request data has been imported, but before
|
|
|
|
|
* any write operations to the database. The result should be passed to the DB
|
|
|
|
|
* setSchemaVars() method.
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
* @since 1.28
|
|
|
|
|
*/
|
|
|
|
|
public function getSchemaVars() {
|
|
|
|
|
return []; // DB-type specific
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-07 14:33:11 +00:00
|
|
|
/**
|
|
|
|
|
* Do all the updates
|
2010-09-11 08:23:26 +00:00
|
|
|
*
|
2013-10-08 16:20:08 +00:00
|
|
|
* @param array $what What updates to perform
|
2010-09-07 14:33:11 +00:00
|
|
|
*/
|
2017-03-06 12:36:57 +00:00
|
|
|
public function doUpdates( array $what = [ 'core', 'extensions', 'stats' ] ) {
|
2016-09-21 20:39:00 +00:00
|
|
|
$this->db->setSchemaVars( $this->getSchemaVars() );
|
|
|
|
|
|
2011-03-30 17:32:20 +00:00
|
|
|
$what = array_flip( $what );
|
2012-11-22 03:53:24 +00:00
|
|
|
$this->skipSchema = isset( $what['noschema'] ) || $this->fileHandle !== null;
|
2011-03-30 17:32:20 +00:00
|
|
|
if ( isset( $what['core'] ) ) {
|
|
|
|
|
$this->runUpdates( $this->getCoreUpdateList(), false );
|
|
|
|
|
}
|
|
|
|
|
if ( isset( $what['extensions'] ) ) {
|
|
|
|
|
$this->runUpdates( $this->getOldGlobalUpdates(), false );
|
|
|
|
|
$this->runUpdates( $this->getExtensionUpdates(), true );
|
|
|
|
|
}
|
2010-09-11 08:23:26 +00:00
|
|
|
|
2012-01-12 10:59:13 +00:00
|
|
|
if ( isset( $what['stats'] ) ) {
|
|
|
|
|
$this->checkStats();
|
|
|
|
|
}
|
2012-11-22 03:53:24 +00:00
|
|
|
|
2013-04-17 14:52:47 +00:00
|
|
|
if ( $this->fileHandle ) {
|
2012-11-22 03:53:24 +00:00
|
|
|
$this->skipSchema = false;
|
2013-03-17 15:13:22 +00:00
|
|
|
$this->writeSchemaUpdateFile();
|
2012-11-22 03:53:24 +00:00
|
|
|
}
|
2010-09-11 08:23:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Helper function for doUpdates()
|
|
|
|
|
*
|
2014-04-19 11:55:27 +00:00
|
|
|
* @param array $updates Array of updates to run
|
|
|
|
|
* @param bool $passSelf Whether to pass this object we calling external functions
|
2010-09-11 08:23:26 +00:00
|
|
|
*/
|
|
|
|
|
private function runUpdates( array $updates, $passSelf ) {
|
2016-09-23 03:42:38 +00:00
|
|
|
$lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$updatesDone = [];
|
|
|
|
|
$updatesSkipped = [];
|
2010-09-11 08:23:26 +00:00
|
|
|
foreach ( $updates as $params ) {
|
2012-12-03 20:24:37 +00:00
|
|
|
$origParams = $params;
|
2010-08-15 18:13:23 +00:00
|
|
|
$func = array_shift( $params );
|
2013-04-17 14:52:47 +00:00
|
|
|
if ( !is_array( $func ) && method_exists( $this, $func ) ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$func = [ $this, $func ];
|
2010-09-11 08:23:26 +00:00
|
|
|
} elseif ( $passSelf ) {
|
|
|
|
|
array_unshift( $params, $this );
|
2010-08-17 13:36:59 +00:00
|
|
|
}
|
2012-11-22 03:53:24 +00:00
|
|
|
$ret = call_user_func_array( $func, $params );
|
2010-08-15 18:13:23 +00:00
|
|
|
flush();
|
2013-04-17 14:52:47 +00:00
|
|
|
if ( $ret !== false ) {
|
2012-12-03 20:24:37 +00:00
|
|
|
$updatesDone[] = $origParams;
|
2016-09-23 03:42:38 +00:00
|
|
|
$lbFactory->waitForReplication();
|
2012-11-22 03:53:24 +00:00
|
|
|
} else {
|
2016-02-17 09:09:32 +00:00
|
|
|
$updatesSkipped[] = [ $func, $params, $origParams ];
|
2012-11-22 03:53:24 +00:00
|
|
|
}
|
2010-07-08 14:57:19 +00:00
|
|
|
}
|
2012-11-22 03:53:24 +00:00
|
|
|
$this->updatesSkipped = array_merge( $this->updatesSkipped, $updatesSkipped );
|
|
|
|
|
$this->updates = array_merge( $this->updates, $updatesDone );
|
2010-07-08 14:57:19 +00:00
|
|
|
}
|
|
|
|
|
|
2010-09-12 16:24:03 +00:00
|
|
|
/**
|
|
|
|
|
* Helper function: check if the given key is present in the updatelog table.
|
|
|
|
|
* Obviously, only use this for updates that occur after the updatelog table was
|
|
|
|
|
* created!
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $key Name of the key to check for
|
2011-10-11 03:57:53 +00:00
|
|
|
* @return bool
|
2010-09-12 16:24:03 +00:00
|
|
|
*/
|
|
|
|
|
public function updateRowExists( $key ) {
|
|
|
|
|
$row = $this->db->selectRow(
|
|
|
|
|
'updatelog',
|
2017-02-20 22:44:19 +00:00
|
|
|
# T67813
|
2014-05-27 20:36:51 +00:00
|
|
|
'1 AS X',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'ul_key' => $key ],
|
2010-09-12 16:24:03 +00:00
|
|
|
__METHOD__
|
|
|
|
|
);
|
2013-10-08 11:43:42 +00:00
|
|
|
|
2010-09-12 16:24:03 +00:00
|
|
|
return (bool)$row;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-03 21:08:44 +00:00
|
|
|
/**
|
|
|
|
|
* Helper function: Add a key to the updatelog table
|
|
|
|
|
* Obviously, only use this for updates that occur after the updatelog table was
|
|
|
|
|
* created!
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $key Name of key to insert
|
2013-10-08 16:20:08 +00:00
|
|
|
* @param string $val [optional] Value to insert along with the key
|
2011-05-03 21:08:44 +00:00
|
|
|
*/
|
|
|
|
|
public function insertUpdateRow( $key, $val = null ) {
|
2011-06-22 14:10:55 +00:00
|
|
|
$this->db->clearFlag( DBO_DDLMODE );
|
2016-02-17 09:09:32 +00:00
|
|
|
$values = [ 'ul_key' => $key ];
|
2013-04-17 14:52:47 +00:00
|
|
|
if ( $val && $this->canUseNewUpdatelog() ) {
|
2011-05-03 21:08:44 +00:00
|
|
|
$values['ul_value'] = $val;
|
|
|
|
|
}
|
|
|
|
|
$this->db->insert( 'updatelog', $values, __METHOD__, 'IGNORE' );
|
2011-06-22 14:10:55 +00:00
|
|
|
$this->db->setFlag( DBO_DDLMODE );
|
2011-05-03 21:08:44 +00:00
|
|
|
}
|
|
|
|
|
|
2010-07-11 12:31:44 +00:00
|
|
|
/**
|
|
|
|
|
* Updatelog was changed in 1.17 to have a ul_value column so we can record
|
|
|
|
|
* more information about what kind of updates we've done (that's what this
|
|
|
|
|
* class does). Pre-1.17 wikis won't have this column, and really old wikis
|
|
|
|
|
* might not even have updatelog at all
|
|
|
|
|
*
|
2014-04-19 11:55:27 +00:00
|
|
|
* @return bool
|
2010-07-11 12:31:44 +00:00
|
|
|
*/
|
|
|
|
|
protected function canUseNewUpdatelog() {
|
2011-11-10 20:39:23 +00:00
|
|
|
return $this->db->tableExists( 'updatelog', __METHOD__ ) &&
|
2011-11-10 20:44:37 +00:00
|
|
|
$this->db->fieldExists( 'updatelog', 'ul_value', __METHOD__ );
|
2010-07-11 12:31:44 +00:00
|
|
|
}
|
2010-07-17 12:55:52 +00:00
|
|
|
|
2012-12-27 17:37:40 +00:00
|
|
|
/**
|
|
|
|
|
* Returns whether updates should be executed on the database table $name.
|
|
|
|
|
* Updates will be prevented if the table is a shared table and it is not
|
|
|
|
|
* specified to run updates on shared tables.
|
|
|
|
|
*
|
2013-10-08 16:20:08 +00:00
|
|
|
* @param string $name Table name
|
2012-12-27 17:37:40 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
protected function doTable( $name ) {
|
|
|
|
|
global $wgSharedDB, $wgSharedTables;
|
|
|
|
|
|
|
|
|
|
// Don't bother to check $wgSharedTables if there isn't a shared database
|
|
|
|
|
// or the user actually also wants to do updates on the shared database.
|
|
|
|
|
if ( $wgSharedDB === null || $this->shared ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-16 20:45:26 +00:00
|
|
|
if ( in_array( $name, $wgSharedTables ) ) {
|
|
|
|
|
$this->output( "...skipping update to shared table $name.\n" );
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2012-12-27 17:37:40 +00:00
|
|
|
}
|
|
|
|
|
|
2010-07-17 12:55:52 +00:00
|
|
|
/**
|
2010-09-12 16:48:03 +00:00
|
|
|
* Before 1.17, we used to handle updates via stuff like
|
2010-07-17 12:55:52 +00:00
|
|
|
* $wgExtNewTables/Fields/Indexes. This is nasty :) We refactored a lot
|
2010-10-27 14:38:31 +00:00
|
|
|
* of this in 1.17 but we want to remain back-compatible for a while. So
|
2010-09-03 21:14:52 +00:00
|
|
|
* load up these old global-based things into our update list.
|
2011-10-11 03:57:53 +00:00
|
|
|
*
|
|
|
|
|
* @return array
|
2010-07-17 12:55:52 +00:00
|
|
|
*/
|
2010-08-22 08:07:26 +00:00
|
|
|
protected function getOldGlobalUpdates() {
|
2010-09-12 16:48:03 +00:00
|
|
|
global $wgExtNewFields, $wgExtNewTables, $wgExtModifiedFields,
|
2012-12-27 17:37:40 +00:00
|
|
|
$wgExtNewIndexes;
|
2010-08-15 18:13:23 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$updates = [];
|
2010-07-17 12:55:52 +00:00
|
|
|
|
|
|
|
|
foreach ( $wgExtNewTables as $tableRecord ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$updates[] = [
|
2010-08-17 13:36:59 +00:00
|
|
|
'addTable', $tableRecord[0], $tableRecord[1], true
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2010-07-17 12:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ( $wgExtNewFields as $fieldRecord ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$updates[] = [
|
2012-12-27 17:37:40 +00:00
|
|
|
'addField', $fieldRecord[0], $fieldRecord[1],
|
2013-10-08 11:43:42 +00:00
|
|
|
$fieldRecord[2], true
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2010-07-17 12:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ( $wgExtNewIndexes as $fieldRecord ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$updates[] = [
|
2010-08-17 17:48:22 +00:00
|
|
|
'addIndex', $fieldRecord[0], $fieldRecord[1],
|
2013-10-08 11:43:42 +00:00
|
|
|
$fieldRecord[2], true
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2010-07-17 12:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ( $wgExtModifiedFields as $fieldRecord ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$updates[] = [
|
2010-09-11 08:35:39 +00:00
|
|
|
'modifyField', $fieldRecord[0], $fieldRecord[1],
|
2013-10-08 11:43:42 +00:00
|
|
|
$fieldRecord[2], true
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2010-07-17 12:55:52 +00:00
|
|
|
}
|
2010-08-15 18:13:23 +00:00
|
|
|
|
|
|
|
|
return $updates;
|
2010-07-17 12:55:52 +00:00
|
|
|
}
|
2010-07-20 22:28:50 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get an array of updates to perform on the database. Should return a
|
2010-09-11 21:55:21 +00:00
|
|
|
* multi-dimensional array. The main key is the MediaWiki version (1.12,
|
2010-07-20 22:28:50 +00:00
|
|
|
* 1.13...) with the values being arrays of updates, identical to how
|
|
|
|
|
* updaters.inc did it (for now)
|
|
|
|
|
*
|
2017-12-28 15:31:56 +00:00
|
|
|
* @return array[]
|
2010-07-20 22:28:50 +00:00
|
|
|
*/
|
2013-01-26 19:00:09 +00:00
|
|
|
abstract protected function getCoreUpdateList();
|
2010-08-17 13:36:59 +00:00
|
|
|
|
2012-11-22 03:53:24 +00:00
|
|
|
/**
|
|
|
|
|
* Append an SQL fragment to the open file handle.
|
|
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $filename File name to open
|
2012-11-22 03:53:24 +00:00
|
|
|
*/
|
|
|
|
|
public function copyFile( $filename ) {
|
2016-10-07 00:12:31 +00:00
|
|
|
$this->db->sourceFile(
|
|
|
|
|
$filename,
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
__METHOD__,
|
2016-02-17 09:09:32 +00:00
|
|
|
[ $this, 'appendLine' ]
|
2012-11-22 03:53:24 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Append a line to the open filehandle. The line is assumed to
|
|
|
|
|
* be a complete SQL statement.
|
|
|
|
|
*
|
2014-12-16 00:41:45 +00:00
|
|
|
* This is used as a callback for sourceLine().
|
2012-11-22 03:53:24 +00:00
|
|
|
*
|
2013-10-08 16:20:08 +00:00
|
|
|
* @param string $line Text to append to the file
|
|
|
|
|
* @return bool False to skip actually executing the file
|
2012-11-22 03:53:24 +00:00
|
|
|
* @throws MWException
|
|
|
|
|
*/
|
|
|
|
|
public function appendLine( $line ) {
|
|
|
|
|
$line = rtrim( $line ) . ";\n";
|
2013-04-17 14:52:47 +00:00
|
|
|
if ( fwrite( $this->fileHandle, $line ) === false ) {
|
2012-11-22 03:53:24 +00:00
|
|
|
throw new MWException( "trouble writing file" );
|
|
|
|
|
}
|
2013-10-08 11:43:42 +00:00
|
|
|
|
2012-11-22 03:53:24 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-17 17:48:22 +00:00
|
|
|
/**
|
|
|
|
|
* Applies a SQL patch
|
2012-12-18 01:03:44 +00:00
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $path Path to the patch file
|
2014-04-19 11:55:27 +00:00
|
|
|
* @param bool $isFullPath Whether to treat $path as a relative or not
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $msg Description of the patch
|
2013-10-08 16:20:08 +00:00
|
|
|
* @return bool False if patch is skipped.
|
2010-08-17 17:48:22 +00:00
|
|
|
*/
|
2012-07-08 08:00:36 +00:00
|
|
|
protected function applyPatch( $path, $isFullPath = false, $msg = null ) {
|
|
|
|
|
if ( $msg === null ) {
|
|
|
|
|
$msg = "Applying $path patch";
|
2010-08-17 17:48:22 +00:00
|
|
|
}
|
2012-11-22 03:53:24 +00:00
|
|
|
if ( $this->skipSchema ) {
|
|
|
|
|
$this->output( "...skipping schema change ($msg).\n" );
|
2013-10-08 11:43:42 +00:00
|
|
|
|
2012-11-22 03:53:24 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->output( "$msg ..." );
|
2012-07-08 08:00:36 +00:00
|
|
|
|
|
|
|
|
if ( !$isFullPath ) {
|
2016-09-15 09:25:16 +00:00
|
|
|
$path = $this->patchPath( $this->db, $path );
|
2012-07-08 08:00:36 +00:00
|
|
|
}
|
2013-04-17 14:52:47 +00:00
|
|
|
if ( $this->fileHandle !== null ) {
|
2012-11-22 03:53:24 +00:00
|
|
|
$this->copyFile( $path );
|
|
|
|
|
} else {
|
|
|
|
|
$this->db->sourceFile( $path );
|
|
|
|
|
}
|
2013-02-03 19:28:43 +00:00
|
|
|
$this->output( "done.\n" );
|
2013-10-08 11:43:42 +00:00
|
|
|
|
2012-11-22 03:53:24 +00:00
|
|
|
return true;
|
2010-08-17 17:48:22 +00:00
|
|
|
}
|
|
|
|
|
|
2016-09-15 09:25:16 +00:00
|
|
|
/**
|
|
|
|
|
* Get the full path of a patch file. Originally based on archive()
|
|
|
|
|
* from updaters.inc. Keep in mind this always returns a patch, as
|
|
|
|
|
* it fails back to MySQL if no DB-specific patch can be found
|
|
|
|
|
*
|
|
|
|
|
* @param IDatabase $db
|
|
|
|
|
* @param string $patch The name of the patch, like patch-something.sql
|
|
|
|
|
* @return string Full path to patch file
|
|
|
|
|
*/
|
|
|
|
|
public function patchPath( IDatabase $db, $patch ) {
|
|
|
|
|
global $IP;
|
|
|
|
|
|
|
|
|
|
$dbType = $db->getType();
|
|
|
|
|
if ( file_exists( "$IP/maintenance/$dbType/archives/$patch" ) ) {
|
|
|
|
|
return "$IP/maintenance/$dbType/archives/$patch";
|
|
|
|
|
} else {
|
|
|
|
|
return "$IP/maintenance/archives/$patch";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-17 13:36:59 +00:00
|
|
|
/**
|
|
|
|
|
* Add a new table to the database
|
2012-12-18 01:03:44 +00:00
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $name Name of the new table
|
|
|
|
|
* @param string $patch Path to the patch file
|
2013-10-08 16:20:08 +00:00
|
|
|
* @param bool $fullpath Whether to treat $patch path as a relative or not
|
|
|
|
|
* @return bool False if this was skipped because schema changes are skipped
|
2010-08-17 13:36:59 +00:00
|
|
|
*/
|
|
|
|
|
protected function addTable( $name, $patch, $fullpath = false ) {
|
2012-12-27 17:37:40 +00:00
|
|
|
if ( !$this->doTable( $name ) ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-10 20:39:23 +00:00
|
|
|
if ( $this->db->tableExists( $name, __METHOD__ ) ) {
|
2011-11-22 13:28:39 +00:00
|
|
|
$this->output( "...$name table already exists.\n" );
|
2010-08-17 13:36:59 +00:00
|
|
|
} else {
|
2012-11-22 03:53:24 +00:00
|
|
|
return $this->applyPatch( $patch, $fullpath, "Creating $name table" );
|
2010-08-17 17:48:22 +00:00
|
|
|
}
|
2013-10-08 11:43:42 +00:00
|
|
|
|
2012-11-22 03:53:24 +00:00
|
|
|
return true;
|
2010-08-17 17:48:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a new field to an existing table
|
2012-12-18 01:03:44 +00:00
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $table Name of the table to modify
|
|
|
|
|
* @param string $field Name of the new field
|
|
|
|
|
* @param string $patch Path to the patch file
|
2013-10-08 16:20:08 +00:00
|
|
|
* @param bool $fullpath Whether to treat $patch path as a relative or not
|
|
|
|
|
* @return bool False if this was skipped because schema changes are skipped
|
2010-08-17 17:48:22 +00:00
|
|
|
*/
|
|
|
|
|
protected function addField( $table, $field, $patch, $fullpath = false ) {
|
2012-12-27 17:37:40 +00:00
|
|
|
if ( !$this->doTable( $table ) ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-10 20:39:23 +00:00
|
|
|
if ( !$this->db->tableExists( $table, __METHOD__ ) ) {
|
2011-11-19 17:39:56 +00:00
|
|
|
$this->output( "...$table table does not exist, skipping new field patch.\n" );
|
2011-11-10 20:44:37 +00:00
|
|
|
} elseif ( $this->db->fieldExists( $table, $field, __METHOD__ ) ) {
|
2011-11-22 13:28:39 +00:00
|
|
|
$this->output( "...have $field field in $table table.\n" );
|
2010-08-17 17:48:22 +00:00
|
|
|
} else {
|
2012-11-22 03:53:24 +00:00
|
|
|
return $this->applyPatch( $patch, $fullpath, "Adding $field field to table $table" );
|
2010-08-17 17:48:22 +00:00
|
|
|
}
|
2013-10-08 11:43:42 +00:00
|
|
|
|
2012-11-22 03:53:24 +00:00
|
|
|
return true;
|
2010-08-17 17:48:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a new index to an existing table
|
2012-12-18 01:03:44 +00:00
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $table Name of the table to modify
|
|
|
|
|
* @param string $index Name of the new index
|
|
|
|
|
* @param string $patch Path to the patch file
|
2013-10-08 16:20:08 +00:00
|
|
|
* @param bool $fullpath Whether to treat $patch path as a relative or not
|
|
|
|
|
* @return bool False if this was skipped because schema changes are skipped
|
2010-08-17 17:48:22 +00:00
|
|
|
*/
|
2011-10-11 18:17:44 +00:00
|
|
|
protected function addIndex( $table, $index, $patch, $fullpath = false ) {
|
2012-12-27 17:37:40 +00:00
|
|
|
if ( !$this->doTable( $table ) ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-22 03:53:24 +00:00
|
|
|
if ( !$this->db->tableExists( $table, __METHOD__ ) ) {
|
|
|
|
|
$this->output( "...skipping: '$table' table doesn't exist yet.\n" );
|
2013-04-17 14:52:47 +00:00
|
|
|
} elseif ( $this->db->indexExists( $table, $index, __METHOD__ ) ) {
|
2012-01-24 09:48:26 +00:00
|
|
|
$this->output( "...index $index already set on $table table.\n" );
|
2010-08-17 17:48:22 +00:00
|
|
|
} else {
|
2012-11-22 03:53:24 +00:00
|
|
|
return $this->applyPatch( $patch, $fullpath, "Adding index $index to table $table" );
|
2010-08-17 13:36:59 +00:00
|
|
|
}
|
2013-10-08 11:43:42 +00:00
|
|
|
|
2012-11-22 03:53:24 +00:00
|
|
|
return true;
|
2010-08-17 13:36:59 +00:00
|
|
|
}
|
2010-08-22 11:57:31 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Drop a field from an existing table
|
|
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $table Name of the table to modify
|
|
|
|
|
* @param string $field Name of the old field
|
|
|
|
|
* @param string $patch Path to the patch file
|
2013-10-08 16:20:08 +00:00
|
|
|
* @param bool $fullpath Whether to treat $patch path as a relative or not
|
|
|
|
|
* @return bool False if this was skipped because schema changes are skipped
|
2010-08-22 11:57:31 +00:00
|
|
|
*/
|
2010-12-08 03:47:04 +00:00
|
|
|
protected function dropField( $table, $field, $patch, $fullpath = false ) {
|
2012-12-27 17:37:40 +00:00
|
|
|
if ( !$this->doTable( $table ) ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-10 20:44:37 +00:00
|
|
|
if ( $this->db->fieldExists( $table, $field, __METHOD__ ) ) {
|
2012-11-22 03:53:24 +00:00
|
|
|
return $this->applyPatch( $patch, $fullpath, "Table $table contains $field field. Dropping" );
|
2010-08-22 11:59:32 +00:00
|
|
|
} else {
|
2011-11-22 13:28:39 +00:00
|
|
|
$this->output( "...$table table does not contain $field field.\n" );
|
2010-08-22 11:59:32 +00:00
|
|
|
}
|
2013-10-08 11:43:42 +00:00
|
|
|
|
2012-11-22 03:53:24 +00:00
|
|
|
return true;
|
2010-08-22 11:57:31 +00:00
|
|
|
}
|
2010-09-07 14:33:11 +00:00
|
|
|
|
2010-09-11 15:20:39 +00:00
|
|
|
/**
|
|
|
|
|
* Drop an index from an existing table
|
|
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $table Name of the table to modify
|
|
|
|
|
* @param string $index Name of the index
|
|
|
|
|
* @param string $patch Path to the patch file
|
2013-10-08 16:20:08 +00:00
|
|
|
* @param bool $fullpath Whether to treat $patch path as a relative or not
|
|
|
|
|
* @return bool False if this was skipped because schema changes are skipped
|
2010-09-11 15:20:39 +00:00
|
|
|
*/
|
2011-10-11 18:17:44 +00:00
|
|
|
protected function dropIndex( $table, $index, $patch, $fullpath = false ) {
|
2012-12-27 17:37:40 +00:00
|
|
|
if ( !$this->doTable( $table ) ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-10 20:44:37 +00:00
|
|
|
if ( $this->db->indexExists( $table, $index, __METHOD__ ) ) {
|
2012-11-22 03:53:24 +00:00
|
|
|
return $this->applyPatch( $patch, $fullpath, "Dropping $index index from table $table" );
|
2010-09-11 15:20:39 +00:00
|
|
|
} else {
|
2011-11-22 13:28:39 +00:00
|
|
|
$this->output( "...$index key doesn't exist.\n" );
|
2010-09-11 15:20:39 +00:00
|
|
|
}
|
2013-10-08 11:43:42 +00:00
|
|
|
|
2012-11-22 03:53:24 +00:00
|
|
|
return true;
|
2010-09-11 15:20:39 +00:00
|
|
|
}
|
|
|
|
|
|
2012-12-18 01:03:44 +00:00
|
|
|
/**
|
|
|
|
|
* Rename an index from an existing table
|
|
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $table Name of the table to modify
|
|
|
|
|
* @param string $oldIndex Old name of the index
|
|
|
|
|
* @param string $newIndex New name of the index
|
2014-04-19 11:55:27 +00:00
|
|
|
* @param bool $skipBothIndexExistWarning Whether to warn if both the
|
2013-10-23 12:16:03 +00:00
|
|
|
* old and the new indexes exist.
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $patch Path to the patch file
|
2013-10-08 16:20:08 +00:00
|
|
|
* @param bool $fullpath Whether to treat $patch path as a relative or not
|
|
|
|
|
* @return bool False if this was skipped because schema changes are skipped
|
2012-12-18 01:03:44 +00:00
|
|
|
*/
|
2013-10-23 12:16:03 +00:00
|
|
|
protected function renameIndex( $table, $oldIndex, $newIndex,
|
|
|
|
|
$skipBothIndexExistWarning, $patch, $fullpath = false
|
|
|
|
|
) {
|
2013-01-05 19:31:35 +00:00
|
|
|
if ( !$this->doTable( $table ) ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-18 01:03:44 +00:00
|
|
|
// First requirement: the table must exist
|
|
|
|
|
if ( !$this->db->tableExists( $table, __METHOD__ ) ) {
|
|
|
|
|
$this->output( "...skipping: '$table' table doesn't exist yet.\n" );
|
2013-10-08 11:43:42 +00:00
|
|
|
|
2013-01-05 19:31:35 +00:00
|
|
|
return true;
|
2012-12-18 01:03:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Second requirement: the new index must be missing
|
|
|
|
|
if ( $this->db->indexExists( $table, $newIndex, __METHOD__ ) ) {
|
|
|
|
|
$this->output( "...index $newIndex already set on $table table.\n" );
|
2013-10-23 12:16:03 +00:00
|
|
|
if ( !$skipBothIndexExistWarning &&
|
|
|
|
|
$this->db->indexExists( $table, $oldIndex, __METHOD__ )
|
|
|
|
|
) {
|
|
|
|
|
$this->output( "...WARNING: $oldIndex still exists, despite it has " .
|
|
|
|
|
"been renamed into $newIndex (which also exists).\n" .
|
2013-01-05 19:31:35 +00:00
|
|
|
" $oldIndex should be manually removed if not needed anymore.\n" );
|
2012-12-18 01:03:44 +00:00
|
|
|
}
|
2013-10-08 11:43:42 +00:00
|
|
|
|
2012-12-18 01:03:44 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Third requirement: the old index must exist
|
|
|
|
|
if ( !$this->db->indexExists( $table, $oldIndex, __METHOD__ ) ) {
|
|
|
|
|
$this->output( "...skipping: index $oldIndex doesn't exist.\n" );
|
2013-10-08 11:43:42 +00:00
|
|
|
|
2013-01-05 19:31:35 +00:00
|
|
|
return true;
|
2012-12-18 01:03:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Requirements have been satisfied, patch can be applied
|
2013-10-23 12:16:03 +00:00
|
|
|
return $this->applyPatch(
|
|
|
|
|
$patch,
|
|
|
|
|
$fullpath,
|
|
|
|
|
"Renaming index $oldIndex into $newIndex to table $table"
|
|
|
|
|
);
|
2012-12-18 01:03:44 +00:00
|
|
|
}
|
|
|
|
|
|
2011-10-27 23:07:04 +00:00
|
|
|
/**
|
2012-08-23 20:43:20 +00:00
|
|
|
* If the specified table exists, drop it, or execute the
|
|
|
|
|
* patch if one is provided.
|
|
|
|
|
*
|
|
|
|
|
* Public @since 1.20
|
|
|
|
|
*
|
2013-10-08 16:20:08 +00:00
|
|
|
* @param string $table Table to drop.
|
|
|
|
|
* @param string|bool $patch String of patch file that will drop the table. Default: false.
|
|
|
|
|
* @param bool $fullpath Whether $patch is a full path. Default: false.
|
|
|
|
|
* @return bool False if this was skipped because schema changes are skipped
|
2011-10-27 23:07:04 +00:00
|
|
|
*/
|
2012-08-23 20:43:20 +00:00
|
|
|
public function dropTable( $table, $patch = false, $fullpath = false ) {
|
2012-12-27 17:37:40 +00:00
|
|
|
if ( !$this->doTable( $table ) ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-10 20:39:23 +00:00
|
|
|
if ( $this->db->tableExists( $table, __METHOD__ ) ) {
|
2012-08-23 20:43:20 +00:00
|
|
|
$msg = "Dropping table $table";
|
|
|
|
|
|
|
|
|
|
if ( $patch === false ) {
|
|
|
|
|
$this->output( "$msg ..." );
|
|
|
|
|
$this->db->dropTable( $table, __METHOD__ );
|
|
|
|
|
$this->output( "done.\n" );
|
2013-10-08 11:43:42 +00:00
|
|
|
} else {
|
2012-11-22 03:53:24 +00:00
|
|
|
return $this->applyPatch( $patch, $fullpath, $msg );
|
2012-08-23 20:43:20 +00:00
|
|
|
}
|
2011-10-27 23:07:04 +00:00
|
|
|
} else {
|
2011-11-22 13:28:39 +00:00
|
|
|
$this->output( "...$table doesn't exist.\n" );
|
2011-10-27 23:07:04 +00:00
|
|
|
}
|
2013-10-08 11:43:42 +00:00
|
|
|
|
2012-11-22 03:53:24 +00:00
|
|
|
return true;
|
2011-10-27 23:07:04 +00:00
|
|
|
}
|
|
|
|
|
|
2010-09-11 08:35:39 +00:00
|
|
|
/**
|
|
|
|
|
* Modify an existing field
|
|
|
|
|
*
|
2013-10-08 16:20:08 +00:00
|
|
|
* @param string $table Name of the table to which the field belongs
|
|
|
|
|
* @param string $field Name of the field to modify
|
|
|
|
|
* @param string $patch Path to the patch file
|
|
|
|
|
* @param bool $fullpath Whether to treat $patch path as a relative or not
|
|
|
|
|
* @return bool False if this was skipped because schema changes are skipped
|
2010-09-11 08:35:39 +00:00
|
|
|
*/
|
|
|
|
|
public function modifyField( $table, $field, $patch, $fullpath = false ) {
|
2012-12-27 17:37:40 +00:00
|
|
|
if ( !$this->doTable( $table ) ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-03 21:08:44 +00:00
|
|
|
$updateKey = "$table-$field-$patch";
|
2011-11-10 20:39:23 +00:00
|
|
|
if ( !$this->db->tableExists( $table, __METHOD__ ) ) {
|
2011-11-19 17:39:56 +00:00
|
|
|
$this->output( "...$table table does not exist, skipping modify field patch.\n" );
|
2011-11-10 20:44:37 +00:00
|
|
|
} elseif ( !$this->db->fieldExists( $table, $field, __METHOD__ ) ) {
|
2013-10-23 12:16:03 +00:00
|
|
|
$this->output( "...$field field does not exist in $table table, " .
|
|
|
|
|
"skipping modify field patch.\n" );
|
2013-04-17 14:52:47 +00:00
|
|
|
} elseif ( $this->updateRowExists( $updateKey ) ) {
|
2011-11-19 17:39:56 +00:00
|
|
|
$this->output( "...$field in table $table already modified by patch $patch.\n" );
|
2010-09-11 08:35:39 +00:00
|
|
|
} else {
|
2017-05-06 23:59:58 +00:00
|
|
|
$apply = $this->applyPatch( $patch, $fullpath, "Modifying $field field of table $table" );
|
|
|
|
|
if ( $apply ) {
|
|
|
|
|
$this->insertUpdateRow( $updateKey );
|
|
|
|
|
}
|
|
|
|
|
return $apply;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2013-10-08 11:43:42 +00:00
|
|
|
|
2017-05-06 23:59:58 +00:00
|
|
|
/**
|
|
|
|
|
* Modify an existing table, similar to modifyField. Intended for changes that
|
|
|
|
|
* touch more than one column on a table.
|
|
|
|
|
*
|
|
|
|
|
* @param string $table Name of the table to modify
|
|
|
|
|
* @param string $patch Name of the patch file to apply
|
2017-08-04 16:44:54 +00:00
|
|
|
* @param string|bool $fullpath Whether to treat $patch path as relative or not, defaults to false
|
2017-05-06 23:59:58 +00:00
|
|
|
* @return bool False if this was skipped because of schema changes being skipped
|
|
|
|
|
*/
|
2017-08-04 16:44:54 +00:00
|
|
|
public function modifyTable( $table, $patch, $fullpath = false ) {
|
2017-05-06 23:59:58 +00:00
|
|
|
if ( !$this->doTable( $table ) ) {
|
|
|
|
|
return true;
|
2010-09-11 08:35:39 +00:00
|
|
|
}
|
2013-10-08 11:43:42 +00:00
|
|
|
|
2017-05-06 23:59:58 +00:00
|
|
|
$updateKey = "$table-$patch";
|
|
|
|
|
if ( !$this->db->tableExists( $table, __METHOD__ ) ) {
|
|
|
|
|
$this->output( "...$table table does not exist, skipping modify table patch.\n" );
|
|
|
|
|
} elseif ( $this->updateRowExists( $updateKey ) ) {
|
|
|
|
|
$this->output( "...table $table already modified by patch $patch.\n" );
|
|
|
|
|
} else {
|
|
|
|
|
$apply = $this->applyPatch( $patch, $fullpath, "Modifying table $table" );
|
|
|
|
|
if ( $apply ) {
|
|
|
|
|
$this->insertUpdateRow( $updateKey );
|
|
|
|
|
}
|
|
|
|
|
return $apply;
|
|
|
|
|
}
|
2012-11-22 03:53:24 +00:00
|
|
|
return true;
|
2010-09-11 08:35:39 +00:00
|
|
|
}
|
|
|
|
|
|
2014-11-06 05:43:54 +00:00
|
|
|
/**
|
|
|
|
|
* Set any .htaccess files or equivilent for storage repos
|
|
|
|
|
*
|
|
|
|
|
* Some zones (e.g. "temp") used to be public and may have been initialized as such
|
|
|
|
|
*/
|
|
|
|
|
public function setFileAccess() {
|
|
|
|
|
$repo = RepoGroup::singleton()->getLocalRepo();
|
|
|
|
|
$zonePath = $repo->getZonePath( 'temp' );
|
2016-02-17 09:09:32 +00:00
|
|
|
if ( $repo->getBackend()->directoryExists( [ 'dir' => $zonePath ] ) ) {
|
2014-11-06 05:43:54 +00:00
|
|
|
// If the directory was never made, then it will have the right ACLs when it is made
|
2016-02-17 09:09:32 +00:00
|
|
|
$status = $repo->getBackend()->secure( [
|
2014-11-06 05:43:54 +00:00
|
|
|
'dir' => $zonePath,
|
|
|
|
|
'noAccess' => true,
|
|
|
|
|
'noListing' => true
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
2014-11-06 05:43:54 +00:00
|
|
|
if ( $status->isOK() ) {
|
|
|
|
|
$this->output( "Set the local repo temp zone container to be private.\n" );
|
|
|
|
|
} else {
|
|
|
|
|
$this->output( "Failed to set the local repo temp zone container to be private.\n" );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-07 14:33:11 +00:00
|
|
|
/**
|
2017-10-06 00:25:50 +00:00
|
|
|
* Purge various database caches
|
2010-09-07 14:33:11 +00:00
|
|
|
*/
|
2012-10-15 15:16:37 +00:00
|
|
|
public function purgeCache() {
|
|
|
|
|
global $wgLocalisationCacheConf;
|
2017-10-06 00:25:50 +00:00
|
|
|
// We can't guarantee that the user will be able to use TRUNCATE,
|
|
|
|
|
// but we know that DELETE is available to us
|
2010-10-01 15:11:06 +00:00
|
|
|
$this->output( "Purging caches..." );
|
2017-10-06 00:25:50 +00:00
|
|
|
|
|
|
|
|
// ObjectCache
|
2010-09-07 14:33:11 +00:00
|
|
|
$this->db->delete( 'objectcache', '*', __METHOD__ );
|
2017-10-06 00:25:50 +00:00
|
|
|
|
|
|
|
|
// LocalisationCache
|
2012-10-15 15:16:37 +00:00
|
|
|
if ( $wgLocalisationCacheConf['manualRecache'] ) {
|
|
|
|
|
$this->rebuildLocalisationCache();
|
|
|
|
|
}
|
2017-10-06 00:25:50 +00:00
|
|
|
|
|
|
|
|
// ResourceLoader: Message cache
|
2015-03-29 04:24:31 +00:00
|
|
|
$blobStore = new MessageBlobStore();
|
|
|
|
|
$blobStore->clear();
|
2017-10-06 00:25:50 +00:00
|
|
|
|
|
|
|
|
// ResourceLoader: File-dependency cache
|
2015-04-10 19:35:13 +00:00
|
|
|
$this->db->delete( 'module_deps', '*', __METHOD__ );
|
2010-10-01 15:11:06 +00:00
|
|
|
$this->output( "done.\n" );
|
2010-09-07 14:33:11 +00:00
|
|
|
}
|
2010-09-12 09:07:51 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check the site_stats table is not properly populated.
|
|
|
|
|
*/
|
|
|
|
|
protected function checkStats() {
|
2012-01-12 10:59:13 +00:00
|
|
|
$this->output( "...site_stats is populated..." );
|
2016-02-17 09:09:32 +00:00
|
|
|
$row = $this->db->selectRow( 'site_stats', '*', [ 'ss_row_id' => 1 ], __METHOD__ );
|
2010-09-12 09:07:51 +00:00
|
|
|
if ( $row === false ) {
|
2010-10-01 15:11:06 +00:00
|
|
|
$this->output( "data is missing! rebuilding...\n" );
|
2010-09-12 09:07:51 +00:00
|
|
|
} elseif ( isset( $row->site_stats ) && $row->ss_total_pages == -1 ) {
|
2010-10-01 15:11:06 +00:00
|
|
|
$this->output( "missing ss_total_pages, rebuilding...\n" );
|
2010-09-12 09:07:51 +00:00
|
|
|
} else {
|
2010-10-01 15:11:06 +00:00
|
|
|
$this->output( "done.\n" );
|
2013-10-08 11:43:42 +00:00
|
|
|
|
2010-09-12 09:07:51 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2011-06-29 15:39:40 +00:00
|
|
|
SiteStatsInit::doAllAndCommit( $this->db );
|
2010-09-12 09:07:51 +00:00
|
|
|
}
|
|
|
|
|
|
2010-09-12 16:24:03 +00:00
|
|
|
# Common updater functions
|
|
|
|
|
|
2011-11-14 21:14:31 +00:00
|
|
|
/**
|
|
|
|
|
* Sets the number of active users in the site_stats table
|
|
|
|
|
*/
|
2010-09-12 16:24:03 +00:00
|
|
|
protected function doActiveUsersInit() {
|
2018-02-27 18:37:26 +00:00
|
|
|
$activeUsers = $this->db->selectField( 'site_stats', 'ss_active_users', '', __METHOD__ );
|
2010-09-12 16:24:03 +00:00
|
|
|
if ( $activeUsers == -1 ) {
|
|
|
|
|
$activeUsers = $this->db->selectField( 'recentchanges',
|
|
|
|
|
'COUNT( DISTINCT rc_user_text )',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'rc_user != 0', 'rc_bot' => 0, "rc_log_type != 'newusers'" ], __METHOD__
|
2010-09-12 16:24:03 +00:00
|
|
|
);
|
|
|
|
|
$this->db->update( 'site_stats',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'ss_active_users' => intval( $activeUsers ) ],
|
|
|
|
|
[ 'ss_row_id' => 1 ], __METHOD__, [ 'LIMIT' => 1 ]
|
2010-09-12 16:24:03 +00:00
|
|
|
);
|
|
|
|
|
}
|
2010-10-01 15:11:06 +00:00
|
|
|
$this->output( "...ss_active_users user count set...\n" );
|
2010-09-12 16:24:03 +00:00
|
|
|
}
|
|
|
|
|
|
2011-11-14 21:14:31 +00:00
|
|
|
/**
|
|
|
|
|
* Populates the log_user_text field in the logging table
|
|
|
|
|
*/
|
2011-02-19 11:49:14 +00:00
|
|
|
protected function doLogUsertextPopulation() {
|
2011-09-08 15:52:00 +00:00
|
|
|
if ( !$this->updateRowExists( 'populate log_usertext' ) ) {
|
|
|
|
|
$this->output(
|
2013-10-08 11:43:42 +00:00
|
|
|
"Populating log_user_text field, printing progress markers. For large\n" .
|
|
|
|
|
"databases, you may want to hit Ctrl-C and do this manually with\n" .
|
|
|
|
|
"maintenance/populateLogUsertext.php.\n"
|
|
|
|
|
);
|
2011-11-11 16:58:09 +00:00
|
|
|
|
2018-01-13 00:02:09 +00:00
|
|
|
$task = $this->maintenance->runChild( PopulateLogUsertext::class );
|
2011-11-11 16:58:09 +00:00
|
|
|
$task->execute();
|
2011-11-19 17:39:56 +00:00
|
|
|
$this->output( "done.\n" );
|
2011-09-08 15:52:00 +00:00
|
|
|
}
|
2011-02-19 11:49:14 +00:00
|
|
|
}
|
|
|
|
|
|
2011-11-14 21:14:31 +00:00
|
|
|
/**
|
|
|
|
|
* Migrate log params to new table and index for searching
|
|
|
|
|
*/
|
2010-09-12 16:24:03 +00:00
|
|
|
protected function doLogSearchPopulation() {
|
2011-09-08 15:52:00 +00:00
|
|
|
if ( !$this->updateRowExists( 'populate log_search' ) ) {
|
|
|
|
|
$this->output(
|
|
|
|
|
"Populating log_search table, printing progress markers. For large\n" .
|
|
|
|
|
"databases, you may want to hit Ctrl-C and do this manually with\n" .
|
|
|
|
|
"maintenance/populateLogSearch.php.\n" );
|
2011-11-11 16:58:09 +00:00
|
|
|
|
2018-01-13 00:02:09 +00:00
|
|
|
$task = $this->maintenance->runChild( PopulateLogSearch::class );
|
2011-11-11 16:58:09 +00:00
|
|
|
$task->execute();
|
2011-11-19 17:39:56 +00:00
|
|
|
$this->output( "done.\n" );
|
2010-09-12 16:24:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-14 21:14:31 +00:00
|
|
|
/**
|
|
|
|
|
* Updates the timestamps in the transcache table
|
2014-08-23 20:34:25 +00:00
|
|
|
* @return bool
|
2011-11-14 21:14:31 +00:00
|
|
|
*/
|
2010-12-08 03:47:04 +00:00
|
|
|
protected function doUpdateTranscacheField() {
|
2010-09-12 16:24:03 +00:00
|
|
|
if ( $this->updateRowExists( 'convert transcache field' ) ) {
|
2010-10-01 15:11:06 +00:00
|
|
|
$this->output( "...transcache tc_time already converted.\n" );
|
2013-10-08 11:43:42 +00:00
|
|
|
|
2012-12-09 02:59:04 +00:00
|
|
|
return true;
|
2010-09-12 16:24:03 +00:00
|
|
|
}
|
|
|
|
|
|
2012-11-22 03:53:24 +00:00
|
|
|
return $this->applyPatch( 'patch-tc-timestamp.sql', false,
|
|
|
|
|
"Converting tc_time from UNIX epoch to MediaWiki timestamp" );
|
2010-09-12 16:24:03 +00:00
|
|
|
}
|
|
|
|
|
|
2011-11-14 21:14:31 +00:00
|
|
|
/**
|
|
|
|
|
* Update CategoryLinks collation
|
|
|
|
|
*/
|
2010-09-12 16:24:03 +00:00
|
|
|
protected function doCollationUpdate() {
|
|
|
|
|
global $wgCategoryCollation;
|
2012-11-22 03:53:24 +00:00
|
|
|
if ( $this->db->fieldExists( 'categorylinks', 'cl_collation', __METHOD__ ) ) {
|
|
|
|
|
if ( $this->db->selectField(
|
|
|
|
|
'categorylinks',
|
|
|
|
|
'COUNT(*)',
|
|
|
|
|
'cl_collation != ' . $this->db->addQuotes( $wgCategoryCollation ),
|
|
|
|
|
__METHOD__
|
2013-10-08 11:43:42 +00:00
|
|
|
) == 0
|
|
|
|
|
) {
|
|
|
|
|
$this->output( "...collations up-to-date.\n" );
|
|
|
|
|
|
|
|
|
|
return;
|
2012-11-22 03:53:24 +00:00
|
|
|
}
|
2010-09-12 16:24:03 +00:00
|
|
|
|
2012-11-22 03:53:24 +00:00
|
|
|
$this->output( "Updating category collations..." );
|
2018-01-13 00:02:09 +00:00
|
|
|
$task = $this->maintenance->runChild( UpdateCollation::class );
|
2012-11-22 03:53:24 +00:00
|
|
|
$task->execute();
|
|
|
|
|
$this->output( "...done.\n" );
|
|
|
|
|
}
|
2010-09-12 16:24:03 +00:00
|
|
|
}
|
2011-09-28 18:08:48 +00:00
|
|
|
|
2011-11-14 21:14:31 +00:00
|
|
|
/**
|
|
|
|
|
* Migrates user options from the user table blob to user_properties
|
|
|
|
|
*/
|
2011-09-28 18:08:48 +00:00
|
|
|
protected function doMigrateUserOptions() {
|
2013-04-17 14:52:47 +00:00
|
|
|
if ( $this->db->tableExists( 'user_properties' ) ) {
|
2018-01-13 00:02:09 +00:00
|
|
|
$cl = $this->maintenance->runChild( ConvertUserOptions::class, 'convertUserOptions.php' );
|
2012-11-22 03:53:24 +00:00
|
|
|
$cl->execute();
|
|
|
|
|
$this->output( "done.\n" );
|
|
|
|
|
}
|
2011-09-28 18:08:48 +00:00
|
|
|
}
|
2011-11-01 05:23:08 +00:00
|
|
|
|
2014-12-03 18:36:12 +00:00
|
|
|
/**
|
|
|
|
|
* Enable profiling table when it's turned on
|
|
|
|
|
*/
|
|
|
|
|
protected function doEnableProfiling() {
|
|
|
|
|
global $wgProfiler;
|
|
|
|
|
|
|
|
|
|
if ( !$this->doTable( 'profiling' ) ) {
|
2016-09-15 09:25:16 +00:00
|
|
|
return;
|
2014-12-03 18:36:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$profileToDb = false;
|
|
|
|
|
if ( isset( $wgProfiler['output'] ) ) {
|
|
|
|
|
$out = $wgProfiler['output'];
|
|
|
|
|
if ( $out === 'db' ) {
|
|
|
|
|
$profileToDb = true;
|
2014-11-27 17:03:07 +00:00
|
|
|
} elseif ( is_array( $out ) && in_array( 'db', $out ) ) {
|
2014-12-03 18:36:12 +00:00
|
|
|
$profileToDb = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $profileToDb && !$this->db->tableExists( 'profiling', __METHOD__ ) ) {
|
|
|
|
|
$this->applyPatch( 'patch-profiling.sql', false, 'Add profiling table' );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-14 21:14:31 +00:00
|
|
|
/**
|
|
|
|
|
* Rebuilds the localisation cache
|
|
|
|
|
*/
|
2011-11-16 15:21:44 +00:00
|
|
|
protected function rebuildLocalisationCache() {
|
2011-11-01 07:34:56 +00:00
|
|
|
/**
|
|
|
|
|
* @var $cl RebuildLocalisationCache
|
|
|
|
|
*/
|
2018-01-13 00:02:09 +00:00
|
|
|
$cl = $this->maintenance->runChild(
|
|
|
|
|
RebuildLocalisationCache::class, 'rebuildLocalisationCache.php'
|
|
|
|
|
);
|
2011-11-01 05:33:57 +00:00
|
|
|
$this->output( "Rebuilding localisation cache...\n" );
|
2011-11-01 07:34:56 +00:00
|
|
|
$cl->setForce();
|
2011-11-01 05:23:08 +00:00
|
|
|
$cl->execute();
|
2011-11-19 17:39:56 +00:00
|
|
|
$this->output( "done.\n" );
|
2011-11-01 05:23:08 +00:00
|
|
|
}
|
2013-11-01 18:24:18 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Turns off content handler fields during parts of the upgrade
|
|
|
|
|
* where they aren't available.
|
|
|
|
|
*/
|
|
|
|
|
protected function disableContentHandlerUseDB() {
|
|
|
|
|
global $wgContentHandlerUseDB;
|
|
|
|
|
|
2013-11-19 18:03:54 +00:00
|
|
|
if ( $wgContentHandlerUseDB ) {
|
2013-11-01 18:24:18 +00:00
|
|
|
$this->output( "Turning off Content Handler DB fields for this part of upgrade.\n" );
|
|
|
|
|
$this->holdContentHandlerUseDB = $wgContentHandlerUseDB;
|
|
|
|
|
$wgContentHandlerUseDB = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Turns content handler fields back on.
|
|
|
|
|
*/
|
|
|
|
|
protected function enableContentHandlerUseDB() {
|
|
|
|
|
global $wgContentHandlerUseDB;
|
|
|
|
|
|
2013-11-19 18:03:54 +00:00
|
|
|
if ( $this->holdContentHandlerUseDB ) {
|
2013-11-01 18:24:18 +00:00
|
|
|
$this->output( "Content Handler DB fields should be usable now.\n" );
|
|
|
|
|
$wgContentHandlerUseDB = $this->holdContentHandlerUseDB;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-06 17:39:14 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Migrate comments to the new 'comment' table
|
|
|
|
|
* @since 1.30
|
|
|
|
|
*/
|
|
|
|
|
protected function migrateComments() {
|
|
|
|
|
global $wgCommentTableSchemaMigrationStage;
|
|
|
|
|
if ( $wgCommentTableSchemaMigrationStage >= MIGRATION_WRITE_NEW &&
|
|
|
|
|
!$this->updateRowExists( 'MigrateComments' )
|
|
|
|
|
) {
|
|
|
|
|
$this->output(
|
|
|
|
|
"Migrating comments to the 'comments' table, printing progress markers. For large\n" .
|
|
|
|
|
"databases, you may want to hit Ctrl-C and do this manually with\n" .
|
|
|
|
|
"maintenance/migrateComments.php.\n"
|
|
|
|
|
);
|
2018-01-13 00:02:09 +00:00
|
|
|
$task = $this->maintenance->runChild( MigrateComments::class, 'migrateComments.php' );
|
2018-03-02 16:24:50 +00:00
|
|
|
$ok = $task->execute();
|
2017-09-12 17:12:29 +00:00
|
|
|
$this->output( $ok ? "done.\n" : "errors were encountered.\n" );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Migrate actors to the new 'actor' table
|
|
|
|
|
* @since 1.31
|
|
|
|
|
*/
|
|
|
|
|
protected function migrateActors() {
|
|
|
|
|
global $wgActorTableSchemaMigrationStage;
|
|
|
|
|
if ( $wgActorTableSchemaMigrationStage >= MIGRATION_WRITE_NEW &&
|
|
|
|
|
!$this->updateRowExists( 'MigrateActors' )
|
|
|
|
|
) {
|
|
|
|
|
$this->output(
|
|
|
|
|
"Migrating actors to the 'actor' table, printing progress markers. For large\n" .
|
|
|
|
|
"databases, you may want to hit Ctrl-C and do this manually with\n" .
|
|
|
|
|
"maintenance/migrateActors.php.\n"
|
|
|
|
|
);
|
|
|
|
|
$task = $this->maintenance->runChild( 'MigrateActors', 'migrateActors.php' );
|
|
|
|
|
$ok = $task->execute();
|
|
|
|
|
$this->output( $ok ? "done.\n" : "errors were encountered.\n" );
|
2017-06-06 17:39:14 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-28 21:13:09 +00:00
|
|
|
/**
|
|
|
|
|
* Migrate ar_text to modern storage
|
|
|
|
|
* @since 1.31
|
|
|
|
|
*/
|
|
|
|
|
protected function migrateArchiveText() {
|
|
|
|
|
$this->output( "Migrating archive ar_text to modern storage.\n" );
|
2018-01-13 00:02:09 +00:00
|
|
|
$task = $this->maintenance->runChild( MigrateArchiveText::class, 'migrateArchiveText.php' );
|
2017-11-28 21:13:09 +00:00
|
|
|
$task->execute();
|
|
|
|
|
$this->output( "done.\n" );
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-20 22:28:50 +00:00
|
|
|
}
|