Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 65 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
MigrateRevisionActorTemp | |
0.00% |
0 / 65 |
|
0.00% |
0 / 3 |
156 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
2 | |||
getUpdateKey | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
doDBUpdates | |
0.00% |
0 / 53 |
|
0.00% |
0 / 1 |
110 |
1 | <?php |
2 | |
3 | use MediaWiki\Maintenance\LoggedUpdateMaintenance; |
4 | |
5 | // @codeCoverageIgnoreStart |
6 | require_once __DIR__ . '/Maintenance.php'; |
7 | // @codeCoverageIgnoreEnd |
8 | |
9 | /** |
10 | * Maintenance script that merges the revision_actor_temp table into the |
11 | * revision table. |
12 | * |
13 | * @ingroup Maintenance |
14 | * @since 1.37 |
15 | */ |
16 | class MigrateRevisionActorTemp extends LoggedUpdateMaintenance { |
17 | public function __construct() { |
18 | parent::__construct(); |
19 | $this->addDescription( |
20 | 'Copy the data from the revision_actor_temp into the revision table' |
21 | ); |
22 | $this->addOption( |
23 | 'sleep', |
24 | 'Sleep time (in seconds) between every batch. Default: 0', |
25 | false, |
26 | true |
27 | ); |
28 | $this->addOption( 'start', 'Start after this rev_id', false, true ); |
29 | } |
30 | |
31 | protected function getUpdateKey() { |
32 | return __CLASS__; |
33 | } |
34 | |
35 | protected function doDBUpdates() { |
36 | $batchSize = $this->getBatchSize(); |
37 | |
38 | $dbw = $this->getDB( DB_PRIMARY ); |
39 | if ( !$dbw->fieldExists( 'revision', 'rev_actor', __METHOD__ ) ) { |
40 | $this->output( "Run update.php to create rev_actor.\n" ); |
41 | return false; |
42 | } |
43 | if ( !$dbw->tableExists( 'revision_actor_temp', __METHOD__ ) ) { |
44 | $this->output( "revision_actor_temp does not exist, so nothing to do.\n" ); |
45 | return true; |
46 | } |
47 | |
48 | $this->output( "Merging the revision_actor_temp table into the revision table...\n" ); |
49 | $conds = []; |
50 | $updated = 0; |
51 | $start = (int)$this->getOption( 'start', 0 ); |
52 | if ( $start > 0 ) { |
53 | $conds[] = $dbw->expr( 'rev_id', '>=', $start ); |
54 | } |
55 | while ( true ) { |
56 | $res = $dbw->newSelectQueryBuilder() |
57 | ->select( [ 'rev_id', 'rev_actor', 'revactor_actor' ] ) |
58 | ->from( 'revision' ) |
59 | ->join( 'revision_actor_temp', null, 'rev_id=revactor_rev' ) |
60 | ->where( $conds ) |
61 | ->limit( $batchSize ) |
62 | ->orderBy( 'rev_id' ) |
63 | ->caller( __METHOD__ ) |
64 | ->fetchResultSet(); |
65 | |
66 | $numRows = $res->numRows(); |
67 | |
68 | $last = null; |
69 | foreach ( $res as $row ) { |
70 | $last = $row->rev_id; |
71 | if ( !$row->rev_actor ) { |
72 | $dbw->newUpdateQueryBuilder() |
73 | ->update( 'revision' ) |
74 | ->set( [ 'rev_actor' => $row->revactor_actor ] ) |
75 | ->where( [ 'rev_id' => $row->rev_id ] ) |
76 | ->caller( __METHOD__ )->execute(); |
77 | $updated += $dbw->affectedRows(); |
78 | } elseif ( $row->rev_actor !== $row->revactor_actor ) { |
79 | $this->error( |
80 | "Revision ID $row->rev_id has rev_actor = $row->rev_actor and " |
81 | . "revactor_actor = $row->revactor_actor. Ignoring the latter." |
82 | ); |
83 | } |
84 | } |
85 | |
86 | if ( $numRows < $batchSize ) { |
87 | // We must have reached the end |
88 | break; |
89 | } |
90 | |
91 | // @phan-suppress-next-line PhanTypeSuspiciousStringExpression last is not-null when used |
92 | $this->output( "... rev_id=$last, updated $updated\n" ); |
93 | $conds = [ $dbw->expr( 'rev_id', '>', $last ) ]; |
94 | |
95 | // Sleep between batches for replication to catch up |
96 | $this->waitForReplication(); |
97 | $sleep = (int)$this->getOption( 'sleep', 0 ); |
98 | if ( $sleep > 0 ) { |
99 | sleep( $sleep ); |
100 | } |
101 | } |
102 | |
103 | $this->output( |
104 | "Completed merge of revision_actor into the revision table, " |
105 | . "$updated rows updated.\n" |
106 | ); |
107 | |
108 | return true; |
109 | } |
110 | |
111 | } |
112 | |
113 | // @codeCoverageIgnoreStart |
114 | $maintClass = MigrateRevisionActorTemp::class; |
115 | require_once RUN_MAINTENANCE_IF_MAIN; |
116 | // @codeCoverageIgnoreEnd |