30require_once __DIR__ .
'/Maintenance.php';
47 parent::__construct();
49 $this->
addOption(
'quick',
'Skip 5 second countdown before starting' );
50 $this->
addOption(
'doshared',
'Also update shared tables' );
51 $this->
addOption(
'noschema',
'Only do the updates that are not done during schema updates' );
54 'Output SQL to do the schema updates instead of doing them. Works '
55 .
'even when $wgAllowSchemaUpdates is false',
59 $this->
addOption(
'force',
'Override when $wgAllowSchemaUpdates disables this script' );
61 'skip-external-dependencies',
62 'Skips checking whether external dependencies are up to date, mostly for developers'
65 'skip-config-validation',
66 'Skips checking whether the existing configuration is valid'
78 $wgMessagesDirs[
'MediaWikiInstaller'] = dirname( __DIR__ ) .
'/includes/installer/i18n';
89 $this->
fatalError(
"Do not run update.php on this wiki. If you're seeing this you should\n"
90 .
"probably ask for some help in performing your schema updates or use\n"
91 .
"the --noschema and --schema options to get an SQL file for someone\n"
92 .
"else to inspect and run.\n\n"
93 .
"If you know what you are doing, you can continue with --force\n" );
96 $this->fileHandle =
null;
97 if ( str_starts_with( $this->
getOption(
'schema',
'' ),
'--' ) ) {
98 $this->
fatalError(
"The --schema option requires a file as an argument.\n" );
99 } elseif ( $this->
hasOption(
'schema' ) ) {
101 $this->fileHandle = fopen( $file,
"w" );
102 if ( $this->fileHandle ===
false ) {
103 $err = error_get_last();
104 $this->
fatalError(
"Problem opening the schema file for writing: $file\n\t{$err['message']}" );
109 if ( !$this->
hasOption(
'skip-config-validation' ) ) {
110 $this->validateSettings();
115 RequestContext::getMain()->setLanguage( $lang );
120 define(
'MW_UPDATER',
true );
127 if ( !$this->
hasOption(
'skip-external-dependencies' ) ) {
128 $composerLockUpToDate = $this->
runChild( CheckComposerLockUpToDate::class );
129 $composerLockUpToDate->execute();
132 "Skipping checking whether external dependencies are up to date, proceed at your own risk\n"
136 # Attempt to connect to the database as a privileged user
137 # This will vomit up an error if there are permissions problems
140 # Check to see whether the database server meets the minimum requirements
142 $dbInstallerClass = Installer::getDBInstallerClass( $db->getType() );
143 $status = $dbInstallerClass::meetsMinimumRequirement( $db );
144 if ( !$status->isOK() ) {
146 $text = $status->getWikiText();
150 $dbDomain = WikiMap::getCurrentWikiDbDomain()->getId();
151 $this->
output(
"Going to run database updates for $dbDomain\n" );
152 if ( $db->getType() ===
'sqlite' ) {
154 '@phan-var DatabaseSqlite $db';
155 $this->
output(
"Using SQLite file: '{$db->getDbFilePath()}'\n" );
157 $this->
output(
"Depending on the size of your database this may take a while!\n" );
160 $this->
output(
"Abort with control-c in the next five seconds "
161 .
"(skip this countdown with --quick) ..." );
165 $time1 = microtime(
true );
167 $shared = $this->
hasOption(
'doshared' );
169 $updates = [
'core',
'extensions' ];
172 $updates[] =
'noschema';
174 $updates[] =
'stats';
177 $updater = DatabaseUpdater::newForDB( $db, $shared, $this );
183 if ( $updater->fieldExists(
'archive',
'ar_user' ) ) {
185 "Can not upgrade from versions older than 1.35, please upgrade to that version or later first."
189 $updater->doUpdates( $updates );
191 foreach ( $updater->getPostDatabaseUpdateMaintenance() as $maint ) {
197 if ( !$isLoggedUpdate && $updater->updateRowExists( $maint ) ) {
202 if ( !$isLoggedUpdate ) {
203 $updater->insertUpdateRow( $maint );
207 $updater->setFileAccess();
209 $updater->purgeCache();
211 $time2 = microtime(
true );
213 $timeDiff = $lang->formatTimePeriod( $time2 - $time1 );
214 $this->
output(
"\nDone in $timeDiff.\n" );
220 # Don't try to access the database
221 # This needs to be disabled early since extensions will try to use the l10n
222 # cache from $wgExtensionFunctions (T22471)
224 'class' => LocalisationCache::class,
225 'storeClass' => LCStoreNull::class,
226 'storeDirectory' =>
false,
227 'manualRecache' =>
false,
242 foreach (
$params as $name => $param ) {
246 isset( $param[
'require'] ) ? $param[
'require'] :
false,
247 isset( $param[
'withArg'] ) ? $param[
'withArg'] :
false,
248 isset( $param[
'shortName'] ) ? $param[
'shortName'] :
false,
249 isset( $param[
'multiOccurrence'] ) ? $param[
'multiOccurrence'] : false
253 parent::validateParamsAndArgs();
256 private function formatWarnings( array $warnings ) {
258 foreach ( $warnings as $warning ) {
259 $warning = wordwrap( $warning, 75,
"\n " );
260 $text .=
"* $warning\n";
265 private function validateSettings() {
266 $settings = SettingsBuilder::getInstance();
269 if ( $settings->getWarnings() ) {
270 $warnings = $settings->getWarnings();
273 $status = $settings->validate();
274 if ( !$status->isOK() ) {
275 foreach ( $status->getErrorsByType(
'error' ) as $msg ) {
276 $msg =
wfMessage( $msg[
'message'], ...$msg[
'params'] );
277 $warnings[] = $msg->text();
281 $deprecations = $settings->detectDeprecatedConfig();
282 foreach ( $deprecations as $key => $msg ) {
283 $warnings[] =
"$key is deprecated: $msg";
286 $obsolete = $settings->detectObsoleteConfig();
287 foreach ( $obsolete as $key => $msg ) {
288 $warnings[] =
"$key is obsolete: $msg";
292 $this->
fatalError(
"Some of your configuration settings caused a warning:\n\n"
293 . $this->formatWarnings( $warnings ) .
"\n"
294 .
"Please correct the issue before running update.php again.\n"
295 .
"If you know what you are doing, you can bypass this check\n"
296 .
"using --skip-config-validation.\n" );
302require_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)
Run a child maintenance script.
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.