Catrope has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/324632

Change subject: ExtensionRegistry: add array_plus_recursive merge strategy
......................................................................

ExtensionRegistry: add array_plus_recursive merge strategy

This is needed for deeply nested structures that get overridden in 
LocalSettings.php.
For example, the MW-Vagrant settings.d file for Echo uses:
        $wgEchoConfig['eventlogging']['EchoMail']['enabled'] = true;
and the default value of $wgEchoConfig is a nested associative array structure
where 'enabled' has other siblings:
        $wgEchoConfig = array(
                ...
                'eventlogging' => array(
                        ...
                        'EchoMail' => array(
                                'enabled' => false,
                                'revision' => 12345,
                                'client' => false
                        )
                )
        )

In this case, the default merge strategy wipes out most of the
config var. array_replace_recursive is the only one that leaves
the structure intact, but in that strategy conflicts are resolved
in favor of the extension.json value, which means overrides
aren't possible. The array_plus_recursive strategy just
calls array_replace_recursive with the arguments reversed, so that
conflicts are resolved in favor of the pre-existing global value.

Change-Id: I03f634ad8c9e568e707baa4a5017aa0d317c2799
---
M docs/extension.schema.json
M docs/extension.schema.v1.json
M includes/registration/ExtensionRegistry.php
M tests/phpunit/includes/registration/ExtensionRegistryTest.php
4 files changed, 46 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/32/324632/1

diff --git a/docs/extension.schema.json b/docs/extension.schema.json
index 30feaef..f3ca1bd 100644
--- a/docs/extension.schema.json
+++ b/docs/extension.schema.json
@@ -684,6 +684,7 @@
                                                        "enum": [
                                                                
"array_merge_recursive",
                                                                
"array_replace_recursive",
+                                                               
"array_plus_recursive",
                                                                "array_plus_2d",
                                                                "array_plus",
                                                                "array_merge"
diff --git a/docs/extension.schema.v1.json b/docs/extension.schema.v1.json
index 421ea5c..edb95c9 100644
--- a/docs/extension.schema.v1.json
+++ b/docs/extension.schema.v1.json
@@ -672,6 +672,7 @@
                                                        "enum": [
                                                                
"array_merge_recursive",
                                                                
"array_replace_recursive",
+                                                               
"array_plus_recursive",
                                                                "array_plus_2d",
                                                                "array_plus",
                                                                "array_merge"
diff --git a/includes/registration/ExtensionRegistry.php 
b/includes/registration/ExtensionRegistry.php
index b5c70e9..56a72dc 100644
--- a/includes/registration/ExtensionRegistry.php
+++ b/includes/registration/ExtensionRegistry.php
@@ -265,6 +265,11 @@
                                case 'array_replace_recursive':
                                        $GLOBALS[$key] = 
array_replace_recursive( $GLOBALS[$key], $val );
                                        break;
+                               case 'array_plus_recursive':
+                                       // Implemented by calling 
array_replace_recursive() in reverse,
+                                       // because that's equivalent
+                                       $GLOBALS[$key] = 
array_replace_recursive( $val, $GLOBALS[$key] );
+                                       break;
                                case 'array_plus_2d':
                                        $GLOBALS[$key] = wfArrayPlus2d( 
$GLOBALS[$key], $val );
                                        break;
diff --git a/tests/phpunit/includes/registration/ExtensionRegistryTest.php 
b/tests/phpunit/includes/registration/ExtensionRegistryTest.php
index 9b57e1c..22c7b2d 100644
--- a/tests/phpunit/includes/registration/ExtensionRegistryTest.php
+++ b/tests/phpunit/includes/registration/ExtensionRegistryTest.php
@@ -287,6 +287,45 @@
                                        ],
                                ],
                        ],
+                       [
+                               'test array_plus_recursive',
+                               [
+                                       'mwtestDeep' => [
+                                               'foo' => [
+                                                       'bar' => [
+                                                               'baz' => 5
+                                                       ]
+                                               ]
+                                       ]
+                               ],
+                               [
+                                       'mwtestDeep' => [
+                                               'foo' => [
+                                                       'x' => 1,
+                                                       'bar' => [
+                                                               'y' => 2,
+                                                               'baz' => 3,
+                                                       ],
+                                                       'z' => 4
+                                               ],
+                                               'q' => 9,
+                                               
ExtensionRegistry::MERGE_STRATEGY => 'array_plus_recursive',
+                                       ]
+                               ],
+                               [
+                                       'mwtestDeep' => [
+                                               'foo' => [
+                                                       'x' => 1,
+                                                       'bar' => [
+                                                               'y' => 2,
+                                                               'baz' => 5,
+                                                       ],
+                                                       'z' => 4
+                                               ],
+                                               'q' => 9,
+                                       ]
+                               ],
+                       ]
                ];
        }
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I03f634ad8c9e568e707baa4a5017aa0d317c2799
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Catrope <r...@wikimedia.org>

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

Reply via email to