MediaWiki  master
migrateRevisionActorTemp.php
Go to the documentation of this file.
1 <?php
2 
3 require_once __DIR__ . '/Maintenance.php';
4 
13  public function __construct() {
14  parent::__construct();
15  $this->addDescription(
16  'Copy the data from the revision_actor_temp into the revision table'
17  );
18  }
19 
20  protected function getUpdateKey() {
21  return __CLASS__;
22  }
23 
24  protected function doDBUpdates() {
25  $batchSize = $this->getBatchSize();
26 
27  $dbw = $this->getDB( DB_PRIMARY );
28  if ( !$dbw->fieldExists( 'revision', 'rev_actor', __METHOD__ ) ) {
29  $this->output( "Run update.php to create rev_actor.\n" );
30  return false;
31  }
32  if ( !$dbw->tableExists( 'revision_actor_temp', __METHOD__ ) ) {
33  $this->output( "revision_actor_temp does not exist, so nothing to do.\n" );
34  return true;
35  }
36 
37  $this->output( "Merging the revision_actor_temp table into the revision table...\n" );
38  $conds = [];
39  $updated = 0;
40  while ( true ) {
41  $res = $dbw->newSelectQueryBuilder()
42  ->select( [ 'rev_id', 'rev_actor', 'revactor_actor' ] )
43  ->from( 'revision' )
44  ->join( 'revision_actor_temp', null, 'rev_id=revactor_rev' )
45  ->where( $conds )
46  ->limit( $batchSize )
47  ->orderBy( 'rev_id' )
48  ->caller( __METHOD__ )
49  ->fetchResultSet();
50 
51  $numRows = $res->numRows();
52 
53  $last = null;
54  foreach ( $res as $row ) {
55  $last = $row->rev_id;
56  if ( !$row->rev_actor ) {
57  $dbw->update(
58  'revision',
59  [ 'rev_actor' => $row->revactor_actor ],
60  [ 'rev_id' => $row->rev_id ],
61  __METHOD__
62  );
63  $updated += $dbw->affectedRows();
64  } elseif ( $row->rev_actor !== $row->revactor_actor ) {
65  $this->error(
66  "Revision ID $row->rev_id has rev_actor = $row->rev_actor and "
67  . "revactor_actor = $row->revactor_actor. Ignoring the latter."
68  );
69  }
70  }
71 
72  if ( $numRows < $batchSize ) {
73  // We must have reached the end
74  break;
75  }
76 
77  $this->output( "... rev_id=$last, updated $updated\n" );
78  $conds = [ 'rev_id > ' . $dbw->addQuotes( $last ) ];
79  }
80 
81  $this->output(
82  "Completed merge of revision_actor into the revision table, "
83  . "$updated rows updated.\n"
84  );
85 
86  return true;
87  }
88 
89 }
90 
91 $maintClass = MigrateRevisionActorTemp::class;
92 require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:329
MigrateRevisionActorTemp\doDBUpdates
doDBUpdates()
Do the actual work.
Definition: migrateRevisionActorTemp.php:24
MigrateRevisionActorTemp\getUpdateKey
getUpdateKey()
Get the update key name to go in the update log table.
Definition: migrateRevisionActorTemp.php:20
$res
$res
Definition: testCompression.php:57
$maintClass
$maintClass
Definition: migrateRevisionActorTemp.php:91
LoggedUpdateMaintenance
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
Definition: LoggedUpdateMaintenance.php:26
MigrateRevisionActorTemp
Maintenance script that merges the revision_actor_temp table into the revision table.
Definition: migrateRevisionActorTemp.php:12
MigrateRevisionActorTemp\__construct
__construct()
Default constructor.
Definition: migrateRevisionActorTemp.php:13
DB_PRIMARY
const DB_PRIMARY
Definition: defines.php:27
Maintenance\getDB
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
Definition: Maintenance.php:1362
Maintenance\getBatchSize
getBatchSize()
Returns batch size.
Definition: Maintenance.php:368
Maintenance\error
error( $err, $die=0)
Throw an error to the user.
Definition: Maintenance.php:464
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:435