31require_once __DIR__ .
'/Maintenance.php';
51 parent::__construct();
53 $this->
addOption(
'quick',
'Skip 5 second countdown before starting' );
55 'Do initial updates required after manual installation using tables-generated.sql' );
56 $this->
addOption(
'doshared',
'Also update shared tables' );
57 $this->
addOption(
'noschema',
'Only do the updates that are not done during schema updates' );
60 'Output SQL to do the schema updates instead of doing them. Works '
61 .
'even when $wgAllowSchemaUpdates is false',
65 $this->
addOption(
'force',
'Override when $wgAllowSchemaUpdates disables this script' );
67 'skip-external-dependencies',
68 'Skips checking whether external dependencies are up to date, mostly for developers'
71 'skip-config-validation',
72 'Skips checking whether the existing configuration is valid'
78 return Maintenance::DB_ADMIN;
85 $wgMessagesDirs[
'MediaWikiInstaller'] = dirname( __DIR__ ) .
'/includes/installer/i18n';
96 $this->
fatalError(
"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" );
103 $this->fileHandle =
null;
104 if ( str_starts_with( $this->
getOption(
'schema',
'' ),
'--' ) ) {
105 $this->
fatalError(
"The --schema option requires a file as an argument.\n" );
106 } elseif ( $this->
hasOption(
'schema' ) ) {
108 $this->fileHandle = fopen( $file,
"w" );
109 if ( $this->fileHandle ===
false ) {
110 $err = error_get_last();
111 $this->
fatalError(
"Problem opening the schema file for writing: $file\n\t{$err['message']}" );
116 if ( !$this->
hasOption(
'skip-config-validation' ) ) {
117 $this->validateSettings();
122 RequestContext::getMain()->setLanguage( $lang );
127 define(
'MW_UPDATER',
true );
134 if ( !$this->
hasOption(
'skip-external-dependencies' ) && !getenv(
'MW_SKIP_EXTERNAL_DEPENDENCIES' ) ) {
135 $composerLockUpToDate = $this->
runChild( CheckComposerLockUpToDate::class );
136 $composerLockUpToDate->execute();
139 "Skipping checking whether external dependencies are up to date, proceed at your own risk\n"
143 # Attempt to connect to the database as a privileged user
144 # This will vomit up an error if there are permissions problems
147 # Check to see whether the database server meets the minimum requirements
149 $dbInstallerClass = Installer::getDBInstallerClass( $db->getType() );
150 $status = $dbInstallerClass::meetsMinimumRequirement( $db );
151 if ( !$status->isOK() ) {
156 $dbDomain = WikiMap::getCurrentWikiDbDomain()->getId();
157 $this->
output(
"Going to run database updates for $dbDomain\n" );
158 if ( $db->getType() ===
'sqlite' ) {
160 '@phan-var DatabaseSqlite $db';
161 $this->
output(
"Using SQLite file: '{$db->getDbFilePath()}'\n" );
163 $this->
output(
"Depending on the size of your database this may take a while!\n" );
166 $this->
output(
"Abort with control-c in the next five seconds "
167 .
"(skip this countdown with --quick) ..." );
171 $time1 = microtime(
true );
173 $shared = $this->
hasOption(
'doshared' );
175 $updates = [
'core',
'extensions' ];
178 $updates[] =
'noschema';
180 $updates[] =
'stats';
183 $updates[] =
'initial';
186 $updater = DatabaseUpdater::newForDB( $db, $shared, $this );
192 if ( !$updater->fieldExists(
'revision',
'rev_actor' ) ) {
194 "Can not upgrade from versions older than 1.35, please upgrade to that version or later first."
198 $updater->doUpdates( $updates );
200 foreach ( $updater->getPostDatabaseUpdateMaintenance() as $maint ) {
206 if ( !$isLoggedUpdate && $updater->updateRowExists( $maint ) ) {
211 if ( !$isLoggedUpdate ) {
212 $updater->insertUpdateRow( $maint );
216 $updater->setFileAccess();
218 $updater->purgeCache();
220 $time2 = microtime(
true );
222 $timeDiff = $lang->formatTimePeriod( $time2 - $time1 );
223 $this->
output(
"\nDone in $timeDiff.\n" );
229 # Don't try to access the database
230 # This needs to be disabled early since extensions will try to use the l10n
231 # cache from $wgExtensionFunctions (T22471)
233 'class' => LocalisationCache::class,
234 'storeClass' => LCStoreNull::class,
235 'storeDirectory' =>
false,
236 'manualRecache' =>
false,
246 $this->
getHookRunner()->onMaintenanceUpdateAddParams( $params );
251 foreach ( $params as $name => $param ) {
255 isset( $param[
'require'] ) ? $param[
'require'] :
false,
256 isset( $param[
'withArg'] ) ? $param[
'withArg'] :
false,
257 isset( $param[
'shortName'] ) ? $param[
'shortName'] :
false,
258 isset( $param[
'multiOccurrence'] ) ? $param[
'multiOccurrence'] : false
262 parent::validateParamsAndArgs();
265 private function formatWarnings( array $warnings ): string {
267 foreach ( $warnings as $warning ) {
268 $warning = wordwrap( $warning, 75,
"\n " );
269 $text .=
"* $warning\n";
274 private function validateSettings() {
275 $settings = SettingsBuilder::getInstance();
278 if ( $settings->getWarnings() ) {
279 $warnings = $settings->getWarnings();
282 $status = $settings->validate();
283 if ( !$status->isOK() ) {
284 foreach ( $status->getMessages(
'error' ) as $msg ) {
289 $deprecations = $settings->detectDeprecatedConfig();
290 foreach ( $deprecations as $key => $msg ) {
291 $warnings[] =
"$key is deprecated: $msg";
294 $obsolete = $settings->detectObsoleteConfig();
295 foreach ( $obsolete as $key => $msg ) {
296 $warnings[] =
"$key is obsolete: $msg";
300 $this->fatalError(
"Some of your configuration settings caused a warning:\n\n"
301 . $this->formatWarnings( $warnings ) .
"\n"
302 .
"Please correct the issue before running update.php again.\n"
303 .
"If you know what you are doing, you can bypass this check\n"
304 .
"using --skip-config-validation.\n" );
311require_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.
if(!defined( 'MW_NO_SESSION') &&MW_ENTRY_POINT !=='cli' $wgLang
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...
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.
runChild( $maintClass, $classFile=null)
Returns an instance of the given maintenance script, with all of the current arguments passed to it.
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...
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.