2014-05-09 10:24:11 +00:00
|
|
|
#!/usr/bin/env php
|
2004-10-13 07:38:43 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Run all updaters.
|
|
|
|
|
*
|
2008-07-19 12:15:07 +00:00
|
|
|
* This is used when the database schema is modified and we need to apply patches.
|
|
|
|
|
*
|
2010-12-16 19:15:12 +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
|
|
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @file
|
2004-10-13 07:38:43 +00:00
|
|
|
* @todo document
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup Maintenance
|
2005-08-02 13:35:19 +00:00
|
|
|
*/
|
2004-10-13 07:38:43 +00:00
|
|
|
|
2013-05-17 00:16:59 +00:00
|
|
|
require_once __DIR__ . '/Maintenance.php';
|
2009-07-03 06:56:46 +00:00
|
|
|
|
2019-08-26 12:24:37 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2019-07-04 07:31:06 +00:00
|
|
|
use Wikimedia\Rdbms\DatabaseSqlite;
|
2017-03-30 20:46:06 +00:00
|
|
|
|
2012-09-03 18:10:09 +00:00
|
|
|
/**
|
|
|
|
|
* Maintenance script to run database schema updates.
|
|
|
|
|
*
|
|
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
2010-09-07 14:33:11 +00:00
|
|
|
class UpdateMediaWiki extends Maintenance {
|
2019-10-09 18:41:33 +00:00
|
|
|
public function __construct() {
|
2010-09-07 14:33:11 +00:00
|
|
|
parent::__construct();
|
2016-01-30 02:48:47 +00:00
|
|
|
$this->addDescription( 'MediaWiki database updater' );
|
2010-09-07 14:33:11 +00:00
|
|
|
$this->addOption( 'skip-compat-checks', 'Skips compatibility checks, mostly for developers' );
|
|
|
|
|
$this->addOption( 'quick', 'Skip 5 second countdown before starting' );
|
|
|
|
|
$this->addOption( 'doshared', 'Also update shared tables' );
|
|
|
|
|
$this->addOption( 'nopurge', 'Do not purge the objectcache table after updates' );
|
2012-11-22 03:53:24 +00:00
|
|
|
$this->addOption( 'noschema', 'Only do the updates that are not done during schema updates' );
|
2014-04-22 20:55:25 +00:00
|
|
|
$this->addOption(
|
|
|
|
|
'schema',
|
|
|
|
|
'Output SQL to do the schema updates instead of doing them. Works '
|
|
|
|
|
. 'even when $wgAllowSchemaUpdates is false',
|
|
|
|
|
false,
|
|
|
|
|
true
|
|
|
|
|
);
|
2011-11-03 20:15:27 +00:00
|
|
|
$this->addOption( 'force', 'Override when $wgAllowSchemaUpdates disables this script' );
|
2015-01-31 21:55:13 +00:00
|
|
|
$this->addOption(
|
|
|
|
|
'skip-external-dependencies',
|
|
|
|
|
'Skips checking whether external dependencies are up to date, mostly for developers'
|
|
|
|
|
);
|
2010-09-07 14:33:11 +00:00
|
|
|
}
|
2006-04-26 20:42:15 +00:00
|
|
|
|
2019-10-09 18:41:33 +00:00
|
|
|
public function getDbType() {
|
2015-05-11 14:34:02 +00:00
|
|
|
return Maintenance::DB_ADMIN;
|
2010-09-07 14:33:11 +00:00
|
|
|
}
|
2006-11-11 16:59:32 +00:00
|
|
|
|
2019-10-11 19:07:32 +00:00
|
|
|
private function compatChecks() {
|
2015-06-28 01:03:48 +00:00
|
|
|
$minimumPcreVersion = Installer::MINIMUM_PCRE_VERSION;
|
2013-12-16 16:02:51 +00:00
|
|
|
|
2019-05-17 14:54:47 +00:00
|
|
|
$pcreVersion = explode( ' ', PCRE_VERSION, 2 )[0];
|
2013-12-16 16:02:51 +00:00
|
|
|
if ( version_compare( $pcreVersion, $minimumPcreVersion, '<' ) ) {
|
2017-11-20 00:36:54 +00:00
|
|
|
$this->fatalError(
|
2013-12-16 16:02:51 +00:00
|
|
|
"PCRE $minimumPcreVersion or later is required.\n" .
|
|
|
|
|
"Your PHP binary is linked with PCRE $pcreVersion.\n\n" .
|
|
|
|
|
"More information:\n" .
|
|
|
|
|
"https://www.mediawiki.org/wiki/Manual:Errors_and_symptoms/PCRE\n\n" .
|
2017-11-20 00:36:54 +00:00
|
|
|
"ABORTING.\n" );
|
2013-12-16 16:02:51 +00:00
|
|
|
}
|
2010-11-06 22:16:19 +00:00
|
|
|
}
|
|
|
|
|
|
2019-10-09 18:41:33 +00:00
|
|
|
public function execute() {
|
2020-02-25 01:33:18 +00:00
|
|
|
global $wgLang, $wgAllowSchemaUpdates, $wgMessagesDirs;
|
2011-07-13 22:14:19 +00:00
|
|
|
|
2014-04-22 20:55:25 +00:00
|
|
|
if ( !$wgAllowSchemaUpdates
|
|
|
|
|
&& !( $this->hasOption( 'force' )
|
|
|
|
|
|| $this->hasOption( 'schema' )
|
|
|
|
|
|| $this->hasOption( 'noschema' ) )
|
|
|
|
|
) {
|
2017-11-20 00:36:54 +00:00
|
|
|
$this->fatalError( "Do not run update.php on this wiki. If you're seeing this you should\n"
|
2012-11-22 03:53:24 +00:00
|
|
|
. "probably ask for some help in performing your schema updates or use\n"
|
|
|
|
|
. "the --noschema and --schema options to get an SQL file for someone\n"
|
|
|
|
|
. "else to inspect and run.\n\n"
|
2017-11-20 00:36:54 +00:00
|
|
|
. "If you know what you are doing, you can continue with --force\n" );
|
2012-11-22 03:53:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->fileHandle = null;
|
2013-04-17 14:52:47 +00:00
|
|
|
if ( substr( $this->getOption( 'schema' ), 0, 2 ) === "--" ) {
|
2017-11-20 00:36:54 +00:00
|
|
|
$this->fatalError( "The --schema option requires a file as an argument.\n" );
|
2013-04-17 14:52:47 +00:00
|
|
|
} elseif ( $this->hasOption( 'schema' ) ) {
|
2012-11-22 03:53:24 +00:00
|
|
|
$file = $this->getOption( 'schema' );
|
|
|
|
|
$this->fileHandle = fopen( $file, "w" );
|
2013-04-17 14:52:47 +00:00
|
|
|
if ( $this->fileHandle === false ) {
|
2012-11-22 03:53:24 +00:00
|
|
|
$err = error_get_last();
|
2017-11-20 00:36:54 +00:00
|
|
|
$this->fatalError( "Problem opening the schema file for writing: $file\n\t{$err['message']}" );
|
2012-11-22 03:53:24 +00:00
|
|
|
}
|
2011-07-13 22:14:19 +00:00
|
|
|
}
|
2004-10-13 07:38:43 +00:00
|
|
|
|
2018-10-11 18:20:30 +00:00
|
|
|
// T206765: We need to load the installer i18n files as some of errors come installer/updater code
|
|
|
|
|
$wgMessagesDirs['MediawikiInstaller'] = dirname( __DIR__ ) . '/includes/installer/i18n';
|
|
|
|
|
|
2019-08-26 12:24:37 +00:00
|
|
|
$lang = MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage( 'en' );
|
2017-02-20 22:48:21 +00:00
|
|
|
// Set global language to ensure localised errors are in English (T22633)
|
2016-03-01 21:36:08 +00:00
|
|
|
RequestContext::getMain()->setLanguage( $lang );
|
|
|
|
|
$wgLang = $lang; // BackCompat
|
2004-12-10 06:05:30 +00:00
|
|
|
|
2013-11-21 00:27:23 +00:00
|
|
|
define( 'MW_UPDATER', true );
|
|
|
|
|
|
2020-02-25 01:33:18 +00:00
|
|
|
$this->output( 'MediaWiki ' . MW_VERSION . " Updater\n\n" );
|
2011-11-11 17:06:03 +00:00
|
|
|
|
2015-03-03 21:14:13 +00:00
|
|
|
wfWaitForSlaves();
|
2010-09-07 14:33:11 +00:00
|
|
|
|
2010-09-11 21:56:11 +00:00
|
|
|
if ( !$this->hasOption( 'skip-compat-checks' ) ) {
|
2010-11-06 22:16:19 +00:00
|
|
|
$this->compatChecks();
|
2010-09-07 14:33:11 +00:00
|
|
|
} else {
|
|
|
|
|
$this->output( "Skipping compatibility checks, proceed at your own risk (Ctrl+C to abort)\n" );
|
2017-10-13 00:24:46 +00:00
|
|
|
$this->countDown( 5 );
|
2010-09-07 14:33:11 +00:00
|
|
|
}
|
|
|
|
|
|
2015-01-17 01:49:49 +00:00
|
|
|
// Check external dependencies are up to date
|
2015-01-31 21:55:13 +00:00
|
|
|
if ( !$this->hasOption( 'skip-external-dependencies' ) ) {
|
2018-01-13 00:02:09 +00:00
|
|
|
$composerLockUpToDate = $this->runChild( CheckComposerLockUpToDate::class );
|
2015-01-31 21:55:13 +00:00
|
|
|
$composerLockUpToDate->execute();
|
|
|
|
|
} else {
|
|
|
|
|
$this->output(
|
|
|
|
|
"Skipping checking whether external dependencies are up to date, proceed at your own risk\n"
|
|
|
|
|
);
|
|
|
|
|
}
|
2015-01-17 01:49:49 +00:00
|
|
|
|
2010-09-07 14:33:11 +00:00
|
|
|
# Attempt to connect to the database as a privileged user
|
|
|
|
|
# This will vomit up an error if there are permissions problems
|
2015-12-31 00:07:37 +00:00
|
|
|
$db = $this->getDB( DB_MASTER );
|
2010-09-07 14:33:11 +00:00
|
|
|
|
2017-10-03 05:14:33 +00:00
|
|
|
# Check to see whether the database server meets the minimum requirements
|
|
|
|
|
/** @var DatabaseInstaller $dbInstallerClass */
|
|
|
|
|
$dbInstallerClass = Installer::getDBInstallerClass( $db->getType() );
|
|
|
|
|
$status = $dbInstallerClass::meetsMinimumRequirement( $db->getServerVersion() );
|
|
|
|
|
if ( !$status->isOK() ) {
|
|
|
|
|
// This might output some wikitext like <strong> but it should be comprehensible
|
|
|
|
|
$text = $status->getWikiText();
|
2017-11-20 00:36:54 +00:00
|
|
|
$this->fatalError( $text );
|
2017-10-03 05:14:33 +00:00
|
|
|
}
|
|
|
|
|
|
2019-07-04 07:31:06 +00:00
|
|
|
$dbDomain = WikiMap::getCurrentWikiDbDomain()->getId();
|
|
|
|
|
$this->output( "Going to run database updates for $dbDomain\n" );
|
2013-04-17 14:52:47 +00:00
|
|
|
if ( $db->getType() === 'sqlite' ) {
|
2019-08-31 16:14:38 +00:00
|
|
|
/** @var DatabaseSqlite $db */
|
|
|
|
|
'@phan-var DatabaseSqlite $db';
|
2015-03-07 12:31:08 +00:00
|
|
|
$this->output( "Using SQLite file: '{$db->getDbFilePath()}'\n" );
|
2012-11-06 12:55:58 +00:00
|
|
|
}
|
2010-09-07 14:33:11 +00:00
|
|
|
$this->output( "Depending on the size of your database this may take a while!\n" );
|
|
|
|
|
|
|
|
|
|
if ( !$this->hasOption( 'quick' ) ) {
|
2014-04-22 20:55:25 +00:00
|
|
|
$this->output( "Abort with control-c in the next five seconds "
|
|
|
|
|
. "(skip this countdown with --quick) ... " );
|
2017-10-13 00:24:46 +00:00
|
|
|
$this->countDown( 5 );
|
2010-09-07 14:33:11 +00:00
|
|
|
}
|
2004-12-10 06:05:30 +00:00
|
|
|
|
2014-05-26 15:02:45 +00:00
|
|
|
$time1 = microtime( true );
|
2013-11-03 14:47:02 +00:00
|
|
|
|
2010-09-07 14:33:11 +00:00
|
|
|
$shared = $this->hasOption( 'doshared' );
|
2011-03-30 20:56:03 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$updates = [ 'core', 'extensions' ];
|
2013-04-17 14:52:47 +00:00
|
|
|
if ( !$this->hasOption( 'schema' ) ) {
|
|
|
|
|
if ( $this->hasOption( 'noschema' ) ) {
|
2012-11-22 03:53:24 +00:00
|
|
|
$updates[] = 'noschema';
|
|
|
|
|
}
|
|
|
|
|
$updates[] = 'stats';
|
|
|
|
|
}
|
2006-01-17 11:48:18 +00:00
|
|
|
|
2016-03-19 00:08:06 +00:00
|
|
|
$updater = DatabaseUpdater::newForDB( $db, $shared, $this );
|
2011-03-30 20:56:03 +00:00
|
|
|
$updater->doUpdates( $updates );
|
2004-10-13 07:38:43 +00:00
|
|
|
|
2013-04-17 14:52:47 +00:00
|
|
|
foreach ( $updater->getPostDatabaseUpdateMaintenance() as $maint ) {
|
2012-10-12 18:52:29 +00:00
|
|
|
$child = $this->runChild( $maint );
|
|
|
|
|
|
|
|
|
|
// LoggedUpdateMaintenance is checking the updatelog itself
|
2015-06-28 01:03:48 +00:00
|
|
|
$isLoggedUpdate = $child instanceof LoggedUpdateMaintenance;
|
2012-10-12 18:52:29 +00:00
|
|
|
|
|
|
|
|
if ( !$isLoggedUpdate && $updater->updateRowExists( $maint ) ) {
|
2011-11-11 17:06:03 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
2012-11-22 03:53:24 +00:00
|
|
|
|
2010-10-26 21:42:49 +00:00
|
|
|
$child->execute();
|
2012-10-12 18:52:29 +00:00
|
|
|
if ( !$isLoggedUpdate ) {
|
|
|
|
|
$updater->insertUpdateRow( $maint );
|
|
|
|
|
}
|
2010-09-07 14:33:11 +00:00
|
|
|
}
|
|
|
|
|
|
2014-11-06 05:43:54 +00:00
|
|
|
$updater->setFileAccess();
|
2013-04-17 14:52:47 +00:00
|
|
|
if ( !$this->hasOption( 'nopurge' ) ) {
|
2012-10-15 15:16:37 +00:00
|
|
|
$updater->purgeCache();
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-26 15:02:45 +00:00
|
|
|
$time2 = microtime( true );
|
|
|
|
|
|
2016-03-01 21:36:08 +00:00
|
|
|
$timeDiff = $lang->formatTimePeriod( $time2 - $time1 );
|
2014-05-26 15:02:45 +00:00
|
|
|
$this->output( "\nDone in $timeDiff.\n" );
|
2010-09-07 14:33:11 +00:00
|
|
|
}
|
2004-10-13 07:38:43 +00:00
|
|
|
|
2019-10-11 19:07:32 +00:00
|
|
|
protected function afterFinalSetup() {
|
2010-09-07 20:45:04 +00:00
|
|
|
global $wgLocalisationCacheConf;
|
|
|
|
|
|
|
|
|
|
# Don't try to access the database
|
|
|
|
|
# This needs to be disabled early since extensions will try to use the l10n
|
2017-02-20 22:48:21 +00:00
|
|
|
# cache from $wgExtensionFunctions (T22471)
|
2016-02-17 09:09:32 +00:00
|
|
|
$wgLocalisationCacheConf = [
|
2018-01-13 00:02:09 +00:00
|
|
|
'class' => LocalisationCache::class,
|
|
|
|
|
'storeClass' => LCStoreNull::class,
|
2010-09-07 20:45:04 +00:00
|
|
|
'storeDirectory' => false,
|
|
|
|
|
'manualRecache' => false,
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2010-09-07 20:45:04 +00:00
|
|
|
}
|
2019-03-22 02:52:11 +00:00
|
|
|
|
2019-07-11 02:16:49 +00:00
|
|
|
/**
|
|
|
|
|
* @throws FatalError
|
|
|
|
|
* @throws MWException
|
|
|
|
|
* @suppress PhanPluginDuplicateConditionalNullCoalescing
|
|
|
|
|
*/
|
2019-03-22 02:52:11 +00:00
|
|
|
public function validateParamsAndArgs() {
|
|
|
|
|
// Allow extensions to add additional params.
|
|
|
|
|
$params = [];
|
|
|
|
|
Hooks::run( 'MaintenanceUpdateAddParams', [ &$params ] );
|
2019-07-11 02:16:49 +00:00
|
|
|
|
|
|
|
|
// This executes before the PHP version check, so don't use null coalesce (??).
|
|
|
|
|
// Keeping this compatible with older PHP versions lets us reach the code that
|
|
|
|
|
// displays a more helpful error.
|
2019-10-12 17:38:08 +00:00
|
|
|
// @phan-suppress-next-line PhanEmptyForeach False positive
|
2019-03-22 02:52:11 +00:00
|
|
|
foreach ( $params as $name => $param ) {
|
|
|
|
|
$this->addOption(
|
|
|
|
|
$name,
|
|
|
|
|
$param['desc'],
|
2019-07-11 02:16:49 +00:00
|
|
|
isset( $param['require'] ) ? $param['require'] : false,
|
|
|
|
|
isset( $param['withArg'] ) ? $param['withArg'] : false,
|
|
|
|
|
isset( $param['shortName'] ) ? $param['shortName'] : false,
|
2019-07-11 13:54:47 +00:00
|
|
|
isset( $param['multiOccurrence'] ) ? $param['multiOccurrence'] : false
|
2019-03-22 02:52:11 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parent::validateParamsAndArgs();
|
|
|
|
|
}
|
2009-09-04 02:03:23 +00:00
|
|
|
}
|
2010-09-07 14:33:11 +00:00
|
|
|
|
2018-01-13 00:02:09 +00:00
|
|
|
$maintClass = UpdateMediaWiki::class;
|
2013-05-07 23:00:15 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|