wiki.techinc.nl/maintenance/exportSites.php
Dreamy Jazz d814e25a81 Test exportSites.php and importSites.php
Why:
* Maintenance scripts in core have low test coverage.
* Testing scripts which are not overly complex should create
  less complex tests that easily raise test coverage.

What:
* Create a test for both exportSites.php and importSites.php which
  checks that the XML file produced by exportSites.php can be
  parsed and produces the same sites table config as was exported.

Bug: T371167
Change-Id: I3eb1b86803ee2413e624f9ffe699a60161103758
2024-09-16 11:51:34 +00:00

60 lines
1.3 KiB
PHP

<?php
// @codeCoverageIgnoreStart
require_once __DIR__ . '/Maintenance.php';
// @codeCoverageIgnoreEnd
use MediaWiki\Site\SiteExporter;
/**
* Maintenance script for exporting site definitions from the sites table to XML.
*
* @since 1.25
*
* @license GPL-2.0-or-later
* @author Daniel Kinzler
*/
class ExportSites extends Maintenance {
public function __construct() {
parent::__construct();
$this->addDescription( 'Exports site definitions from the sites table to XML file' );
$this->addArg( 'file', 'A file to write the XML to (see docs/sitelist.md). ' .
'Use "php://stdout" to write to stdout.', true
);
}
/**
* Do the actual work. All child classes will need to implement this
*/
public function execute() {
$file = $this->getArg( 0 );
if ( $file === 'php://output' || $file === 'php://stdout' ) {
$this->mQuiet = true;
}
$handle = fopen( $file, 'w' );
if ( !$handle ) {
$this->fatalError( "Failed to open $file for writing.\n" );
}
$exporter = new SiteExporter( $handle );
$siteLookup = $this->getServiceContainer()->getSiteLookup();
$exporter->exportSites( $siteLookup->getSites() );
fclose( $handle );
$this->output( "Exported sites to " . realpath( $file ) . ".\n" );
}
}
// @codeCoverageIgnoreStart
$maintClass = ExportSites::class;
require_once RUN_MAINTENANCE_IF_MAIN;
// @codeCoverageIgnoreEnd