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:
parent
b2b516c9f7
commit
e49ea91fad
1 changed files with 37 additions and 1 deletions
|
|
@ -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 );
|
||||
|
|
|
|||
Loading…
Reference in a new issue