Go to the documentation of this file.
30 require_once __DIR__ .
'/Maintenance.php';
42 parent::__construct();
44 $this->
addOption(
'skip-compat-checks',
'Skips compatibility checks, mostly for developers' );
45 $this->
addOption(
'quick',
'Skip 5 second countdown before starting' );
46 $this->
addOption(
'doshared',
'Also update shared tables' );
47 $this->
addOption(
'noschema',
'Only do the updates that are not done during schema updates' );
50 'Output SQL to do the schema updates instead of doing them. Works '
51 .
'even when $wgAllowSchemaUpdates is false',
55 $this->
addOption(
'force',
'Override when $wgAllowSchemaUpdates disables this script' );
57 'skip-external-dependencies',
58 'Skips checking whether external dependencies are up to date, mostly for developers'
69 $pcreVersion = explode(
' ', PCRE_VERSION, 2 )[0];
70 if ( version_compare( $pcreVersion, $minimumPcreVersion,
'<' ) ) {
72 "PCRE $minimumPcreVersion or later is required.\n" .
73 "Your PHP binary is linked with PCRE $pcreVersion.\n\n" .
74 "More information:\n" .
75 "https://www.mediawiki.org/wiki/Manual:Errors_and_symptoms/PCRE\n\n" .
88 $this->
fatalError(
"Do not run update.php on this wiki. If you're seeing this you should\n"
89 .
"probably ask for some help in performing your schema updates or use\n"
90 .
"the --noschema and --schema options to get an SQL file for someone\n"
91 .
"else to inspect and run.\n\n"
92 .
"If you know what you are doing, you can continue with --force\n" );
95 $this->fileHandle =
null;
96 if ( substr( $this->
getOption(
'schema' ), 0, 2 ) ===
"--" ) {
97 $this->
fatalError(
"The --schema option requires a file as an argument.\n" );
98 } elseif ( $this->
hasOption(
'schema' ) ) {
100 $this->fileHandle = fopen(
$file,
"w" );
101 if ( $this->fileHandle ===
false ) {
102 $err = error_get_last();
103 $this->
fatalError(
"Problem opening the schema file for writing: $file\n\t{$err['message']}" );
108 $wgMessagesDirs[
'MediawikiInstaller'] = dirname( __DIR__ ) .
'/includes/installer/i18n';
110 $lang = MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage(
'en' );
117 define(
'MW_UPDATER',
true );
121 MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->waitForReplication();
123 if ( !$this->
hasOption(
'skip-compat-checks' ) ) {
126 $this->
output(
"Skipping compatibility checks, proceed at your own risk (Ctrl+C to abort)\n" );
131 if ( !$this->
hasOption(
'skip-external-dependencies' ) ) {
132 $composerLockUpToDate = $this->
runChild( CheckComposerLockUpToDate::class );
133 $composerLockUpToDate->execute();
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
144 # Check to see whether the database server meets the minimum requirements
147 $status = $dbInstallerClass::meetsMinimumRequirement( $db->getServerVersion() );
148 if ( !$status->isOK() ) {
150 $text = $status->getWikiText();
155 $this->
output(
"Going to run database updates for $dbDomain\n" );
156 if ( $db->getType() ===
'sqlite' ) {
158 '@phan-var DatabaseSqlite $db';
159 $this->
output(
"Using SQLite file: '{$db->getDbFilePath()}'\n" );
161 $this->
output(
"Depending on the size of your database this may take a while!\n" );
164 $this->
output(
"Abort with control-c in the next five seconds "
165 .
"(skip this countdown with --quick) ... " );
169 $time1 = microtime(
true );
171 $shared = $this->
hasOption(
'doshared' );
173 $updates = [
'core',
'extensions' ];
176 $updates[] =
'noschema';
178 $updates[] =
'stats';
182 $updater->doUpdates( $updates );
184 foreach ( $updater->getPostDatabaseUpdateMaintenance() as $maint ) {
190 if ( !$isLoggedUpdate && $updater->updateRowExists( $maint ) ) {
195 if ( !$isLoggedUpdate ) {
196 $updater->insertUpdateRow( $maint );
200 $updater->setFileAccess();
202 $updater->purgeCache();
204 $time2 = microtime(
true );
206 $timeDiff =
$lang->formatTimePeriod( $time2 - $time1 );
207 $this->
output(
"\nDone in $timeDiff.\n" );
213 # Don't try to access the database
214 # This needs to be disabled early since extensions will try to use the l10n
215 # cache from $wgExtensionFunctions (T22471)
217 'class' => LocalisationCache::class,
218 'storeClass' => LCStoreNull::class,
219 'storeDirectory' =>
false,
220 'manualRecache' =>
false,
232 $this->
getHookRunner()->onMaintenanceUpdateAddParams( $params );
237 foreach ( $params as $name => $param ) {
241 isset( $param[
'require'] ) ? $param[
'require'] :
false,
242 isset( $param[
'withArg'] ) ? $param[
'withArg'] :
false,
243 isset( $param[
'shortName'] ) ? $param[
'shortName'] :
false,
244 isset( $param[
'multiOccurrence'] ) ? $param[
'multiOccurrence'] :
false
248 parent::validateParamsAndArgs();
253 require_once 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.
const MW_VERSION
The running version of MediaWiki.
$wgMessagesDirs
Extension messages directories.
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...
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...
execute()
Do the actual work.
getHookRunner()
Get a HookRunner for running core hooks.
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.
getOption( $name, $default=null)
Get an option, or return the default.
output( $out, $channel=null)
Throw some output to the user.
const MINIMUM_PCRE_VERSION
The oldest version of PCRE we can support.
hasOption( $name)
Checks to see if a particular option exists.
static getDBInstallerClass( $type)
Get the DatabaseInstaller class name for this type.