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 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
FixProofreadIndexPagesContentModel
0.00% covered (danger)
0.00%
0 / 36
0.00% covered (danger)
0.00%
0 / 3
30
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
 doDBUpdates
0.00% covered (danger)
0.00%
0 / 31
0.00% covered (danger)
0.00%
0 / 1
12
 getUpdateKey
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21use ProofreadPage\ProofreadPage;
22
23$IP = getenv( 'MW_INSTALL_PATH' );
24if ( $IP === false ) {
25    $IP = __DIR__ . '/../../..';
26}
27require_once "$IP/maintenance/Maintenance.php";
28
29/**
30 * Set the content model type for Page: pages
31 *
32 * @ingroup ProofreadPage
33 */
34class FixProofreadIndexPagesContentModel extends LoggedUpdateMaintenance {
35
36    public function __construct() {
37        parent::__construct();
38
39        $this->addDescription( 'Set the content model type for Index: pages' );
40        $this->setBatchSize( 1000 );
41
42        $this->requireExtension( 'ProofreadPage' );
43    }
44
45    /**
46     * @inheritDoc
47     */
48    public function doDBUpdates() {
49        $dbw = $this->getDB( DB_PRIMARY );
50        if ( !$dbw->fieldExists( 'page', 'page_content_model', __METHOD__ ) ) {
51            $this->error( 'page_content_model field of page table does not exists.' );
52            return false;
53        }
54
55        $this->output( "Updating content model for Index: pages..\n" );
56        $total = 0;
57        $namespaceId = ProofreadPage::getIndexNamespaceId();
58        do {
59            $pageIds = $dbw->newSelectQueryBuilder()
60                ->select( 'page_id' )
61                ->from( 'page' )
62                ->where( [
63                    'page_namespace' => $namespaceId,
64                    'page_content_model' => CONTENT_MODEL_WIKITEXT
65                ] )
66                ->limit( $this->mBatchSize )
67                ->caller( __METHOD__ )
68                ->fetchFieldValues();
69            if ( !$pageIds ) {
70                break;
71            }
72            $dbw->newUpdateQueryBuilder()
73                ->update( 'page' )
74                ->set( [ 'page_content_model' => CONTENT_MODEL_PROOFREAD_INDEX ] )
75                ->where( [ 'page_id' => $pageIds ] )
76                ->caller( __METHOD__ )
77                ->execute();
78            $this->waitForReplication();
79            $total += $dbw->affectedRows();
80            $this->output( "$total\n" );
81        } while ( true );
82
83        $this->output( "Update of the content model for Index: pages is done.\n" );
84
85        return true;
86    }
87
88    /**
89     * @inheritDoc
90     */
91    public function getUpdateKey() {
92        return 'FixIndexPagesContentModel';
93    }
94
95}
96
97$maintClass = FixProofreadIndexPagesContentModel::class;
98require_once RUN_MAINTENANCE_IF_MAIN;