Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 33
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
FlowPopulateRefId
0.00% covered (danger)
0.00%
0 / 27
0.00% covered (danger)
0.00%
0 / 4
56
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 getUpdateKey
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 doDBUpdates
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
6
 update
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2
3namespace Flow\Maintenance;
4
5use Flow\Container;
6use Flow\Data\ObjectManager;
7use Flow\Exception\InvalidInputException;
8use LoggedUpdateMaintenance;
9use MediaWiki\WikiMap\WikiMap;
10
11$IP = getenv( 'MW_INSTALL_PATH' );
12if ( $IP === false ) {
13    $IP = __DIR__ . '/../../..';
14}
15
16require_once "$IP/maintenance/Maintenance.php";
17
18/**
19 * Populates ref_id in flow_wiki_ref & flow_ext_ref.
20 *
21 * @ingroup Maintenance
22 */
23class FlowPopulateRefId extends LoggedUpdateMaintenance {
24    public function __construct() {
25        parent::__construct();
26
27        $this->addDescription( 'Populates ref_id in flow_wiki_ref & flow_ext_ref' );
28
29        $this->setBatchSize( 300 );
30
31        $this->requireExtension( 'Flow' );
32    }
33
34    protected function getUpdateKey() {
35        return 'FlowPopulateRefId';
36    }
37
38    protected function doDBUpdates() {
39        $types = [
40            'flow_wiki_ref' => Container::get( 'storage.wiki_reference' ),
41            'flow_ext_ref' => Container::get( 'storage.url_reference' ),
42        ];
43
44        foreach ( $types as $table => $storage ) {
45            $this->update( $storage );
46        }
47
48        $this->output( "Completed\n" );
49
50        return true;
51    }
52
53    /**
54     * @param ObjectManager $storage
55     * @throws InvalidInputException
56     */
57    protected function update( ObjectManager $storage ) {
58        global $wgFlowCluster;
59
60        $total = 0;
61
62        $lbFactory = $this->getServiceContainer()->getDBLoadBalancerFactory();
63
64        while ( true ) {
65            $references = (array)$storage->find(
66                [ 'ref_id' => null, 'ref_src_wiki' => WikiMap::getCurrentWikiId() ],
67                [ 'limit' => $this->getBatchSize() ]
68            );
69            if ( !$references ) {
70                break;
71            }
72
73            $storage->multiPut( $references, [] );
74            $total += count( $references );
75            $this->output( "Ensured ref_id for " . $total . " " . get_class( $references[0] ) . " references...\n" );
76            $lbFactory->waitForReplication( [ 'cluster' => $wgFlowCluster ] );
77        }
78    }
79}
80
81$maintClass = FlowPopulateRefId::class;
82require_once RUN_MAINTENANCE_IF_MAIN;