mediawiki-extensions-Discus.../maintenance/manageForeignResources.php
Bartosz Dziewoński 1cdb3df12a Fix boilerplate in maintenance scripts for WMF production
We run MediaWiki from directories like "php-1.39.0-wmf.26",
whose names include dots, making these scripts impossible to run.

Bug: T316548
Change-Id: Ic318939cea6eafb1a0cd3105517e45c9fca52f4b
2022-08-29 14:14:09 +00:00

55 lines
1.4 KiB
PHP

<?php
namespace MediaWiki\Extension\DiscussionTools\Maintenance;
use ForeignResourceManager;
use Maintenance;
// Security: Disable all stream wrappers and reenable individually as needed
foreach ( stream_get_wrappers() as $wrapper ) {
stream_wrapper_unregister( $wrapper );
}
// Needed by the Guzzle library for some reason
stream_wrapper_restore( 'php' );
// Needed by ForeignResourceManager to unpack TAR files
stream_wrapper_restore( 'phar' );
stream_wrapper_restore( 'file' );
$basePath = getenv( 'MW_INSTALL_PATH' );
if ( $basePath ) {
if ( !is_dir( $basePath )
|| strpos( $basePath, '~' ) !== false
) {
die( "Bad MediaWiki install path: $basePath\n" );
}
} else {
$basePath = __DIR__ . '/../../..';
}
require_once "$basePath/maintenance/Maintenance.php";
class ManageForeignResources extends Maintenance {
public function __construct() {
parent::__construct();
$this->requireExtension( 'DiscussionTools' );
}
public function execute() {
$frm = new ForeignResourceManager(
__DIR__ . '/../modules/lib/foreign-resources.yaml',
__DIR__ . '/../modules/lib'
);
return $frm->run( 'update', 'all' );
}
}
$maintClass = ManageForeignResources::class;
$doMaintenancePath = RUN_MAINTENANCE_IF_MAIN;
if ( !( file_exists( $doMaintenancePath ) &&
realpath( $doMaintenancePath ) === realpath( "$basePath/maintenance/doMaintenance.php" ) ) ) {
die( "Bad maintenance script location: $basePath\n" );
}
require_once RUN_MAINTENANCE_IF_MAIN;