28require_once __DIR__ .
'/Maintenance.php';
42 parent::__construct();
52 return $dbw->
selectRowCount(
'archive',
'*', [], __METHOD__ ) === 0 &&
61 $this->
output(
"Populating ar_rev_id...\n" );
66 $any = $dbw->selectField(
69 [
'ar_rev_id' =>
null ],
73 $this->
output(
"Completed ar_rev_id population, 0 rows updated.\n" );
77 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
80 $lbFactory->waitForReplication();
82 $arIds = $dbw->selectFieldValues(
85 [
'ar_rev_id' =>
null ],
87 [
'LIMIT' => $this->
getBatchSize(),
'ORDER BY' => [
'ar_id' ] ]
90 $this->
output(
"Completed ar_rev_id population, $count rows updated.\n" );
98 $this->
output(
" ... $min-$max\n" );
113 if ( $dbw->
getType() !==
'mysql' ) {
117 if ( !self::$dummyRev ) {
125 $dbw->
insert(
'revision', self::$dummyRev, $fname );
130 (
int)$dbw->
selectField(
'archive',
'MAX(ar_rev_id)', [], $fname ),
131 (
int)$dbw->
selectField(
'slots',
'MAX(slot_revision_id)', [], $fname )
133 if ( $id <= $maxId ) {
134 $dbw->
insert(
'revision', [
'rev_id' => $maxId + 1 ] + self::$dummyRev, $fname );
135 $toDelete[] = $maxId + 1;
138 $dbw->
delete(
'revision', [
'rev_id' => $toDelete ], $fname );
142 if ( $e->errno != 1062 ) {
158 if ( !self::$dummyRev ) {
164 $dbw->
insert(
'revision', array_fill( 0, count( $arIds ), self::$dummyRev ), $fname );
169 [
'rev_timestamp' => self::$dummyRev[
'rev_timestamp'] ],
172 if ( !is_array( $revIds ) ) {
173 throw new UnexpectedValueException(
'Failed to insert dummy revisions' );
175 if ( count( $revIds ) !== count( $arIds ) ) {
176 throw new UnexpectedValueException(
177 'Tried to insert ' . count( $arIds ) .
' dummy revisions, but found '
178 . count( $revIds ) .
' matching rows.'
181 $dbw->
delete(
'revision', [
'rev_id' => $revIds ], $fname );
183 return array_combine( $arIds, $revIds );
187 foreach ( $updates as $arId => $revId ) {
190 [
'ar_rev_id' => $revId ],
191 [
'ar_id' => $arId ] + $conds,
210 $ts = $dbw->
timestamp(
'11111111111111' );
213 $mainPage = Title::newMainPage();
214 $pageId = $mainPage ? $mainPage->getArticleID() :
null;
219 [
'rev_page' => $pageId ],
221 [
'ORDER BY' =>
'rev_timestamp ASC' ]
232 [
'ORDER BY' =>
'rev_timestamp ASC' ]
238 wfDebug( __METHOD__ .
": No revisions are available to copy" );
240 $dbw->
begin( __METHOD__ );
243 $title = Title::newFromText(
"PopulateArchiveRevId_4b05b46a81e29" );
244 $page = WikiPage::factory(
$title );
245 $updater = $page->newPageUpdater(
248 $updater->setContent(
250 ContentHandler::makeContent(
"Content for dummy rev",
$title )
252 $updater->saveRevision(
253 CommentStoreComment::newUnsavedComment(
'dummy rev summary' ),
263 [
'ORDER BY' =>
'rev_timestamp ASC' ]
270 throw new UnexpectedValueException(
271 'No revisions are available to copy, and one couldn\'t be created'
275 unset( $rev->rev_id );
277 $rev[
'rev_timestamp'] = $ts;
278 if ( isset( $rev[
'rev_user'] ) ) {
279 $rev[
'rev_user'] = 0;
280 $rev[
'rev_user_text'] =
'0.0.0.0';
282 if ( isset( $rev[
'rev_comment'] ) ) {
283 $rev[
'rev_comment'] =
'Dummy row';
289 [
'rev_timestamp' => $ts ],
293 throw new UnexpectedValueException(
"... Why does your database contain a revision dated $ts?" );
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
const RUN_MAINTENANCE_IF_MAIN
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.
setBatchSize( $s=0)
Set the batch size.
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.