Seb35 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/344766 )

Change subject: Fix bug about empty lists/objects in composer.json
......................................................................

Fix bug about empty lists/objects in composer.json

During installation of Composer-managed MediaWiki extensions, the composer.json
is changed and sometimes the 'require' section becomes empty; this was
previously solved by adding the option JSON_FORCE_OBJECT in json_encode, but
this option transforms all lists to objects, which conflicts with standard
MediaWiki composer.json which contains real listes (e.g. 'authors') and Composer
stops because of schema error.

The solution implemented here is to remove the option JSON_FORCE_OBJECT and
remove the sections 'require-dev' and 'require' when they are empty to avoid
they are changed to an empty list. Added a list in the test composer.json to
avoid further regressions about this.

Change-Id: Id4b4017f69fd611b8b0e84b7b0b27ce3d326e624
---
M src/MediaWikiFarmComposerScript.php
M tests/phpunit/data/mediawiki/vstub/composer.json
2 files changed, 12 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MediaWikiFarm 
refs/changes/66/344766/1

diff --git a/src/MediaWikiFarmComposerScript.php 
b/src/MediaWikiFarmComposerScript.php
index f46e232..42fd69e 100644
--- a/src/MediaWikiFarmComposerScript.php
+++ b/src/MediaWikiFarmComposerScript.php
@@ -154,6 +154,12 @@
                                $dependencies[$extensions[$package['name']]] = 
array_key_exists( 'require', $package ) ? array_keys( $package['require'] ) : 
array();
                        }
                }
+
+               # Remove if empty, else it would create an empty JSON list but 
the schema expects it is an object (PHP has no
+               # such distinction); the option JSON_FORCE_OBJECT is not 
appropriate because it always transforms lists to objects
+               if( array_key_exists( 'require-dev', $baseComposerJson ) && 
count( $baseComposerJson['require-dev'] ) == 0 ) {
+                       unset( $baseComposerJson['require-dev'] );
+               }
                asort( $extensions );
                ksort( $dependencies );
                if( !$quiet ) {
@@ -196,7 +202,7 @@
                        }
 
                        self::rmdirr( 'vendor/autoload.php' );
-                       file_put_contents( 'composer.json', json_encode( 
$thisInstallation, JSON_FORCE_OBJECT ) );
+                       file_put_contents( 'composer.json', json_encode( 
$thisInstallation ) );
                        system( 'composer update ' . implode( ' ', $this->argv 
), $return );
                        if( $return ) {
                                // @codeCoverageIgnoreStart
@@ -216,13 +222,16 @@
                # Finally the Composer set without any extension/skin
                $thisInstallation = $baseComposerJson;
                $thisInstallation['config']['autoloader-suffix'] = 'DEFAULT';
+               if( array_key_exists( 'require', $baseComposerJson ) && count( 
$baseComposerJson['require'] ) == 0 ) {
+                       unset( $thisInstallation['require'] );
+               }
 
                if( !$quiet ) {
                        echo "$icounter. Composer with empty extensions/skins 
set:\n"; // @codeCoverageIgnore
                }
 
                self::rmdirr( 'vendor/autoload.php' );
-               file_put_contents( 'composer.json', json_encode( 
$thisInstallation, JSON_FORCE_OBJECT ) );
+               file_put_contents( 'composer.json', json_encode( 
$thisInstallation ) );
                system( 'composer update ' . implode( ' ', $this->argv ), 
$return );
                if( $return ) {
                        // @codeCoverageIgnoreStart
diff --git a/tests/phpunit/data/mediawiki/vstub/composer.json 
b/tests/phpunit/data/mediawiki/vstub/composer.json
index 937df07..c3746c3 100644
--- a/tests/phpunit/data/mediawiki/vstub/composer.json
+++ b/tests/phpunit/data/mediawiki/vstub/composer.json
@@ -1,4 +1,5 @@
 {
+       "keywords": [],
        "require": {
                "mediawiki/page-forms": "*",
                "mediawiki/semantic-forms-select": "*",

-- 
To view, visit https://gerrit.wikimedia.org/r/344766
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id4b4017f69fd611b8b0e84b7b0b27ce3d326e624
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MediaWikiFarm
Gerrit-Branch: master
Gerrit-Owner: Seb35 <se...@seb35.fr>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to