28require_once __DIR__ .
'/Maintenance.php';
40 parent::__construct();
42 $this->
addOption(
'skip-compat-checks',
'Skips compatibility checks, mostly for developers' );
43 $this->
addOption(
'quick',
'Skip 5 second countdown before starting' );
44 $this->
addOption(
'doshared',
'Also update shared tables' );
45 $this->
addOption(
'nopurge',
'Do not purge the objectcache table after updates' );
46 $this->
addOption(
'noschema',
'Only do the updates that are not done during schema updates' );
49 'Output SQL to do the schema updates instead of doing them. Works '
50 .
'even when $wgAllowSchemaUpdates is false',
54 $this->
addOption(
'force',
'Override when $wgAllowSchemaUpdates disables this script' );
56 'skip-external-dependencies',
57 'Skips checking whether external dependencies are up to date, mostly for developers'
68 $pcreVersion = explode(
' ', PCRE_VERSION, 2 )[0];
69 if ( version_compare( $pcreVersion, $minimumPcreVersion,
'<' ) ) {
71 "PCRE $minimumPcreVersion or later is required.\n" .
72 "Your PHP binary is linked with PCRE $pcreVersion.\n\n" .
73 "More information:\n" .
74 "https://www.mediawiki.org/wiki/Manual:Errors_and_symptoms/PCRE\n\n" .
87 $this->
fatalError(
"Do not run update.php on this wiki. If you're seeing this you should\n"
88 .
"probably ask for some help in performing your schema updates or use\n"
89 .
"the --noschema and --schema options to get an SQL file for someone\n"
90 .
"else to inspect and run.\n\n"
91 .
"If you know what you are doing, you can continue with --force\n" );
94 $this->fileHandle =
null;
95 if ( substr( $this->
getOption(
'schema',
'' ), 0, 2 ) ===
"--" ) {
96 $this->
fatalError(
"The --schema option requires a file as an argument.\n" );
97 } elseif ( $this->
hasOption(
'schema' ) ) {
99 $this->fileHandle = fopen(
$file,
"w" );
100 if ( $this->fileHandle ===
false ) {
101 $err = error_get_last();
102 $this->
fatalError(
"Problem opening the schema file for writing: $file\n\t{$err['message']}" );
107 $wgMessagesDirs[
'MediawikiInstaller'] = dirname( __DIR__ ) .
'/includes/installer/i18n';
109 $lang = MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage(
'en' );
111 RequestContext::getMain()->setLanguage(
$lang );
116 define(
'MW_UPDATER',
true );
120 MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->waitForReplication();
122 if ( !$this->
hasOption(
'skip-compat-checks' ) ) {
125 $this->
output(
"Skipping compatibility checks, proceed at your own risk (Ctrl+C to abort)\n" );
130 if ( !$this->
hasOption(
'skip-external-dependencies' ) ) {
131 $composerLockUpToDate = $this->
runChild( CheckComposerLockUpToDate::class );
132 $composerLockUpToDate->execute();
135 "Skipping checking whether external dependencies are up to date, proceed at your own risk\n"
139 # Attempt to connect to the database as a privileged user
140 # This will vomit up an error if there are permissions problems
143 # Check to see whether the database server meets the minimum requirements
146 $status = $dbInstallerClass::meetsMinimumRequirement( $db->getServerVersion() );
147 if ( !$status->isOK() ) {
149 $text = $status->getWikiText();
153 $dbDomain = WikiMap::getCurrentWikiDbDomain()->getId();
154 $this->
output(
"Going to run database updates for $dbDomain\n" );
155 if ( $db->getType() ===
'sqlite' ) {
157 '@phan-var DatabaseSqlite $db';
158 $this->
output(
"Using SQLite file: '{$db->getDbFilePath()}'\n" );
160 $this->
output(
"Depending on the size of your database this may take a while!\n" );
163 $this->
output(
"Abort with control-c in the next five seconds "
164 .
"(skip this countdown with --quick) ... " );
168 $time1 = microtime(
true );
170 $shared = $this->
hasOption(
'doshared' );
172 $updates = [
'core',
'extensions' ];
175 $updates[] =
'noschema';
177 $updates[] =
'stats';
180 $updater = DatabaseUpdater::newForDB( $db, $shared, $this );
181 $updater->doUpdates( $updates );
183 foreach ( $updater->getPostDatabaseUpdateMaintenance() as $maint ) {
189 if ( !$isLoggedUpdate && $updater->updateRowExists( $maint ) ) {
194 if ( !$isLoggedUpdate ) {
195 $updater->insertUpdateRow( $maint );
199 $updater->setFileAccess();
201 $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();
$wgMessagesDirs
Extension messages directories.
$wgAllowSchemaUpdates
Allow schema updates.
$wgLocalisationCacheConf
Localisation cache configuration.
const MW_VERSION
The running version of MediaWiki.
const RUN_MAINTENANCE_IF_MAIN
const MINIMUM_PCRE_VERSION
The oldest version of PCRE we can support.
static getDBInstallerClass( $type)
Get the DatabaseInstaller class name for this type.
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
execute()
Do the actual work.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
getHookRunner()
Get a HookRunner for running core hooks.
hasOption( $name)
Checks to see if a particular option was set.
countDown( $seconds)
Count down from $seconds to zero on the terminal, with a one-second pause between showing each number...
runChild( $maintClass, $classFile=null)
Run a child maintenance script.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
if(!isset( $args[0])) $lang