Debian Codegraph @

maintenance/importSites.php

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