Go to the documentation of this file.
28 require_once __DIR__ .
'/Maintenance.php';
39 parent::__construct();
41 $this->
addOption(
'skip-compat-checks',
'Skips compatibility checks, mostly for developers' );
42 $this->
addOption(
'quick',
'Skip 5 second countdown before starting' );
43 $this->
addOption(
'doshared',
'Also update shared tables' );
44 $this->
addOption(
'nopurge',
'Do not purge the objectcache table after updates' );
45 $this->
addOption(
'noschema',
'Only do the updates that are not done during schema updates' );
48 'Output SQL to do the schema updates instead of doing them. Works '
49 .
'even when $wgAllowSchemaUpdates is false',
53 $this->
addOption(
'force',
'Override when $wgAllowSchemaUpdates disables this script' );
55 'skip-external-dependencies',
56 'Skips checking whether external dependencies are up to date, mostly for developers'
67 $pcreVersion = explode(
' ', PCRE_VERSION, 2 )[0];
68 if ( version_compare( $pcreVersion, $minimumPcreVersion,
'<' ) ) {
70 "PCRE $minimumPcreVersion or later is required.\n" .
71 "Your PHP binary is linked with PCRE $pcreVersion.\n\n" .
72 "More information:\n" .
73 "https://www.mediawiki.org/wiki/Manual:Errors_and_symptoms/PCRE\n\n" .
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" );
95 $this->
fatalError(
"Do not run update.php on this wiki. If you're seeing this you should\n"
96 .
"probably ask for some help in performing your schema updates or use\n"
97 .
"the --noschema and --schema options to get an SQL file for someone\n"
98 .
"else to inspect and run.\n\n"
99 .
"If you know what you are doing, you can continue with --force\n" );
102 $this->fileHandle =
null;
103 if ( substr( $this->
getOption(
'schema' ), 0, 2 ) ===
"--" ) {
104 $this->
fatalError(
"The --schema option requires a file as an argument.\n" );
105 } elseif ( $this->
hasOption(
'schema' ) ) {
107 $this->fileHandle = fopen(
$file,
"w" );
108 if ( $this->fileHandle ===
false ) {
109 $err = error_get_last();
110 $this->
fatalError(
"Problem opening the schema file for writing: $file\n\t{$err['message']}" );
115 $wgMessagesDirs[
'MediawikiInstaller'] = dirname( __DIR__ ) .
'/includes/installer/i18n';
122 define(
'MW_UPDATER',
true );
124 $this->
output(
"MediaWiki {$wgVersion} Updater\n\n" );
128 if ( !$this->
hasOption(
'skip-compat-checks' ) ) {
131 $this->
output(
"Skipping compatibility checks, proceed at your own risk (Ctrl+C to abort)\n" );
136 if ( !$this->
hasOption(
'skip-external-dependencies' ) ) {
137 $composerLockUpToDate = $this->
runChild( CheckComposerLockUpToDate::class );
138 $composerLockUpToDate->execute();
141 "Skipping checking whether external dependencies are up to date, proceed at your own risk\n"
145 # Attempt to connect to the database as a privileged user
146 # This will vomit up an error if there are permissions problems
149 # Check to see whether the database server meets the minimum requirements
152 $status = $dbInstallerClass::meetsMinimumRequirement( $db->getServerVersion() );
155 $text =
$status->getWikiText();
160 $this->
output(
"Going to run database updates for $dbDomain\n" );
161 if ( $db->getType() ===
'sqlite' ) {
163 '@phan-var DatabaseSqlite $db';
164 $this->
output(
"Using SQLite file: '{$db->getDbFilePath()}'\n" );
166 $this->
output(
"Depending on the size of your database this may take a while!\n" );
169 $this->
output(
"Abort with control-c in the next five seconds "
170 .
"(skip this countdown with --quick) ... " );
174 $time1 = microtime(
true );
176 $badPhpUnit = dirname( __DIR__ ) .
'/vendor/phpunit/phpunit/src/Util/PHP/eval-stdin.php';
177 if ( file_exists( $badPhpUnit ) ) {
181 $md5 = md5_file( $badPhpUnit );
182 if ( $md5 ===
'120ac49800671dc383b6f3709c25c099'
183 || $md5 ===
'28af792cb38fc9a1b236b91c1aad2876'
187 $this->
output(
"Removed PHPUnit eval-stdin.php to protect against CVE-2017-9841\n" );
189 $this->
error(
"Unable to remove $badPhpUnit, you should manually. See CVE-2017-9841" );
194 $shared = $this->
hasOption(
'doshared' );
196 $updates = [
'core',
'extensions' ];
199 $updates[] =
'noschema';
201 $updates[] =
'stats';
205 $updater->doUpdates( $updates );
207 foreach ( $updater->getPostDatabaseUpdateMaintenance() as $maint ) {
213 if ( !$isLoggedUpdate && $updater->updateRowExists( $maint ) ) {
218 if ( !$isLoggedUpdate ) {
219 $updater->insertUpdateRow( $maint );
223 $updater->setFileAccess();
225 $updater->purgeCache();
228 $time2 = microtime(
true );
230 $timeDiff =
$lang->formatTimePeriod( $time2 - $time1 );
231 $this->
output(
"\nDone in $timeDiff.\n" );
237 # Don't try to access the database
238 # This needs to be disabled early since extensions will try to use the l10n
239 # cache from $wgExtensionFunctions (T22471)
241 'class' => LocalisationCache::class,
242 'storeClass' => LCStoreNull::class,
243 'storeDirectory' =>
false,
244 'manualRecache' =>
false,
256 Hooks::run(
'MaintenanceUpdateAddParams', [ &$params ] );
261 foreach ( $params as $name => $param ) {
265 isset( $param[
'require'] ) ? $param[
'require'] :
false,
266 isset( $param[
'withArg'] ) ? $param[
'withArg'] :
false,
267 isset( $param[
'shortName'] ) ? $param[
'shortName'] :
false,
268 isset( $param[
'multiOccurrence'] ) ? $param[
'multiOccurrence'] :
false
272 parent::validateParamsAndArgs();
const RUN_MAINTENANCE_IF_MAIN
static newForDB(IMaintainableDatabase $db, $shared=false, Maintenance $maintenance=null)
static getCurrentWikiDbDomain()
if(!isset( $args[0])) $lang
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
addDescription( $text)
Set the description text.
runChild( $maintClass, $classFile=null)
Run a child maintenance script.
$wgVersion
MediaWiki version number.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
$wgAllowSchemaUpdates
Allow schema updates.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
wfWaitForSlaves( $ifWritesSince=null, $wiki=false, $cluster=false, $timeout=null)
Waits for the replica DBs to catch up to the master position.
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
$wgLocalisationCacheConf
Localisation cache configuration.
countDown( $seconds)
Count down from $seconds to zero on the terminal, with a one-second pause between showing each number...
$wgMessagesDirs['ReplaceText']
execute()
Do the actual work.
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
static getMain()
Get the RequestContext object associated with the main request.
Test for PHP+libxml2 bug which breaks XML input subtly with certain versions.
getOption( $name, $default=null)
Get an option, or return the default.
error( $err, $die=0)
Throw an error to the user.
output( $out, $channel=null)
Throw some output to the user.
const MINIMUM_PCRE_VERSION
The oldest version of PCRE we can support.
static factory( $code)
Get a cached or new language object for a given language code.
hasOption( $name)
Checks to see if a particular option exists.
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
static getDBInstallerClass( $type)
Get the DatabaseInstaller class name for this type.