r80205 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80204‎ | r80205 | r80206 >
Date:22:58, 13 January 2011
Author:demon
Status:ok (Comments)
Tags:
Comment:
Fix concern raised by Brion in r74108 (but has really existed since the maintenance rewrite). Right now, including a maintenance script causes it to execute. This is bad when you want to reuse the particular class but not have it start executing all by itself.

Until now, we relied on setting MW_NO_SETUP which was a) hacky, b) irreversable, and c) likely to be forgotten if you didn't use one of the wrappers like runChild().

Instead, move the freaky magic to doMaintenance and have *it* check if it's in a specific call stack that indicates this is being run from the file scope and should be executed. Rename DO_MAINTENANCE to RUN_MAINTENANCE_IF_MAIN so it's nice and clear what magic happens behind the require_once().
Modified paths:
  • /trunk/phase3/docs/maintenance.txt (modified) (history)
  • /trunk/phase3/includes/installer/DatabaseUpdater.php (modified) (history)
  • /trunk/phase3/maintenance/Maintenance.php (modified) (history)
  • /trunk/phase3/maintenance/addwiki.php (modified) (history)
  • /trunk/phase3/maintenance/attachLatest.php (modified) (history)
  • /trunk/phase3/maintenance/benchmarks/bench_HTTP_HTTPS.php (modified) (history)
  • /trunk/phase3/maintenance/benchmarks/bench_strtr_str_replace.php (modified) (history)
  • /trunk/phase3/maintenance/benchmarks/bench_wfIsWindows.php (modified) (history)
  • /trunk/phase3/maintenance/benchmarks/benchmarkPurge.php (modified) (history)
  • /trunk/phase3/maintenance/changePassword.php (modified) (history)
  • /trunk/phase3/maintenance/checkAutoLoader.php (modified) (history)
  • /trunk/phase3/maintenance/checkBadRedirects.php (modified) (history)
  • /trunk/phase3/maintenance/checkImages.php (modified) (history)
  • /trunk/phase3/maintenance/checkSyntax.php (modified) (history)
  • /trunk/phase3/maintenance/checkUsernames.php (modified) (history)
  • /trunk/phase3/maintenance/cleanupCaps.php (modified) (history)
  • /trunk/phase3/maintenance/cleanupImages.php (modified) (history)
  • /trunk/phase3/maintenance/cleanupRemovedModules.php (modified) (history)
  • /trunk/phase3/maintenance/cleanupSpam.php (modified) (history)
  • /trunk/phase3/maintenance/cleanupTitles.php (modified) (history)
  • /trunk/phase3/maintenance/cleanupWatchlist.php (modified) (history)
  • /trunk/phase3/maintenance/clear_interwiki_cache.php (modified) (history)
  • /trunk/phase3/maintenance/clear_stats.php (modified) (history)
  • /trunk/phase3/maintenance/commandLine.inc (modified) (history)
  • /trunk/phase3/maintenance/compareParsers.php (modified) (history)
  • /trunk/phase3/maintenance/convertLinks.php (modified) (history)
  • /trunk/phase3/maintenance/convertUserOptions.php (modified) (history)
  • /trunk/phase3/maintenance/createAndPromote.php (modified) (history)
  • /trunk/phase3/maintenance/deleteArchivedFiles.php (modified) (history)
  • /trunk/phase3/maintenance/deleteArchivedRevisions.php (modified) (history)
  • /trunk/phase3/maintenance/deleteBatch.php (modified) (history)
  • /trunk/phase3/maintenance/deleteDefaultMessages.php (modified) (history)
  • /trunk/phase3/maintenance/deleteImageMemcached.php (modified) (history)
  • /trunk/phase3/maintenance/deleteOldRevisions.php (modified) (history)
  • /trunk/phase3/maintenance/deleteOrphanedRevisions.php (modified) (history)
  • /trunk/phase3/maintenance/deleteRevision.php (modified) (history)
  • /trunk/phase3/maintenance/deleteSelfExternals.php (modified) (history)
  • /trunk/phase3/maintenance/doMaintenance.php (modified) (history)
  • /trunk/phase3/maintenance/dumpInterwiki.php (modified) (history)
  • /trunk/phase3/maintenance/dumpLinks.php (modified) (history)
  • /trunk/phase3/maintenance/dumpSisterSites.php (modified) (history)
  • /trunk/phase3/maintenance/dumpUploads.php (modified) (history)
  • /trunk/phase3/maintenance/edit.php (modified) (history)
  • /trunk/phase3/maintenance/fetchText.php (modified) (history)
  • /trunk/phase3/maintenance/findhooks.php (modified) (history)
  • /trunk/phase3/maintenance/fixSlaveDesync.php (modified) (history)
  • /trunk/phase3/maintenance/fixTimestamps.php (modified) (history)
  • /trunk/phase3/maintenance/fixUserRegistration.php (modified) (history)
  • /trunk/phase3/maintenance/generateSitemap.php (modified) (history)
  • /trunk/phase3/maintenance/getLagTimes.php (modified) (history)
  • /trunk/phase3/maintenance/getSlaveServer.php (modified) (history)
  • /trunk/phase3/maintenance/getText.php (modified) (history)
  • /trunk/phase3/maintenance/httpSessionDownload.php (modified) (history)
  • /trunk/phase3/maintenance/importUseModWikipedia.php (modified) (history)
  • /trunk/phase3/maintenance/initEditCount.php (modified) (history)
  • /trunk/phase3/maintenance/initStats.php (modified) (history)
  • /trunk/phase3/maintenance/install.php (modified) (history)
  • /trunk/phase3/maintenance/lag.php (modified) (history)
  • /trunk/phase3/maintenance/language/alltrans.php (modified) (history)
  • /trunk/phase3/maintenance/language/countMessages.php (modified) (history)
  • /trunk/phase3/maintenance/language/date-formats.php (modified) (history)
  • /trunk/phase3/maintenance/language/digit2html.php (modified) (history)
  • /trunk/phase3/maintenance/language/dumpMessages.php (modified) (history)
  • /trunk/phase3/maintenance/language/generateNormalizerData.php (modified) (history)
  • /trunk/phase3/maintenance/language/lang2po.php (modified) (history)
  • /trunk/phase3/maintenance/language/langmemusage.php (modified) (history)
  • /trunk/phase3/maintenance/mctest.php (modified) (history)
  • /trunk/phase3/maintenance/mergeMessageFileList.php (modified) (history)
  • /trunk/phase3/maintenance/migrateUserGroup.php (modified) (history)
  • /trunk/phase3/maintenance/minify.php (modified) (history)
  • /trunk/phase3/maintenance/moveBatch.php (modified) (history)
  • /trunk/phase3/maintenance/namespaceDupes.php (modified) (history)
  • /trunk/phase3/maintenance/nextJobDB.php (modified) (history)
  • /trunk/phase3/maintenance/nukeNS.php (modified) (history)
  • /trunk/phase3/maintenance/nukePage.php (modified) (history)
  • /trunk/phase3/maintenance/orphans.php (modified) (history)
  • /trunk/phase3/maintenance/patchSql.php (modified) (history)
  • /trunk/phase3/maintenance/populateCategory.php (modified) (history)
  • /trunk/phase3/maintenance/populateLogSearch.php (modified) (history)
  • /trunk/phase3/maintenance/populateLogUsertext.php (modified) (history)
  • /trunk/phase3/maintenance/populateParentId.php (modified) (history)
  • /trunk/phase3/maintenance/populateRevisionLength.php (modified) (history)
  • /trunk/phase3/maintenance/populateSha1.php (modified) (history)
  • /trunk/phase3/maintenance/protect.php (modified) (history)
  • /trunk/phase3/maintenance/purgeList.php (modified) (history)
  • /trunk/phase3/maintenance/purgeOldText.php (modified) (history)
  • /trunk/phase3/maintenance/reassignEdits.php (modified) (history)
  • /trunk/phase3/maintenance/rebuildFileCache.php (modified) (history)
  • /trunk/phase3/maintenance/rebuildImages.php (modified) (history)
  • /trunk/phase3/maintenance/rebuildInterwiki.php (modified) (history)
  • /trunk/phase3/maintenance/rebuildLocalisationCache.php (modified) (history)
  • /trunk/phase3/maintenance/rebuildall.php (modified) (history)
  • /trunk/phase3/maintenance/rebuildmessages.php (modified) (history)
  • /trunk/phase3/maintenance/rebuildrecentchanges.php (modified) (history)
  • /trunk/phase3/maintenance/rebuildtextindex.php (modified) (history)
  • /trunk/phase3/maintenance/refreshImageCount.php (modified) (history)
  • /trunk/phase3/maintenance/refreshLinks.php (modified) (history)
  • /trunk/phase3/maintenance/removeUnusedAccounts.php (modified) (history)
  • /trunk/phase3/maintenance/renameDbPrefix.php (modified) (history)
  • /trunk/phase3/maintenance/renamewiki.php (modified) (history)
  • /trunk/phase3/maintenance/renderDump.php (modified) (history)
  • /trunk/phase3/maintenance/rollbackEdits.php (modified) (history)
  • /trunk/phase3/maintenance/runBatchedQuery.php (modified) (history)
  • /trunk/phase3/maintenance/runJobs.php (modified) (history)
  • /trunk/phase3/maintenance/showJobs.php (modified) (history)
  • /trunk/phase3/maintenance/showStats.php (modified) (history)
  • /trunk/phase3/maintenance/sql.php (modified) (history)
  • /trunk/phase3/maintenance/sqlite.php (modified) (history)
  • /trunk/phase3/maintenance/stats.php (modified) (history)
  • /trunk/phase3/maintenance/storage/dumpRev.php (modified) (history)
  • /trunk/phase3/maintenance/storage/fixBug20757.php (modified) (history)
  • /trunk/phase3/maintenance/storage/orphanStats.php (modified) (history)
  • /trunk/phase3/maintenance/storage/storageTypeStats.php (modified) (history)
  • /trunk/phase3/maintenance/undelete.php (modified) (history)
  • /trunk/phase3/maintenance/update.php (modified) (history)
  • /trunk/phase3/maintenance/updateArticleCount.php (modified) (history)
  • /trunk/phase3/maintenance/updateCollation.php (modified) (history)
  • /trunk/phase3/maintenance/updateDoubleWidthSearch.php (modified) (history)
  • /trunk/phase3/maintenance/updateRestrictions.php (modified) (history)
  • /trunk/phase3/maintenance/updateSearchIndex.php (modified) (history)
  • /trunk/phase3/maintenance/updateSpecialPages.php (modified) (history)
  • /trunk/phase3/maintenance/upgrade1_5.php (modified) (history)
  • /trunk/phase3/maintenance/waitForSlave.php (modified) (history)
  • /trunk/phase3/tests/RunSeleniumTests.php (modified) (history)

