wiki.techinc.nl/maintenance/updateExtensionJsonSchema.php
Kunal Mehta 83ec5909d4 registration: Convert "config" into an object with metadata
To add extra metadata for "config" options without constantly adding
hacky underscore prefixed keys, convert "config" items into an object,
where the value is under a "value" key.

"_merge_strategy" is now just "merge_strategy", but still has the
underscore prefix for the cache structure, to avoid changing it.

Since this is a fully breaking change, it only applies to files with
manifest_version: 2 set. A conversion script has been added to assist
with automated conversion.

Bug: T133626
Change-Id: Id1071fc0647892438e5cd0e3ee621fbdaaa64014
2016-07-13 14:58:00 -07:00

69 lines
2 KiB
PHP

<?php
require_once __DIR__ . '/Maintenance.php';
class UpdateExtensionJsonSchema extends Maintenance {
public function __construct() {
parent::__construct();
$this->addDescription( 'Updates extension.json files to the latest manifest_version' );
$this->addArg( 'path', 'Location to the extension.json or skin.json you wish to convert',
/* $required = */ true );
}
public function execute() {
$filename = $this->getArg( 0 );
if ( !is_readable( $filename ) ) {
$this->error( "Error: Unable to read $filename", 1 );
}
$json = FormatJson::decode( file_get_contents( $filename ), true );
if ( $json === null ) {
$this->error( "Error: Invalid JSON", 1 );
}
if ( !isset( $json['manifest_version'] ) ) {
$json['manifest_version'] = 1;
}
if ( $json['manifest_version'] == ExtensionRegistry::MANIFEST_VERSION ) {
$this->output( "Already at the latest version: {$json['manifest_version']}\n" );
return;
}
while ( $json['manifest_version'] !== ExtensionRegistry::MANIFEST_VERSION ) {
$json['manifest_version'] += 1;
$func = "updateTo{$json['manifest_version']}";
$this->$func( $json );
}
file_put_contents( $filename, FormatJson::encode( $json, "\t", FormatJson::ALL_OK ) . "\n" );
$this->output( "Updated to {$json['manifest_version']}...\n" );
}
protected function updateTo2( &$json ) {
if ( isset( $json['config'] ) ) {
$config = $json['config'];
$json['config'] = [];
if ( isset( $config['_prefix'] ) ) {
$json = wfArrayInsertAfter( $json, [
'config_prefix' => $config['_prefix']
], 'config' );
unset( $config['_prefix'] );
}
foreach ( $config as $name => $value ) {
if ( $name[0] !== '@' ) {
$json['config'][$name] = [ 'value' => $value ];
if ( isset( $value[ExtensionRegistry::MERGE_STRATEGY] ) ) {
$json['config'][$name]['merge_strategy'] = $value[ExtensionRegistry::MERGE_STRATEGY];
unset( $value[ExtensionRegistry::MERGE_STRATEGY] );
}
}
}
}
}
}
$maintClass = 'UpdateExtensionJsonSchema';
require_once RUN_MAINTENANCE_IF_MAIN;