Merge "Add error checking for file argument"
[mediawiki.git] / maintenance / importSites.php
blob7cd2000820e35b3953ed6f2be8bcd5d9e23f00b7
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->mDescription = '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();
28 /**
29 * Do the import.
31 public function execute() {
32 $file = $this->getArg( 0 );
34 $importer = new SiteImporter( SiteSQLStore::newInstance() );
35 $importer->setExceptionCallback( array( $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;