Follow-up revisions

RevisionCommit summaryAuthorDate
r80231Followup r80205: scripts using commandLine.inc were failing the shouldExecute...demon02:13, 14 January 2011
r80272use require( RUN_MAINTENANCE_IF_MAIN ) as per r80205...hashar15:08, 14 January 2011
r80468Follow up r80205 define rename in check-vars and files added in r80443 and r8...platonides21:42, 17 January 2011
r805501.17: MFT r80106, r80137, r80138, r80205, r80210, r80222, r80223, r80231, r80...catrope02:09, 19 January 2011
r82579Follow up r80205 magic, so that you can also use require.platonides22:36, 21 February 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r74108Be sure that MW_NO_SETUP is defined before executing updates, this is not alw...ialex20:56, 1 October 2010

Comments

#Comment by 😂 (talk | contribs)   23:01, 13 January 2011

Most of these files were just a batch rename DO_MAINTENANCE. The real changes were in doMaintenance.php, Maintenance.php and DatabaseUpdater.php

#Comment by Catrope (talk | contribs)   23:15, 18 January 2011
		$bt = debug_backtrace();
+		if( count( $bt ) !== 2 ) {
+			return false;
+		}
+		return $bt[1]['function'] == 'require_once' &&
+			$bt[0]['class'] == 'Maintenance' &&
+			$bt[0]['function'] == 'shouldExecute';
+	}

Just counting the backtrace depth should give you enough information, right? This way only require_once triggers the check, but things like require, include and include_once don't.

OK otherwise, marking as OK because no one in MW uses anything else than require_once anyway.

#Comment by 😂 (talk | contribs)   23:30, 18 January 2011

Yeah, I was probably overthinking it.

Status & tagging log