Move ChronologyProtector/TransactionProfiler to Rdbms namespace
[mediawiki.git] / maintenance / updateExtensionJsonSchema.php
blob427769f19f1a164aa18d69eefd926607ec7b08ab
1 <?php
3 require_once __DIR__ . '/Maintenance.php';
5 class UpdateExtensionJsonSchema extends Maintenance {
7 public function __construct() {
8 parent::__construct();
9 $this->addDescription( 'Updates extension.json files to the latest manifest_version' );
10 $this->addArg( 'path', 'Location to the extension.json or skin.json you wish to convert',
11 /* $required = */ true );
14 public function execute() {
15 $filename = $this->getArg( 0 );
16 if ( !is_readable( $filename ) ) {
17 $this->error( "Error: Unable to read $filename", 1 );
20 $json = FormatJson::decode( file_get_contents( $filename ), true );
21 if ( $json === null ) {
22 $this->error( "Error: Invalid JSON", 1 );
25 if ( !isset( $json['manifest_version'] ) ) {
26 $json['manifest_version'] = 1;
29 if ( $json['manifest_version'] == ExtensionRegistry::MANIFEST_VERSION ) {
30 $this->output( "Already at the latest version: {$json['manifest_version']}\n" );
31 return;
34 while ( $json['manifest_version'] !== ExtensionRegistry::MANIFEST_VERSION ) {
35 $json['manifest_version'] += 1;
36 $func = "updateTo{$json['manifest_version']}";
37 $this->$func( $json );
40 file_put_contents( $filename, FormatJson::encode( $json, "\t", FormatJson::ALL_OK ) . "\n" );
41 $this->output( "Updated to {$json['manifest_version']}...\n" );
44 protected function updateTo2( &$json ) {
45 if ( isset( $json['config'] ) ) {
46 $config = $json['config'];
47 $json['config'] = [];
48 if ( isset( $config['_prefix'] ) ) {
49 $json = wfArrayInsertAfter( $json, [
50 'config_prefix' => $config['_prefix']
51 ], 'config' );
52 unset( $config['_prefix'] );
55 foreach ( $config as $name => $value ) {
56 if ( $name[0] !== '@' ) {
57 $json['config'][$name] = [ 'value' => $value ];
58 if ( isset( $value[ExtensionRegistry::MERGE_STRATEGY] ) ) {
59 $json['config'][$name]['merge_strategy'] = $value[ExtensionRegistry::MERGE_STRATEGY];
60 unset( $value[ExtensionRegistry::MERGE_STRATEGY] );
68 $maintClass = 'UpdateExtensionJsonSchema';
69 require_once RUN_MAINTENANCE_IF_MAIN;