Merge "Remove not used private member variable mParserWarnings from OutputPage"
[mediawiki.git] / maintenance / update.php
blobeeaf9c83b0f2a18d5208fdb75a8e8cac9649bd54
1 #!/usr/bin/env php
2 <?php
3 /**
4 * Run all updaters.
6 * This is used when the database schema is modified and we need to apply patches.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * http://www.gnu.org/copyleft/gpl.html
23 * @file
24 * @todo document
25 * @ingroup Maintenance
28 $wgUseMasterForMaintenance = true;
29 require_once __DIR__ . '/Maintenance.php';
31 /**
32 * Maintenance script to run database schema updates.
34 * @ingroup Maintenance
36 class UpdateMediaWiki extends Maintenance {
37 function __construct() {
38 parent::__construct();
39 $this->mDescription = "MediaWiki database updater";
40 $this->addOption( 'skip-compat-checks', 'Skips compatibility checks, mostly for developers' );
41 $this->addOption( 'quick', 'Skip 5 second countdown before starting' );
42 $this->addOption( 'doshared', 'Also update shared tables' );
43 $this->addOption( 'nopurge', 'Do not purge the objectcache table after updates' );
44 $this->addOption( 'noschema', 'Only do the updates that are not done during schema updates' );
45 $this->addOption(
46 'schema',
47 'Output SQL to do the schema updates instead of doing them. Works '
48 . 'even when $wgAllowSchemaUpdates is false',
49 false,
50 true
52 $this->addOption( 'force', 'Override when $wgAllowSchemaUpdates disables this script' );
53 $this->addOption(
54 'skip-external-dependencies',
55 'Skips checking whether external dependencies are up to date, mostly for developers'
59 function getDbType() {
60 return Maintenance::DB_ADMIN;
63 function compatChecks() {
64 $minimumPcreVersion = Installer::MINIMUM_PCRE_VERSION;
66 list( $pcreVersion ) = explode( ' ', PCRE_VERSION, 2 );
67 if ( version_compare( $pcreVersion, $minimumPcreVersion, '<' ) ) {
68 $this->error(
69 "PCRE $minimumPcreVersion or later is required.\n" .
70 "Your PHP binary is linked with PCRE $pcreVersion.\n\n" .
71 "More information:\n" .
72 "https://www.mediawiki.org/wiki/Manual:Errors_and_symptoms/PCRE\n\n" .
73 "ABORTING.\n",
74 true );
77 $test = new PhpXmlBugTester();
78 if ( !$test->ok ) {
79 $this->error(
80 "Your system has a combination of PHP and libxml2 versions that is buggy\n" .
81 "and can cause hidden data corruption in MediaWiki and other web apps.\n" .
82 "Upgrade to libxml2 2.7.3 or later.\n" .
83 "ABORTING (see https://bugs.php.net/bug.php?id=45996).\n",
84 true );
88 function execute() {
89 global $wgVersion, $wgLang, $wgAllowSchemaUpdates;
91 if ( !$wgAllowSchemaUpdates
92 && !( $this->hasOption( 'force' )
93 || $this->hasOption( 'schema' )
94 || $this->hasOption( 'noschema' ) )
95 ) {
96 $this->error( "Do not run update.php on this wiki. If you're seeing this you should\n"
97 . "probably ask for some help in performing your schema updates or use\n"
98 . "the --noschema and --schema options to get an SQL file for someone\n"
99 . "else to inspect and run.\n\n"
100 . "If you know what you are doing, you can continue with --force\n", true );
103 $this->fileHandle = null;
104 if ( substr( $this->getOption( 'schema' ), 0, 2 ) === "--" ) {
105 $this->error( "The --schema option requires a file as an argument.\n", true );
106 } elseif ( $this->hasOption( 'schema' ) ) {
107 $file = $this->getOption( 'schema' );
108 $this->fileHandle = fopen( $file, "w" );
109 if ( $this->fileHandle === false ) {
110 $err = error_get_last();
111 $this->error( "Problem opening the schema file for writing: $file\n\t{$err['message']}", true );
115 $wgLang = Language::factory( 'en' );
117 define( 'MW_UPDATER', true );
119 $this->output( "MediaWiki {$wgVersion} Updater\n\n" );
121 wfWaitForSlaves();
123 if ( !$this->hasOption( 'skip-compat-checks' ) ) {
124 $this->compatChecks();
125 } else {
126 $this->output( "Skipping compatibility checks, proceed at your own risk (Ctrl+C to abort)\n" );
127 wfCountdown( 5 );
130 // Check external dependencies are up to date
131 if ( !$this->hasOption( 'skip-external-dependencies' ) ) {
132 $composerLockUpToDate = $this->runChild( 'CheckComposerLockUpToDate' );
133 $composerLockUpToDate->execute();
134 } else {
135 $this->output(
136 "Skipping checking whether external dependencies are up to date, proceed at your own risk\n"
140 # Attempt to connect to the database as a privileged user
141 # This will vomit up an error if there are permissions problems
142 $db = $this->getDB( DB_MASTER );
144 $this->output( "Going to run database updates for " . wfWikiID() . "\n" );
145 if ( $db->getType() === 'sqlite' ) {
146 $this->output( "Using SQLite file: '{$db->getDbFilePath()}'\n" );
148 $this->output( "Depending on the size of your database this may take a while!\n" );
150 if ( !$this->hasOption( 'quick' ) ) {
151 $this->output( "Abort with control-c in the next five seconds "
152 . "(skip this countdown with --quick) ... " );
153 wfCountDown( 5 );
156 $time1 = microtime( true );
158 $shared = $this->hasOption( 'doshared' );
160 $updates = array( 'core', 'extensions' );
161 if ( !$this->hasOption( 'schema' ) ) {
162 if ( $this->hasOption( 'noschema' ) ) {
163 $updates[] = 'noschema';
165 $updates[] = 'stats';
168 $updater = DatabaseUpdater::newForDb( $db, $shared, $this );
169 $updater->doUpdates( $updates );
171 foreach ( $updater->getPostDatabaseUpdateMaintenance() as $maint ) {
172 $child = $this->runChild( $maint );
174 // LoggedUpdateMaintenance is checking the updatelog itself
175 $isLoggedUpdate = $child instanceof LoggedUpdateMaintenance;
177 if ( !$isLoggedUpdate && $updater->updateRowExists( $maint ) ) {
178 continue;
181 $child->execute();
182 if ( !$isLoggedUpdate ) {
183 $updater->insertUpdateRow( $maint );
187 $updater->setFileAccess();
188 if ( !$this->hasOption( 'nopurge' ) ) {
189 $updater->purgeCache();
192 $time2 = microtime( true );
194 $timeDiff = $wgLang->formatTimePeriod( $time2 - $time1 );
195 $this->output( "\nDone in $timeDiff.\n" );
198 function afterFinalSetup() {
199 global $wgLocalisationCacheConf;
201 # Don't try to access the database
202 # This needs to be disabled early since extensions will try to use the l10n
203 # cache from $wgExtensionFunctions (bug 20471)
204 $wgLocalisationCacheConf = array(
205 'class' => 'LocalisationCache',
206 'storeClass' => 'LCStoreNull',
207 'storeDirectory' => false,
208 'manualRecache' => false,
213 $maintClass = 'UpdateMediaWiki';
214 require_once RUN_MAINTENANCE_IF_MAIN;