Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
41 / 41
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
CleanupPageTriage
100.00% covered (success)
100.00%
41 / 41
100.00% covered (success)
100.00%
2 / 2
5
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 execute
100.00% covered (success)
100.00%
38 / 38
100.00% covered (success)
100.00%
1 / 1
4
1<?php
2/**
3 * Remove page with namespace other than NS_MAIN/NS_USER from pagetriage queue
4 *
5 * @ingroup Maintenance
6 */
7
8namespace MediaWiki\Extension\PageTriage\Maintenance;
9
10use MediaWiki\Extension\PageTriage\PageTriageUtil;
11use MediaWiki\Maintenance\Maintenance;
12
13/**
14 * Maintenance script that removes page with namespace other than NS_MAIN/NS_USER
15 * from pagetriage queue
16 *
17 * @ingroup Maintenance
18 */
19class CleanupPageTriage extends Maintenance {
20
21    public function __construct() {
22        parent::__construct();
23        $this->requireExtension( 'PageTriage' );
24        $this->setBatchSize( 100 );
25    }
26
27    public function execute() {
28        $dbw = PageTriageUtil::getPrimaryConnection();
29        $dbr = PageTriageUtil::getReplicaConnection();
30
31        $batchSize = $this->getBatchSize();
32        $count = $batchSize;
33        $start = 0;
34
35        while ( $count == $batchSize ) {
36            $res = $dbr->newSelectQueryBuilder()
37                ->select( [ 'page_id' ] )
38                ->from( 'pagetriage_page' )
39                ->join( 'page', null, 'page_id = ptrp_page_id' )
40                ->where( [
41                    $dbr->expr( 'page_namespace', '!=', [ NS_MAIN, NS_USER ] ),
42                    $dbr->expr( 'ptrp_page_id', '>', $start ),
43                ] )
44                ->limit( $batchSize )
45                ->orderBy( 'ptrp_page_id' )
46                ->caller( __METHOD__ )
47                ->fetchResultSet();
48
49            $page = [];
50            foreach ( $res as $row ) {
51                $page[] = $row->page_id;
52                $start  = $row->page_id;
53            }
54            $count = count( $page );
55
56            if ( $count > 0 ) {
57                $this->beginTransaction( $dbw, __METHOD__ );
58
59                $dbw->newDeleteQueryBuilder()
60                    ->deleteFrom( 'pagetriage_page' )
61                    ->where( [ 'ptrp_page_id' => $page ] )
62                    ->caller( __METHOD__ )
63                    ->execute();
64
65                $dbw->newDeleteQueryBuilder()
66                    ->deleteFrom( 'pagetriage_page_tags' )
67                    ->where( [ 'ptrpt_page_id' => $page ] )
68                    ->caller( __METHOD__ )
69                    ->execute();
70
71                $this->commitTransaction( $dbw, __METHOD__ );
72
73                $this->output( "processing " . $count . "\n" );
74                $this->waitForReplication();
75            }
76
77        }
78    }
79}