29require_once __DIR__ .
'/Maintenance.php';
43 parent::__construct();
53 return $dbw->
selectRowCount(
'archive',
'*', [], __METHOD__ ) === 0 &&
62 $this->
output(
"Populating ar_rev_id...\n" );
67 $any = $dbw->selectField(
70 [
'ar_rev_id' =>
null ],
74 $this->
output(
"Completed ar_rev_id population, 0 rows updated.\n" );
78 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
81 $lbFactory->waitForReplication();
83 $arIds = $dbw->selectFieldValues(
86 [
'ar_rev_id' =>
null ],
88 [
'LIMIT' => $this->
getBatchSize(),
'ORDER BY' => [
'ar_id' ] ]
91 $this->
output(
"Completed ar_rev_id population, $count rows updated.\n" );
99 $this->
output(
" ... $min-$max\n" );
114 if ( $dbw->
getType() !==
'mysql' ) {
118 if ( !self::$dummyRev ) {
126 $dbw->
insert(
'revision', self::$dummyRev, $fname );
131 (
int)$dbw->
selectField(
'archive',
'MAX(ar_rev_id)', [], $fname ),
132 (
int)$dbw->
selectField(
'slots',
'MAX(slot_revision_id)', [], $fname )
134 if ( $id <= $maxId ) {
135 $dbw->
insert(
'revision', [
'rev_id' => $maxId + 1 ] + self::$dummyRev, $fname );
136 $toDelete[] = $maxId + 1;
139 $dbw->
delete(
'revision', [
'rev_id' => $toDelete ], $fname );
143 if ( $e->errno != 1062 ) {
159 if ( !self::$dummyRev ) {
165 $dbw->
insert(
'revision', array_fill( 0, count( $arIds ), self::$dummyRev ), $fname );
170 [
'rev_timestamp' => self::$dummyRev[
'rev_timestamp'] ],
173 if ( count( $revIds ) !== count( $arIds ) ) {
174 throw new UnexpectedValueException(
175 'Tried to insert ' . count( $arIds ) .
' dummy revisions, but found '
176 . count( $revIds ) .
' matching rows.'
179 $dbw->
delete(
'revision', [
'rev_id' => $revIds ], $fname );
181 return array_combine( $arIds, $revIds );
185 foreach ( $updates as $arId => $revId ) {
188 [
'ar_rev_id' => $revId ],
189 [
'ar_id' => $arId ] + $conds,
208 $ts = $dbw->
timestamp(
'11111111111111' );
211 $mainPage = Title::newMainPage();
212 $pageId = $mainPage ? $mainPage->getArticleID() :
null;
217 [
'rev_page' => $pageId ],
219 [
'ORDER BY' =>
'rev_timestamp ASC' ]
230 [
'ORDER BY' =>
'rev_timestamp ASC' ]
236 wfDebug( __METHOD__ .
": No revisions are available to copy" );
238 $dbw->
begin( __METHOD__ );
241 $title = Title::newFromText(
"PopulateArchiveRevId_4b05b46a81e29" );
242 $page = MediaWikiServices::getInstance()->getWikiPageFactory()->newFromTitle(
$title );
243 $page->newPageUpdater(
248 ContentHandler::makeContent(
"Content for dummy rev",
$title )
251 CommentStoreComment::newUnsavedComment(
'dummy rev summary' ),
261 [
'ORDER BY' =>
'rev_timestamp ASC' ]
268 throw new UnexpectedValueException(
269 'No revisions are available to copy, and one couldn\'t be created'
273 unset( $rev->rev_id );
275 $rev[
'rev_timestamp'] = $ts;
276 if ( isset( $rev[
'rev_user'] ) ) {
277 $rev[
'rev_user'] = 0;
278 $rev[
'rev_user_text'] =
'0.0.0.0';
280 if ( isset( $rev[
'rev_comment'] ) ) {
281 $rev[
'rev_comment'] =
'Dummy row';
287 [
'rev_timestamp' => $ts ],
291 throw new UnexpectedValueException(
"... Why does your database contain a revision dated $ts?" );
299require_once RUN_MAINTENANCE_IF_MAIN;
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
output( $out, $channel=null)
Throw some output to the user.
getBatchSize()
Returns batch size.
addDescription( $text)
Set the description text.
Maintenance script that populares archive.ar_rev_id in old rows.
doDBUpdates()
Do the actual work.
getUpdateKey()
Get the update key name to go in the update log table.
static array null $dummyRev
Dummy revision row.
static checkMysqlAutoIncrementBug(IDatabase $dbw)
Check for (and work around) a MySQL auto-increment bug.
static reassignArRevIds(IDatabase $dbw, array $arIds, array $conds=[])
Assign new ar_rev_ids to a set of ar_ids.
static makeDummyRevisionRow(IDatabase $dbw)
Construct a dummy revision table row to use for reserving IDs.
static isNewInstall(IDatabase $dbw)
__construct()
Default constructor.
static newSystemUser( $name, $options=[])
Static factory method for creation of a "system" user from username.
const MAINTENANCE_SCRIPT_USER
Username used for various maintenance scripts.