31require_once __DIR__ .
'/Maintenance.php';
49 parent::__construct();
51 $this->
addOption(
'quick',
'Skip 5 second countdown before starting' );
53 'Do initial updates required after manual installation using tables-generated.sql' );
54 $this->
addOption(
'doshared',
'Also update shared tables' );
55 $this->
addOption(
'noschema',
'Only do the updates that are not done during schema updates' );
58 'Output SQL to do the schema updates instead of doing them. Works '
59 .
'even when $wgAllowSchemaUpdates is false',
63 $this->
addOption(
'force',
'Override when $wgAllowSchemaUpdates disables this script' );
65 'skip-external-dependencies',
66 'Skips checking whether external dependencies are up to date, mostly for developers'
69 'skip-config-validation',
70 'Skips checking whether the existing configuration is valid'
82 $wgMessagesDirs[
'MediaWikiInstaller'] = dirname( __DIR__ ) .
'/includes/installer/i18n';
93 $this->
fatalError(
"Do not run update.php on this wiki. If you're seeing this you should\n"
94 .
"probably ask for some help in performing your schema updates or use\n"
95 .
"the --noschema and --schema options to get an SQL file for someone\n"
96 .
"else to inspect and run.\n\n"
97 .
"If you know what you are doing, you can continue with --force\n" );
100 $this->fileHandle =
null;
101 if ( str_starts_with( $this->
getOption(
'schema',
'' ),
'--' ) ) {
102 $this->
fatalError(
"The --schema option requires a file as an argument.\n" );
103 } elseif ( $this->
hasOption(
'schema' ) ) {
105 $this->fileHandle = fopen( $file,
"w" );
106 if ( $this->fileHandle ===
false ) {
107 $err = error_get_last();
108 $this->
fatalError(
"Problem opening the schema file for writing: $file\n\t{$err['message']}" );
113 if ( !$this->
hasOption(
'skip-config-validation' ) ) {
114 $this->validateSettings();
119 RequestContext::getMain()->setLanguage( $lang );
124 define(
'MW_UPDATER',
true );
131 if ( !$this->
hasOption(
'skip-external-dependencies' ) && !getenv(
'MW_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
146 $dbInstallerClass = Installer::getDBInstallerClass( $db->getType() );
147 $status = $dbInstallerClass::meetsMinimumRequirement( $db );
148 if ( !$status->isOK() ) {
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 $updates[] =
'initial';
183 $updater = DatabaseUpdater::newForDB( $db, $shared, $this );
189 if ( !$updater->fieldExists(
'revision',
'rev_actor' ) ) {
191 "Can not upgrade from versions older than 1.35, please upgrade to that version or later first."
195 $updater->doUpdates( $updates );
197 foreach ( $updater->getPostDatabaseUpdateMaintenance() as $maint ) {
203 if ( !$isLoggedUpdate && $updater->updateRowExists( $maint ) ) {
208 if ( !$isLoggedUpdate ) {
209 $updater->insertUpdateRow( $maint );
213 $updater->setFileAccess();
215 $updater->purgeCache();
217 $time2 = microtime(
true );
219 $timeDiff = $lang->formatTimePeriod( $time2 - $time1 );
220 $this->
output(
"\nDone in $timeDiff.\n" );
226 # Don't try to access the database
227 # This needs to be disabled early since extensions will try to use the l10n
228 # cache from $wgExtensionFunctions (T22471)
230 'class' => LocalisationCache::class,
231 'storeClass' => LCStoreNull::class,
232 'storeDirectory' =>
false,
233 'manualRecache' =>
false,
248 foreach (
$params as $name => $param ) {
252 isset( $param[
'require'] ) ? $param[
'require'] :
false,
253 isset( $param[
'withArg'] ) ? $param[
'withArg'] :
false,
254 isset( $param[
'shortName'] ) ? $param[
'shortName'] :
false,
255 isset( $param[
'multiOccurrence'] ) ? $param[
'multiOccurrence'] : false
259 parent::validateParamsAndArgs();
262 private function formatWarnings( array $warnings ) {
264 foreach ( $warnings as $warning ) {
265 $warning = wordwrap( $warning, 75,
"\n " );
266 $text .=
"* $warning\n";
271 private function validateSettings() {
272 $settings = SettingsBuilder::getInstance();
275 if ( $settings->getWarnings() ) {
276 $warnings = $settings->getWarnings();
279 $status = $settings->validate();
280 if ( !$status->isOK() ) {
281 foreach ( $status->getMessages(
'error' ) as $msg ) {
286 $deprecations = $settings->detectDeprecatedConfig();
287 foreach ( $deprecations as $key => $msg ) {
288 $warnings[] =
"$key is deprecated: $msg";
291 $obsolete = $settings->detectObsoleteConfig();
292 foreach ( $obsolete as $key => $msg ) {
293 $warnings[] =
"$key is obsolete: $msg";
297 $this->
fatalError(
"Some of your configuration settings caused a warning:\n\n"
298 . $this->formatWarnings( $warnings ) .
"\n"
299 .
"Please correct the issue before running update.php again.\n"
300 .
"If you know what you are doing, you can bypass this check\n"
301 .
"using --skip-config-validation.\n" );
308require_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.
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.
waitForReplication()
Wait for replica DBs to catch up.
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)
Returns an instance of the given maintenance script, with all of the current arguments passed to it.
getServiceContainer()
Returns the main service container.
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.
Group all the pieces relevant to the context of a request into one instance.
$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.