Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 108 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
FlowUpdateRecentChanges | |
0.00% |
0 / 102 |
|
0.00% |
0 / 4 |
870 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
doDBUpdates | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
refreshBatch | |
0.00% |
0 / 92 |
|
0.00% |
0 / 1 |
650 | |||
getUpdateKey | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Flow\Maintenance; |
4 | |
5 | use Flow\Data\Listener\RecentChangesListener; |
6 | use LoggedUpdateMaintenance; |
7 | use Wikimedia\AtEase\AtEase; |
8 | use Wikimedia\Rdbms\IDatabase; |
9 | |
10 | $IP = getenv( 'MW_INSTALL_PATH' ); |
11 | if ( $IP === false ) { |
12 | $IP = __DIR__ . '/../../..'; |
13 | } |
14 | |
15 | require_once "$IP/maintenance/Maintenance.php"; |
16 | |
17 | /** |
18 | * Updates recentchanges entries to contain information to build the |
19 | * AbstractBlock objects. |
20 | * |
21 | * @ingroup Maintenance |
22 | */ |
23 | class FlowUpdateRecentChanges extends LoggedUpdateMaintenance { |
24 | /** |
25 | * The number of entries completed |
26 | * |
27 | * @var int |
28 | */ |
29 | private $completeCount = 0; |
30 | |
31 | public function __construct() { |
32 | parent::__construct(); |
33 | |
34 | $this->setBatchSize( 300 ); |
35 | $this->requireExtension( 'Flow' ); |
36 | } |
37 | |
38 | protected function doDBUpdates() { |
39 | $dbw = $this->getPrimaryDB(); |
40 | |
41 | $continue = 0; |
42 | |
43 | while ( $continue !== null ) { |
44 | $continue = $this->refreshBatch( $dbw, $continue ); |
45 | $this->waitForReplication(); |
46 | } |
47 | |
48 | return true; |
49 | } |
50 | |
51 | /** |
52 | * Refreshes a batch of recentchanges entries |
53 | * |
54 | * @param IDatabase $dbw |
55 | * @param int|null $continue The next batch starting at rc_id |
56 | * @return int|null Start id for the next batch |
57 | */ |
58 | public function refreshBatch( IDatabase $dbw, $continue = null ) { |
59 | $rows = $dbw->newSelectQueryBuilder() |
60 | ->select( [ 'rc_id', 'rc_params' ] ) |
61 | ->from( 'recentchanges' ) |
62 | ->where( [ |
63 | $dbw->expr( 'rc_id', '>', $continue ), |
64 | 'rc_source' => RecentChangesListener::SRC_FLOW |
65 | ] ) |
66 | ->limit( $this->getBatchSize() ) |
67 | ->orderBy( 'rc_id' ) |
68 | ->caller( __METHOD__ ) |
69 | ->fetchResultSet(); |
70 | |
71 | $continue = null; |
72 | |
73 | foreach ( $rows as $row ) { |
74 | $continue = $row->rc_id; |
75 | |
76 | // build params |
77 | AtEase::suppressWarnings(); |
78 | $params = unserialize( $row->rc_params ); |
79 | AtEase::restoreWarnings(); |
80 | if ( !$params ) { |
81 | $params = []; |
82 | } |
83 | |
84 | // Don't fix entries that have been dealt with already |
85 | if ( !isset( $params['flow-workflow-change']['type'] ) ) { |
86 | continue; |
87 | } |
88 | |
89 | // Set action, based on older 'type' values |
90 | switch ( $params['flow-workflow-change']['type'] ) { |
91 | case 'flow-rev-message-edit-title': |
92 | case 'flow-edit-title': |
93 | $params['flow-workflow-change']['action'] = 'edit-title'; |
94 | $params['flow-workflow-change']['block'] = 'topic'; |
95 | $params['flow-workflow-change']['revision_type'] = 'PostRevision'; |
96 | break; |
97 | |
98 | case 'flow-rev-message-new-post': |
99 | case 'flow-new-post': |
100 | $params['flow-workflow-change']['action'] = 'new-post'; |
101 | $params['flow-workflow-change']['block'] = 'topic'; |
102 | $params['flow-workflow-change']['revision_type'] = 'PostRevision'; |
103 | break; |
104 | |
105 | case 'flow-rev-message-edit-post': |
106 | case 'flow-edit-post': |
107 | $params['flow-workflow-change']['action'] = 'edit-post'; |
108 | $params['flow-workflow-change']['block'] = 'topic'; |
109 | $params['flow-workflow-change']['revision_type'] = 'PostRevision'; |
110 | break; |
111 | |
112 | case 'flow-rev-message-reply': |
113 | case 'flow-reply': |
114 | $params['flow-workflow-change']['action'] = 'reply'; |
115 | $params['flow-workflow-change']['block'] = 'topic'; |
116 | $params['flow-workflow-change']['revision_type'] = 'PostRevision'; |
117 | break; |
118 | |
119 | case 'flow-rev-message-restored-post': |
120 | case 'flow-post-restored': |
121 | $params['flow-workflow-change']['action'] = 'restore-post'; |
122 | $params['flow-workflow-change']['block'] = 'topic'; |
123 | $params['flow-workflow-change']['revision_type'] = 'PostRevision'; |
124 | break; |
125 | |
126 | case 'flow-rev-message-hid-post': |
127 | case 'flow-post-hidden': |
128 | $params['flow-workflow-change']['action'] = 'hide-post'; |
129 | $params['flow-workflow-change']['block'] = 'topic'; |
130 | $params['flow-workflow-change']['revision_type'] = 'PostRevision'; |
131 | break; |
132 | |
133 | case 'flow-rev-message-deleted-post': |
134 | case 'flow-post-deleted': |
135 | $params['flow-workflow-change']['action'] = 'delete-post'; |
136 | $params['flow-workflow-change']['block'] = 'topic'; |
137 | $params['flow-workflow-change']['revision_type'] = 'PostRevision'; |
138 | break; |
139 | |
140 | case 'flow-rev-message-censored-post': |
141 | case 'flow-post-censored': |
142 | $params['flow-workflow-change']['action'] = 'suppress-post'; |
143 | $params['flow-workflow-change']['block'] = 'topic'; |
144 | $params['flow-workflow-change']['revision_type'] = 'PostRevision'; |
145 | break; |
146 | |
147 | case 'flow-rev-message-edit-header': |
148 | case 'flow-edit-summary': |
149 | $params['flow-workflow-change']['action'] = 'edit-header'; |
150 | $params['flow-workflow-change']['block'] = 'header'; |
151 | $params['flow-workflow-change']['revision_type'] = 'Header'; |
152 | break; |
153 | |
154 | case 'flow-rev-message-create-header': |
155 | case 'flow-create-summary': |
156 | case 'flow-create-header': |
157 | $params['flow-workflow-change']['action'] = 'create-header'; |
158 | $params['flow-workflow-change']['block'] = 'header'; |
159 | $params['flow-workflow-change']['revision_type'] = 'Header'; |
160 | break; |
161 | } |
162 | |
163 | unset( $params['flow-workflow-change']['type'] ); |
164 | |
165 | // update log entry |
166 | $dbw->newUpdateQueryBuilder() |
167 | ->update( 'recentchanges' ) |
168 | ->set( [ 'rc_params' => serialize( $params ) ] ) |
169 | ->where( [ 'rc_id' => $row->rc_id ] ) |
170 | ->caller( __METHOD__ ) |
171 | ->execute(); |
172 | |
173 | $this->completeCount++; |
174 | } |
175 | |
176 | return $continue; |
177 | } |
178 | |
179 | /** |
180 | * Get the update key name to go in the update log table |
181 | * |
182 | * @return string |
183 | */ |
184 | protected function getUpdateKey() { |
185 | return 'FlowUpdateRecentChanges'; |
186 | } |
187 | } |
188 | |
189 | $maintClass = FlowUpdateRecentChanges::class; |
190 | require_once RUN_MAINTENANCE_IF_MAIN; |