Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 42
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
FlowUpdateRevContentModelFromOccupyPages
0.00% covered (danger)
0.00%
0 / 36
0.00% covered (danger)
0.00%
0 / 2
42
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
 execute
0.00% covered (danger)
0.00%
0 / 32
0.00% covered (danger)
0.00%
0 / 1
30
1<?php
2
3namespace Flow\Maintenance;
4
5use IDBAccessObject;
6use Maintenance;
7use MediaWiki\Title\Title;
8
9$IP = getenv( 'MW_INSTALL_PATH' );
10if ( $IP === false ) {
11    $IP = __DIR__ . '/../../..';
12}
13
14require_once "$IP/maintenance/Maintenance.php";
15
16/**
17 * This script should be run immediately before dropping the wgFlowOccupyPages
18 * configuration variable, to ensure that rev_content_model is set appropriately.
19 *
20 * See comments at https://gerrit.wikimedia.org/r/#/c/228267/ .
21 *
22 * It sets rev_content_model to flow-board for the last revision of all occupied pages.
23 *
24 * @ingroup Maintenance
25 */
26class FlowUpdateRevContentModelFromOccupyPages extends Maintenance {
27    public function __construct() {
28        parent::__construct();
29
30        $this->addDescription( 'Sets rev_content_model from wgFlowOccupyPages, in preparation for dropping that config variable.' );
31
32        $this->requireExtension( 'Flow' );
33
34        // Given the number of occupied pages, this probably doesn't need to be
35        // batched; just being cautious.
36        $this->setBatchSize( 10 );
37    }
38
39    public function execute() {
40        global $wgFlowOccupyPages;
41
42        $dbw = $this->getPrimaryDB();
43
44        $pageCount = count( $wgFlowOccupyPages );
45        $overallInd = 0;
46        $updatedCount = 0;
47        $skippedCount = 0;
48        $batchSize = $this->getBatchSize();
49
50        while ( $overallInd < $pageCount ) {
51            $this->beginTransaction( $dbw, __METHOD__ );
52            $batchInd = 0;
53            while ( $overallInd < $pageCount && $batchInd < $batchSize ) {
54                $pageName = $wgFlowOccupyPages[$overallInd];
55                $title = Title::newFromTextThrow( $pageName );
56                $revId = $title->getLatestRevID( IDBAccessObject::READ_LATEST );
57                if ( $revId !== 0 ) {
58                    $dbw->newUpdateQueryBuilder()
59                        ->update( 'revision' )
60                        ->set( [
61                            'rev_content_model' => CONTENT_MODEL_FLOW_BOARD
62                        ] )
63                        ->where( [ 'rev_id' => $revId ] )
64                        ->caller( __METHOD__ )
65                        ->execute();
66                    $updatedCount++;
67                    $this->output( "Set content model for \"{$title->getPrefixedDBkey()}\"\n" );
68                } else {
69                    $skippedCount++;
70                    $this->output( "WARNING: Skipped \"{$title->getPrefixedDBkey()}\" because it does not exist\n" );
71                }
72
73                $overallInd++;
74                $batchInd++;
75            }
76
77            $this->commitTransaction( $dbw, __METHOD__ );
78            $this->output( "Completed batch.\n\n" );
79        }
80
81        $this->output( "Set content model for $updatedCount pages; skipped $skippedCount pages.\n" );
82    }
83}
84
85$maintClass = FlowUpdateRevContentModelFromOccupyPages::class;
86require_once RUN_MAINTENANCE_IF_MAIN;