Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 43
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 / 37
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 / 5
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 MediaWiki\Maintenance\Maintenance;
6use MediaWiki\Title\Title;
7use Wikimedia\Rdbms\IDBAccessObject;
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, ' .
31            'in preparation for dropping that config variable.' );
32
33        $this->requireExtension( 'Flow' );
34
35        // Given the number of occupied pages, this probably doesn't need to be
36        // batched; just being cautious.
37        $this->setBatchSize( 10 );
38    }
39
40    public function execute() {
41        global $wgFlowOccupyPages;
42
43        $dbw = $this->getPrimaryDB();
44
45        $pageCount = count( $wgFlowOccupyPages );
46        $overallInd = 0;
47        $updatedCount = 0;
48        $skippedCount = 0;
49        $batchSize = $this->getBatchSize();
50
51        while ( $overallInd < $pageCount ) {
52            $this->beginTransaction( $dbw, __METHOD__ );
53            $batchInd = 0;
54            while ( $overallInd < $pageCount && $batchInd < $batchSize ) {
55                $pageName = $wgFlowOccupyPages[$overallInd];
56                $title = Title::newFromTextThrow( $pageName );
57                $revId = $title->getLatestRevID( IDBAccessObject::READ_LATEST );
58                if ( $revId !== 0 ) {
59                    $dbw->newUpdateQueryBuilder()
60                        ->update( 'revision' )
61                        ->set( [
62                            'rev_content_model' => CONTENT_MODEL_FLOW_BOARD
63                        ] )
64                        ->where( [ 'rev_id' => $revId ] )
65                        ->caller( __METHOD__ )
66                        ->execute();
67                    $updatedCount++;
68                    $this->output( "Set content model for \"{$title->getPrefixedDBkey()}\"\n" );
69                } else {
70                    $skippedCount++;
71                    $this->output( "WARNING: Skipped \"{$title->getPrefixedDBkey()}\" because it does not exist\n" );
72                }
73
74                $overallInd++;
75                $batchInd++;
76            }
77
78            $this->commitTransaction( $dbw, __METHOD__ );
79            $this->output( "Completed batch.\n\n" );
80        }
81
82        $this->output( "Set content model for $updatedCount pages; skipped $skippedCount pages.\n" );
83    }
84}
85
86$maintClass = FlowUpdateRevContentModelFromOccupyPages::class;
87require_once RUN_MAINTENANCE_IF_MAIN;