Handle empty revision table in populateArchiveRevId.php

Running update.php for new wikis without any revisions yet fails when
update.php attempts to run populateArchiveRevId.php. This problem
does not exist if using the web installer or running
maintenance/install.php, since both of these generate a Main Page
revision. Manually generating a MediaWiki database by sourcing
maintenance/tables.sql does not generate any revisions, and thus is
susceptible to this problem.

Bug: T203982

Change-Id: Ifd78c50fb1e11f82340cd83a10fa903b7c5fc1e7
This commit is contained in:
James Montalvo 2018-09-10 14:45:37 -05:00 committed by James D. Forrester
parent b2b516c9f7
commit e49ea91fad

View file

@ -220,7 +220,43 @@ class PopulateArchiveRevId extends LoggedUpdateMaintenance {
);
}
if ( !$rev ) {
throw new UnexpectedValueException( 'No revisions are available to copy' );
// Since no revisions are available to copy, generate a dummy
// revision to a dummy page, then rollback the commit
wfDebug( __METHOD__ . ": No revisions are available to copy\n" );
$dbw->begin();
// Make a title and revision and insert them
$title = Title::newFromText( "PopulateArchiveRevId_4b05b46a81e29" );
$page = WikiPage::factory( $title );
$updater = $page->newPageUpdater(
User::newSystemUser( 'Maintenance script', [ 'steal' => true ] )
);
$updater->setContent(
'main',
ContentHandler::makeContent( "Content for dummy rev", $title )
);
$updater->saveRevision(
CommentStoreComment::newUnsavedComment( 'dummy rev summary' ),
EDIT_NEW | EDIT_SUPPRESS_RC
);
// get the revision row just inserted
$rev = $dbw->selectRow(
'revision',
'*',
[],
__METHOD__,
[ 'ORDER BY' => 'rev_timestamp ASC' ]
);
$dbw->rollback();
}
if ( !$rev ) {
// This should never happen.
throw new UnexpectedValueException(
'No revisions are available to copy, and one couldn\'t be created'
);
}
unset( $rev->rev_id );