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'
77 return Maintenance::DB_ADMIN;
84 $wgMessagesDirs[
'MediaWikiInstaller'] = dirname( __DIR__ ) .
'/includes/installer/i18n';
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 ( str_starts_with( $this->
getOption(
'schema',
'' ),
'--' ) ) {
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 if ( !$this->
hasOption(
'skip-config-validation' ) ) {
116 $this->validateSettings();
121 RequestContext::getMain()->setLanguage( $lang );
126 define(
'MW_UPDATER',
true );
133 if ( !$this->
hasOption(
'skip-external-dependencies' ) && !getenv(
'MW_SKIP_EXTERNAL_DEPENDENCIES' ) ) {
134 $composerLockUpToDate = $this->
runChild( CheckComposerLockUpToDate::class );
135 $composerLockUpToDate->execute();
138 "Skipping checking whether external dependencies are up to date, proceed at your own risk\n"
142 # Attempt to connect to the database as a privileged user
143 # This will vomit up an error if there are permissions problems
146 # Check to see whether the database server meets the minimum requirements
148 $dbInstallerClass = Installer::getDBInstallerClass( $db->getType() );
149 $status = $dbInstallerClass::meetsMinimumRequirement( $db );
150 if ( !$status->isOK() ) {
155 $dbDomain = WikiMap::getCurrentWikiDbDomain()->getId();
156 $this->
output(
"Going to run database updates for $dbDomain\n" );
157 if ( $db->getType() ===
'sqlite' ) {
159 '@phan-var DatabaseSqlite $db';
160 $this->
output(
"Using SQLite file: '{$db->getDbFilePath()}'\n" );
162 $this->
output(
"Depending on the size of your database this may take a while!\n" );
165 $this->
output(
"Abort with control-c in the next five seconds "
166 .
"(skip this countdown with --quick) ..." );
170 $time1 = microtime(
true );
172 $shared = $this->
hasOption(
'doshared' );
174 $updates = [
'core',
'extensions' ];
177 $updates[] =
'noschema';
179 $updates[] =
'stats';
182 $updates[] =
'initial';
185 $updater = DatabaseUpdater::newForDB( $db, $shared, $this );
191 if ( !$updater->fieldExists(
'revision',
'rev_actor' ) ) {
193 "Can not upgrade from versions older than 1.35, please upgrade to that version or later first."
197 $updater->doUpdates( $updates );
199 foreach ( $updater->getPostDatabaseUpdateMaintenance() as $maint ) {
205 if ( !$isLoggedUpdate && $updater->updateRowExists( $maint ) ) {
210 if ( !$isLoggedUpdate ) {
211 $updater->insertUpdateRow( $maint );
215 $updater->setFileAccess();
217 $updater->purgeCache();
219 $time2 = microtime(
true );
221 $timeDiff = $lang->formatTimePeriod( $time2 - $time1 );
222 $this->
output(
"\nDone in $timeDiff.\n" );
228 # Don't try to access the database
229 # This needs to be disabled early since extensions will try to use the l10n
230 # cache from $wgExtensionFunctions (T22471)
232 'class' => LocalisationCache::class,
233 'storeClass' => LCStoreNull::class,
234 'storeDirectory' =>
false,
235 'manualRecache' =>
false,
250 foreach (
$params as $name => $param ) {
254 isset( $param[
'require'] ) ? $param[
'require'] :
false,
255 isset( $param[
'withArg'] ) ? $param[
'withArg'] :
false,
256 isset( $param[
'shortName'] ) ? $param[
'shortName'] :
false,
257 isset( $param[
'multiOccurrence'] ) ? $param[
'multiOccurrence'] : false
261 parent::validateParamsAndArgs();
264 private function formatWarnings( array $warnings ) {
266 foreach ( $warnings as $warning ) {
267 $warning = wordwrap( $warning, 75,
"\n " );
268 $text .=
"* $warning\n";
273 private function validateSettings() {
274 $settings = SettingsBuilder::getInstance();
277 if ( $settings->getWarnings() ) {
278 $warnings = $settings->getWarnings();
281 $status = $settings->validate();
282 if ( !$status->isOK() ) {
283 foreach ( $status->getMessages(
'error' ) as $msg ) {
288 $deprecations = $settings->detectDeprecatedConfig();
289 foreach ( $deprecations as $key => $msg ) {
290 $warnings[] =
"$key is deprecated: $msg";
293 $obsolete = $settings->detectObsoleteConfig();
294 foreach ( $obsolete as $key => $msg ) {
295 $warnings[] =
"$key is obsolete: $msg";
299 $this->
fatalError(
"Some of your configuration settings caused a warning:\n\n"
300 . $this->formatWarnings( $warnings ) .
"\n"
301 .
"Please correct the issue before running update.php again.\n"
302 .
"If you know what you are doing, you can bypass this check\n"
303 .
"using --skip-config-validation.\n" );
310require_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
array $params
The job parameters.
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.
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.