MediaWiki master
importSites.php
Go to the documentation of this file.
1<?php
2
3// @codeCoverageIgnoreStart
4require_once __DIR__ . '/Maintenance.php';
5// @codeCoverageIgnoreEnd
6
9
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
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
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
Maintenance script for importing site definitions from XML into the sites table.
reportException(Exception $ex)
Outputs a message via the output() method.
execute()
Do the import.
__construct()
Default constructor.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
addArg( $arg, $description, $required=true, $multi=false)
Add some args that are needed.
getArg( $argId=0, $default=null)
Get an argument.
output( $out, $channel=null)
Throw some output to the user.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.
Utility for importing site entries from XML.
$maintClass