Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
84.62% covered (warning)
84.62%
11 / 13
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
ImportSites
84.62% covered (warning)
84.62%
11 / 13
66.67% covered (warning)
66.67%
2 / 3
3.03
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 execute
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 reportException
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3// @codeCoverageIgnoreStart
4require_once __DIR__ . '/Maintenance.php';
5// @codeCoverageIgnoreEnd
6
7use MediaWiki\Maintenance\Maintenance;
8use MediaWiki\Site\SiteImporter;
9
10/**
11 * Maintenance script for importing site definitions from XML into the sites table.
12 *
13 * @since 1.25
14 *
15 * @license GPL-2.0-or-later
16 * @author Daniel Kinzler
17 */
18class ImportSites extends Maintenance {
19
20    public function __construct() {
21        parent::__construct();
22
23        $this->addDescription( 'Imports site definitions from XML into the sites table.' );
24
25        $this->addArg( 'file', 'An XML file containing site definitions (see docs/sitelist.md). ' .
26            'Use "php://stdin" to read from stdin.', true
27        );
28    }
29
30    /**
31     * Do the import.
32     */
33    public function execute() {
34        $file = $this->getArg( 0 );
35
36        $siteStore = $this->getServiceContainer()->getSiteStore();
37        $importer = new SiteImporter( $siteStore );
38        $importer->setExceptionCallback( [ $this, 'reportException' ] );
39
40        $importer->importFromFile( $file );
41
42        $this->output( "Done.\n" );
43    }
44
45    /**
46     * Outputs a message via the output() method.
47     */
48    public function reportException( Exception $ex ) {
49        $msg = $ex->getMessage();
50        $this->output( "$msg\n" );
51    }
52}
53
54// @codeCoverageIgnoreStart
55$maintClass = ImportSites::class;
56require_once RUN_MAINTENANCE_IF_MAIN;
57// @codeCoverageIgnoreEnd