From: James Montalvo Date: Mon, 10 Sep 2018 19:45:37 +0000 (-0500) Subject: Handle empty revision table in populateArchiveRevId.php X-Git-Tag: 1.34.0-rc.0~3968^2 X-Git-Url: http://git.cyclocoop.org/%22.%24h.%22?a=commitdiff_plain;h=e49ea91fad5197e16cfc0eb78bf8e4e116fbc906;p=lhc%2Fweb%2Fwiklou.git 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 --- diff --git a/maintenance/populateArchiveRevId.php b/maintenance/populateArchiveRevId.php index 60f5e8a126..c03eb24853 100644 --- a/maintenance/populateArchiveRevId.php +++ b/maintenance/populateArchiveRevId.php @@ -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 );