Merge "Added release notes for 'ContentHandler::runLegacyHooks' removal"
[mediawiki.git] / maintenance / importSites.php
blob572234422f8aa863be799d1ccc2e928fd78e9344
1 <?php
3 $basePath = getenv( 'MW_INSTALL_PATH' ) !== false ? getenv( 'MW_INSTALL_PATH' ) : __DIR__ . '/..';
5 require_once $basePath . '/maintenance/Maintenance.php';
7 /**
8 * Maintenance script for importing site definitions from XML into the sites table.
10 * @since 1.25
12 * @license GNU GPL v2+
13 * @author Daniel Kinzler
15 class ImportSites extends Maintenance {
17 public function __construct() {
18 $this->addDescription( 'Imports site definitions from XML into the sites table.' );
20 $this->addArg( 'file', 'An XML file containing site definitions (see docs/sitelist.txt). ' .
21 'Use "php://stdin" to read from stdin.', true
24 parent::__construct();
27 /**
28 * Do the import.
30 public function execute() {
31 $file = $this->getArg( 0 );
33 $siteStore = \MediaWiki\MediaWikiServices::getInstance()->getSiteStore();
34 $importer = new SiteImporter( $siteStore );
35 $importer->setExceptionCallback( [ $this, 'reportException' ] );
37 $importer->importFromFile( $file );
39 $this->output( "Done.\n" );
42 /**
43 * Outputs a message via the output() method.
45 * @param Exception $ex
47 public function reportException( Exception $ex ) {
48 $msg = $ex->getMessage();
49 $this->output( "$msg\n" );
53 $maintClass = 'ImportSites';
54 require_once RUN_MAINTENANCE_IF_MAIN;