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 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
ProfilePages
0.00% covered (danger)
0.00%
0 / 39
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 / 10
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 1
20
 printProfileTypes
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 printAvailableActions
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 * @ingroup Maintenance
19 */
20
21use MediaWiki\Extension\MathSearch\Graph\Job\PageCreation;
22use MediaWiki\Extension\MathSearch\Graph\Job\SetProfileType;
23use MediaWiki\Extension\MathSearch\Graph\Map;
24
25require_once __DIR__ . '/../../../maintenance/Maintenance.php';
26
27class ProfilePages extends Maintenance {
28
29    public function __construct() {
30        parent::__construct();
31        $this->addDescription( "Mass perform actions for profile pages." );
32        $this->addArg( 'action', 'Action to be performed. ' . $this->printAvailableActions() );
33        $this->addArg( 'type', 'Type of profile to be addressed. ' . $this->printProfileTypes() );
34        $this->setBatchSize( 100000 );
35        $this->addOption(
36            'overwrite', 'Overwrite existing pages with the same name.', false, false, "o"
37        );
38
39        $this->requireExtension( 'MathSearch' );
40        $this->requireExtension( 'LinkedWiki' );
41    }
42
43    public function execute() {
44        global $wgMathProfileQueries, $wgMathProfileQIdMap;
45        $type = $this->getArg( 'type' );
46        if ( !isset( $wgMathProfileQueries[$type] ) ) {
47            $this->error( "Unknown type of profile to be created.\n" );
48            $this->error( $this->printProfileTypes() );
49            return;
50        }
51        $jobOptions = [
52            'overwrite' => $this->getOption( 'overwrite' )
53        ];
54        $action = $this->getArg( 'action' );
55        if ( $action === 'create' ) {
56            $jobType = PageCreation::class;
57        } elseif ( $action === 'load' ) {
58            $jobType = SetProfileType::class;
59            $jobOptions['qType'] = $wgMathProfileQIdMap[$type];
60        } else {
61            $this->error( "Unknown action to be performed.\n" );
62            $this->error( $this->printAvailableActions() );
63            return;
64        }
65
66        ( new Map() )->getJobs(
67            \Closure::fromCallable( [ $this, 'output' ] ),
68            $this->getOption( 'batchSize', $this->getBatchSize() ),
69            $type,
70            $jobType,
71            $jobOptions
72        );
73    }
74
75    public function printProfileTypes(): string {
76        global $wgMathProfileQueries;
77        return "Available types are: " . implode( ', ', array_keys( $wgMathProfileQueries ) ) .
78            "\n";
79    }
80
81    public function printAvailableActions(): string {
82        return "Available actions are: create, load.\n";
83    }
84
85}
86
87$maintClass = ProfilePages::class;
88require_once RUN_MAINTENANCE_IF_MAIN;