- foreach ( $updates as $arId => $revId ) {
- $dbw->update(
- 'archive',
- [ 'ar_rev_id' => $revId ],
- [ 'ar_id' => $arId, 'ar_rev_id' => null ],
- __METHOD__
+ /**
+ * Assign new ar_rev_ids to a set of ar_ids.
+ * @param IDatabase $dbw
+ * @param int[] $arIds
+ * @param array $conds Extra conditions for the update
+ * @return int Number of updated rows
+ */
+ public static function reassignArRevIds( IDatabase $dbw, array $arIds, array $conds = [] ) {
+ if ( !self::$dummyRev ) {
+ self::$dummyRev = self::makeDummyRevisionRow( $dbw );
+ }
+
+ $updates = $dbw->doAtomicSection( __METHOD__, function ( $dbw, $fname ) use ( $arIds ) {
+ // Create new rev_ids by inserting dummy rows into revision and then deleting them.
+ $dbw->insert( 'revision', array_fill( 0, count( $arIds ), self::$dummyRev ), $fname );
+ $revIds = $dbw->selectFieldValues(
+ 'revision',
+ 'rev_id',
+ [ 'rev_timestamp' => self::$dummyRev['rev_timestamp'] ],
+ $fname
+ );
+ if ( !is_array( $revIds ) ) {
+ throw new UnexpectedValueException( 'Failed to insert dummy revisions' );
+ }
+ if ( count( $revIds ) !== count( $arIds ) ) {
+ throw new UnexpectedValueException(
+ 'Tried to insert ' . count( $arIds ) . ' dummy revisions, but found '
+ . count( $revIds ) . ' matching rows.'