Added getDefaultInstance() return type doc
[lhc/web/wiklou.git] / maintenance / exportSites.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 exporting site definitions from XML into the sites table.
9 *
10 * @since 1.25
11 *
12 * @licence GNU GPL v2+
13 * @author Daniel Kinzler
14 */
15 class ExportSites extends Maintenance {
16
17 public function __construct() {
18 $this->mDescription = 'Exports site definitions the sites table to XML file';
19
20 $this->addArg( 'file', 'A file to write the XML to (see docs/sitelist.txt). Use "php://stdout" to write to stdout.', true );
21
22 parent::__construct();
23 }
24
25 /**
26 * Do the actual work. All child classes will need to implement this
27 */
28 public function execute() {
29 $file = $this->getArg( 0 );
30
31 if ( $file === 'php://output' || $file === 'php://stdout' ) {
32 $this->mQuiet = true;
33 }
34
35 $handle = fopen( $file, 'w' );
36
37 if ( !$handle ) {
38 $this->error( "Failed to open $file for writing.\n", 1 );
39 }
40
41 $exporter = new SiteExporter( $handle );
42
43 $sites = SiteSQLStore::newInstance()->getSites( 'recache' );
44 $exporter->exportSites( $sites );
45
46 fclose( $handle );
47
48 $this->output( "Exported sites to " . realpath( $file ) . ".\n" );
49 }
50
51 }
52
53 $maintClass = 'ExportSites';
54 require_once( RUN_MAINTENANCE_IF_MAIN );