Fix setting of scripts from config command, refs #7225

main
Jordi Boggiano 6 years ago
parent 5aff7dff70
commit 0ab843a058

@ -613,12 +613,12 @@ EOT
} }
// handle script // handle script
if (preg_match('/^scripts\.(.+)/', $settingKey,$matches)){ if (preg_match('/^scripts\.(.+)/', $settingKey, $matches)){
if ($input->getOption('unset')) { if ($input->getOption('unset')) {
return $this->configSource->removeConfigSetting($settingKey); return $this->configSource->removeProperty($settingKey);
} }
return $this->configSource->addConfigSetting($settingKey, $values[0]); return $this->configSource->addProperty($settingKey, count($values) > 1 ? $values : $values[0]);
} }
throw new \InvalidArgumentException('Setting '.$settingKey.' does not exist or is not supported by this command'); throw new \InvalidArgumentException('Setting '.$settingKey.' does not exist or is not supported by this command');

@ -135,10 +135,10 @@ class JsonConfigSource implements ConfigSourceInterface
public function addProperty($name, $value) public function addProperty($name, $value)
{ {
$this->manipulateJson('addProperty', $name, $value, function (&$config, $key, $val) { $this->manipulateJson('addProperty', $name, $value, function (&$config, $key, $val) {
if (substr($key, 0, 6) === 'extra.') { if (substr($key, 0, 6) === 'extra.' || substr($key, 0, 8) === 'scripts.') {
$bits = explode('.', $key); $bits = explode('.', $key);
$last = array_pop($bits); $last = array_pop($bits);
$arr = &$config['extra']; $arr = &$config[reset($bits)];
foreach ($bits as $bit) { foreach ($bits as $bit) {
if (!isset($arr[$bit])) { if (!isset($arr[$bit])) {
$arr[$bit] = array(); $arr[$bit] = array();
@ -159,10 +159,10 @@ class JsonConfigSource implements ConfigSourceInterface
{ {
$authConfig = $this->authConfig; $authConfig = $this->authConfig;
$this->manipulateJson('removeProperty', $name, function (&$config, $key) { $this->manipulateJson('removeProperty', $name, function (&$config, $key) {
if (substr($key, 0, 6) === 'extra.') { if (substr($key, 0, 6) === 'extra.' || substr($key, 0, 8) === 'scripts.') {
$bits = explode('.', $key); $bits = explode('.', $key);
$last = array_pop($bits); $last = array_pop($bits);
$arr = &$config['extra']; $arr = &$config[reset($bits)];
foreach ($bits as $bit) { foreach ($bits as $bit) {
if (!isset($arr[$bit])) { if (!isset($arr[$bit])) {
return; return;

@ -171,6 +171,10 @@ class JsonManipulator
return $this->addSubNode('extra', substr($name, 6), $value); return $this->addSubNode('extra', substr($name, 6), $value);
} }
if (substr($name, 0, 8) === 'scripts.') {
return $this->addSubNode('scripts', substr($name, 8), $value);
}
return $this->addMainKey($name, $value); return $this->addMainKey($name, $value);
} }
@ -180,6 +184,10 @@ class JsonManipulator
return $this->removeSubNode('extra', substr($name, 6)); return $this->removeSubNode('extra', substr($name, 6));
} }
if (substr($name, 0, 8) === 'scripts.') {
return $this->removeSubNode('scripts', substr($name, 8));
}
return $this->removeMainKey($name); return $this->removeMainKey($name);
} }
@ -188,7 +196,7 @@ class JsonManipulator
$decoded = JsonFile::parseJson($this->contents); $decoded = JsonFile::parseJson($this->contents);
$subName = null; $subName = null;
if (in_array($mainNode, array('config', 'extra')) && false !== strpos($name, '.')) { if (in_array($mainNode, array('config', 'extra', 'scripts')) && false !== strpos($name, '.')) {
list($name, $subName) = explode('.', $name, 2); list($name, $subName) = explode('.', $name, 2);
} }
@ -308,7 +316,7 @@ class JsonManipulator
} }
$subName = null; $subName = null;
if (in_array($mainNode, array('config', 'extra')) && false !== strpos($name, '.')) { if (in_array($mainNode, array('config', 'extra', 'scripts')) && false !== strpos($name, '.')) {
list($name, $subName) = explode('.', $name, 2); list($name, $subName) = explode('.', $name, 2);
} }

Loading…
Cancel
Save