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