Fixed spacing
[lhc/web/wiklou.git] / maintenance / importSites.php
1 <?php
2
3 $basePath = getenv( 'MW_INSTALL_PATH' ) !== false ? getenv( 'MW_INSTALL_PATH' ) : __DIR__ . '/..';
4
5 require_once $basePath . '/maintenance/Maintenance.php';
6
7 /**
8 * Maintenance script for importing site definitions from XML into the sites table.
9 *
10 * @since 1.25
11 *
12 * @license GNU GPL v2+
13 * @author Daniel Kinzler
14 */
15 class ImportSites extends Maintenance {
16
17 public function __construct() {
18 $this->mDescription = 'Imports site definitions from XML into the sites table.';
19
20 $this->addArg( 'file', 'An XML file containing site definitions (see docs/sitelist.txt). Use "php://stdin" to read from stdin.', true );
21
22 parent::__construct();
23 }
24
25
26 /**
27 * Do the import.
28 */
29 public function execute() {
30 $file = $this->getArg( 0 );
31
32 $importer = new SiteImporter( SiteSQLStore::newInstance() );
33 $importer->setExceptionCallback( array( $this, 'reportException' ) );
34
35 $importer->importFromFile( $file );
36
37 $this->output( "Done.\n" );
38 }
39
40 /**
41 * Outputs a message via the output() method.
42 *
43 * @param Exception $ex
44 */
45 public function reportException( Exception $ex ) {
46 $msg = $ex->getMessage();
47 $this->output( "$msg\n" );
48 }
49 }
50
51 $maintClass = 'ImportSites';
52 require_once RUN_MAINTENANCE_IF_MAIN;