17require_once __DIR__ .
'/Maintenance.php';
39 parent::__construct();
41 $this->
addOption(
'quick',
'Skip 5 second countdown before starting' );
43 'Do initial updates required after manual installation using tables-generated.sql' );
44 $this->
addOption(
'doshared',
'Also update shared tables' );
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'
59 'skip-config-validation',
60 'Skips checking whether the existing configuration is valid'
64 'Output a message for each update that has already been applied before'
70 return Maintenance::DB_ADMIN;
77 $wgMessagesDirs[
'MediaWikiInstaller'] = dirname( __DIR__ ) .
'/includes/Installer/i18n';
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 ( str_starts_with( $this->
getOption(
'schema',
'' ),
'--' ) ) {
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 if ( !$this->
hasOption(
'skip-config-validation' ) ) {
109 $this->validateSettings();
114 RequestContext::getMain()->setLanguage( $lang );
119 define(
'MW_UPDATER',
true );
126 if ( !$this->
hasOption(
'skip-external-dependencies' ) && !getenv(
'MW_SKIP_EXTERNAL_DEPENDENCIES' ) ) {
127 $composerLockUpToDate = $this->
createChild( CheckComposerLockUpToDate::class );
128 $composerLockUpToDate->execute();
131 "Skipping checking whether external dependencies are up to date, proceed at your own risk\n"
135 # Attempt to connect to the database as a privileged user
136 # This will vomit up an error if there are permissions problems
139 # Check to see whether the database server meets the minimum requirements
141 $dbInstallerClass = Installer::getDBInstallerClass( $db->getType() );
142 $status = $dbInstallerClass::meetsMinimumRequirement( $db );
143 if ( !$status->isOK() ) {
148 $dbDomain = WikiMap::getCurrentWikiDbDomain()->getId();
149 $this->
output(
"Going to run database updates for $dbDomain\n" );
150 if ( $db->getType() ===
'sqlite' ) {
152 '@phan-var DatabaseSqlite $db';
153 $this->
output(
"Using SQLite file: '{$db->getDbFilePath()}'\n" );
155 $this->
output(
"Depending on the size of your database this may take a while!\n" );
158 $this->
output(
"Abort with control-c in the next five seconds "
159 .
"(skip this countdown with --quick) ..." );
163 $time1 = microtime(
true );
165 $shared = $this->
hasOption(
'doshared' );
167 $updates = [
'core',
'extensions' ];
170 $updates[] =
'noschema';
172 $updates[] =
'stats';
175 $updates[] =
'initial';
178 $updater = DatabaseUpdater::newForDB( $db, $shared, $this );
179 $updater->logApplied = $this->
hasOption(
'log-applied' );
185 if ( !$updater->tableExists(
'user_autocreate_serial' ) ) {
187 "Can not upgrade from versions older than 1.39, please upgrade to that version or later first."
191 $updater->doUpdates( $updates );
193 foreach ( $updater->getPostDatabaseUpdateMaintenance() as $maint ) {
198 if ( !$isLoggedUpdate && $updater->updateRowExists( $maint ) ) {
199 $updater->outputApplied(
"...Update '{$maint}' already logged as completed.\n" );
203 $updater->outputApplied(
"..." . $child->updateSkippedMessage() .
"\n" );
208 if ( !$isLoggedUpdate ) {
209 $updater->insertUpdateRow( $maint );
212 $updater->outputAppliedSummary();
214 $updater->setFileAccess();
216 $updater->purgeCache();
218 $time2 = microtime(
true );
220 $timeDiff = $lang->formatTimePeriod( $time2 - $time1 );
221 $this->
output(
"\nDone in $timeDiff.\n" );
227 # Don't try to access the database
228 # This needs to be disabled early since extensions will try to use the l10n
229 # cache from $wgExtensionFunctions (T22471)
231 'class' => LocalisationCache::class,
232 'storeClass' => LCStoreNull::class,
233 'storeDirectory' =>
false,
234 'manualRecache' =>
false,
244 $this->
getHookRunner()->onMaintenanceUpdateAddParams( $params );
249 foreach ( $params as $name => $param ) {
253 isset( $param[
'require'] ) ? $param[
'require'] :
false,
254 isset( $param[
'withArg'] ) ? $param[
'withArg'] :
false,
255 isset( $param[
'shortName'] ) ? $param[
'shortName'] :
false,
256 isset( $param[
'multiOccurrence'] ) ? $param[
'multiOccurrence'] : false
260 parent::validateParamsAndArgs();
263 private function formatWarnings( array $warnings ): string {
265 foreach ( $warnings as $warning ) {
266 $warning = wordwrap( $warning, 75,
"\n " );
267 $text .=
"* $warning\n";
272 private function validateSettings() {
273 $settings = SettingsBuilder::getInstance();
276 if ( $settings->getWarnings() ) {
277 $warnings = $settings->getWarnings();
280 $status = $settings->validate();
281 if ( !$status->isOK() ) {
282 foreach ( $status->getMessages(
'error' ) as $msg ) {
287 $deprecations = $settings->detectDeprecatedConfig();
288 foreach ( $deprecations as $key => $msg ) {
289 $warnings[] =
"$key is deprecated: $msg";
292 $obsolete = $settings->detectObsoleteConfig();
293 foreach ( $obsolete as $key => $msg ) {
294 $warnings[] =
"$key is obsolete: $msg";
298 $this->fatalError(
"Some of your configuration settings caused a warning:\n\n"
299 . $this->formatWarnings( $warnings ) .
"\n"
300 .
"Please correct the issue before running update.php again.\n"
301 .
"If you know what you are doing, you can bypass this check\n"
302 .
"using --skip-config-validation.\n" );
309require_once RUN_MAINTENANCE_IF_MAIN;
const MW_VERSION
The running version of MediaWiki.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Group all the pieces relevant to the context of a request into one instance.
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
execute()
Do the actual work.All child classes will need to implement thisbool|null|void True for success,...
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
createChild(string $maintClass, ?string $classFile=null)
Returns an instance of the given maintenance script, with all of the current arguments passed to it.
output( $out, $channel=null)
Throw some output to the user.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
waitForReplication()
Wait for replica DB servers to catch up.
hasOption( $name)
Checks to see if a particular option was set.
getOption( $name, $default=null)
Get an option, or return the default.
getHookRunner()
Get a HookRunner for running core hooks.
getServiceContainer()
Returns the main service container.
countDown( $seconds)
Count down from $seconds to zero on the terminal, with a one-second pause between showing each number...
getPrimaryDB(string|false $virtualDomain=false)
addDescription( $text)
Set the description text.
$wgMessagesDirs
Config variable stub for the MessagesDirs setting, for use by phpdoc and IDEs.
$wgAllowSchemaUpdates
Config variable stub for the AllowSchemaUpdates setting, for use by phpdoc and IDEs.
$wgLocalisationCacheConf
Config variable stub for the LocalisationCacheConf setting, for use by phpdoc and IDEs.