Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 82 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
FlowPopulateLinksTables | |
0.00% |
0 / 76 |
|
0.00% |
0 / 5 |
132 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
getUpdateKey | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
doDBUpdates | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
processHeaders | |
0.00% |
0 / 34 |
|
0.00% |
0 / 1 |
20 | |||
processPosts | |
0.00% |
0 / 32 |
|
0.00% |
0 / 1 |
20 |
1 | <?php |
2 | |
3 | namespace Flow\Maintenance; |
4 | |
5 | use Flow\Container; |
6 | use Flow\DbFactory; |
7 | use Flow\Model\UUID; |
8 | use MediaWiki\Maintenance\LoggedUpdateMaintenance; |
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 | * Currently iterates through all revisions for debugging purposes, the |
19 | * production version will want to only process the most recent revision |
20 | * of each object. |
21 | * |
22 | * @ingroup Maintenance |
23 | */ |
24 | class FlowPopulateLinksTables extends LoggedUpdateMaintenance { |
25 | public function __construct() { |
26 | parent::__construct(); |
27 | $this->addDescription( "Populates links tables for wikis deployed before change 110090" ); |
28 | $this->setBatchSize( 300 ); |
29 | $this->requireExtension( 'Flow' ); |
30 | } |
31 | |
32 | public function getUpdateKey() { |
33 | return "FlowPopulateLinksTables"; |
34 | } |
35 | |
36 | public function doDBUpdates() { |
37 | $this->output( "Populating links tables...\n" ); |
38 | $recorder = Container::get( 'reference.recorder' ); |
39 | $this->processHeaders( $recorder ); |
40 | $this->processPosts( $recorder ); |
41 | |
42 | return true; |
43 | } |
44 | |
45 | protected function processHeaders( $recorder ) { |
46 | $storage = Container::get( 'storage.header' ); |
47 | $batchSize = $this->getBatchSize(); |
48 | $count = $batchSize; |
49 | $id = ''; |
50 | /** @var DbFactory $dbf */ |
51 | $dbf = Container::get( 'db.factory' ); |
52 | $dbr = $dbf->getDB( DB_REPLICA ); |
53 | while ( $count === $batchSize ) { |
54 | $count = 0; |
55 | $res = $dbr->newSelectQueryBuilder() |
56 | ->select( [ 'rev_type_id' ] ) |
57 | ->from( 'flow_revision' ) |
58 | ->where( [ |
59 | 'rev_type' => 'header', |
60 | $dbr->expr( 'rev_type_id', '>', $id ), |
61 | ] ) |
62 | ->orderBy( 'rev_type_id' ) |
63 | ->limit( $batchSize ) |
64 | ->caller( __METHOD__ ) |
65 | ->fetchResultSet(); |
66 | foreach ( $res as $row ) { |
67 | $count++; |
68 | $id = $row->rev_type_id; |
69 | $uuid = UUID::create( $id ); |
70 | $alpha = $uuid->getAlphadecimal(); |
71 | $header = $storage->get( $uuid ); |
72 | if ( $header ) { |
73 | echo "Processing header $alpha\n"; |
74 | $recorder->onAfterInsert( |
75 | $header, [], |
76 | [ |
77 | 'workflow' => $header->getCollection()->getWorkflow() |
78 | ] |
79 | ); |
80 | } |
81 | } |
82 | $dbf->waitForReplicas(); |
83 | } |
84 | } |
85 | |
86 | protected function processPosts( $recorder ) { |
87 | $storage = Container::get( 'storage.post' ); |
88 | $batchSize = $this->getBatchSize(); |
89 | $count = $batchSize; |
90 | $id = ''; |
91 | $dbr = Container::get( 'db.factory' )->getDB( DB_REPLICA ); |
92 | while ( $count === $batchSize ) { |
93 | $count = 0; |
94 | $res = $dbr->newSelectQueryBuilder() |
95 | ->select( [ 'tree_rev_id' ] ) |
96 | ->from( 'flow_tree_revision' ) |
97 | ->where( [ |
98 | $dbr->expr( 'tree_parent_id', '!=', null ), |
99 | $dbr->expr( 'tree_rev_id', '>', $id ), |
100 | ] ) |
101 | ->caller( __METHOD__ ) |
102 | ->orderBy( 'tree_rev_id' ) |
103 | ->limit( $batchSize ) |
104 | ->fetchResultSet(); |
105 | foreach ( $res as $row ) { |
106 | $count++; |
107 | $id = $row->tree_rev_id; |
108 | $uuid = UUID::create( $id ); |
109 | $alpha = $uuid->getAlphadecimal(); |
110 | $post = $storage->get( $uuid ); |
111 | if ( $post ) { |
112 | echo "Processing post $alpha\n"; |
113 | $recorder->onAfterInsert( |
114 | $post, [], |
115 | [ |
116 | 'workflow' => $post->getCollection()->getWorkflow() |
117 | ] |
118 | ); |
119 | } |
120 | } |
121 | } |
122 | } |
123 | } |
124 | |
125 | $maintClass = FlowPopulateLinksTables::class; |
126 | require_once RUN_MAINTENANCE_IF_MAIN; |