ImportSites::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 15 and the first side effect is on line 3.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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->addDescription( 'Imports site definitions from XML into the sites table.' );
19
20
		$this->addArg( 'file', 'An XML file containing site definitions (see docs/sitelist.txt). ' .
21
			'Use "php://stdin" to read from stdin.', true
22
		);
23
24
		parent::__construct();
25
	}
26
27
	/**
28
	 * Do the import.
29
	 */
30
	public function execute() {
31
		$file = $this->getArg( 0 );
32
33
		$siteStore = \MediaWiki\MediaWikiServices::getInstance()->getSiteStore();
34
		$importer = new SiteImporter( $siteStore );
35
		$importer->setExceptionCallback( [ $this, 'reportException' ] );
36
37
		$importer->importFromFile( $file );
38
39
		$this->output( "Done.\n" );
40
	}
41
42
	/**
43
	 * Outputs a message via the output() method.
44
	 *
45
	 * @param Exception $ex
46
	 */
47
	public function reportException( Exception $ex ) {
48
		$msg = $ex->getMessage();
49
		$this->output( "$msg\n" );
50
	}
51
}
52
53
$maintClass = 'ImportSites';
54
require_once RUN_MAINTENANCE_IF_MAIN;
55