Skip to content

Commit dc521ef

Browse files
committed
properly handling install of plugins
1 parent 45a3788 commit dc521ef

File tree

1 file changed

+36
-11
lines changed

1 file changed

+36
-11
lines changed

src/PatternLab/Config.php

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -327,32 +327,57 @@ public static function updateConfigOption($optionName,$optionValue, $force = fal
327327

328328
// standardize the values for comparison
329329
$currentOption = self::getOption($optionName);
330-
$currentOptionValue = isset($currentOption["plugins"]) ? $currentOption["plugins"] : $currentOption;
331-
$newOptionValue = isset($optionValue["plugins"]) ? $optionValue["plugins"] : $optionValue;
330+
$currentOptionValue = $currentOption;
331+
$newOptionValue = $optionValue;
332+
$optionNameOutput = $optionName;
333+
334+
// dive into plugins to do a proper comparison to
335+
if ($optionName == "plugins") {
336+
337+
// replace the data in anticipation of it being used
338+
$optionValue = array_replace_recursive($currentOption, $newOptionValue);
339+
340+
// get the key of the plugin that is being added/updated
341+
reset($newOptionValue);
342+
$newOptionKey = key($newOptionValue);
343+
344+
if (!array_key_exists($newOptionKey, $currentOptionValue)) {
345+
346+
// if the key doesn't exist just write out the new config and move on
347+
self::writeUpdateConfigOption($optionName,$optionValue);
348+
return;
349+
350+
} else {
351+
352+
// see if the existing configs for the plugin exists. if so just return with no changes
353+
if ($newOptionValue[$newOptionKey] == $currentOptionValue[$newOptionKey]) {
354+
return;
355+
} else {
356+
$optionNameOutput = $optionName.".".$newOptionKey;
357+
}
358+
359+
}
360+
361+
}
332362

333363
if ($currentOptionValue != $newOptionValue) {
334364

335365
// prompt for input
336366
if (is_array($currentOptionValue)) {
337-
$prompt = "update the config option <desc>".$optionName."</desc> with the value from the package install?";
367+
$prompt = "update the config option <desc>".$optionNameOutput."</desc> with the value from the package install?";
338368
} else {
339-
$prompt = "update the config option <desc>".$optionName." (".$currentOptionValue.")</desc> with the value <desc>".$newOptionValue."</desc>?";
369+
$prompt = "update the config option <desc>".$optionNameOutput." (".$currentOptionValue.")</desc> with the value <desc>".$newOptionValue."</desc>?";
340370
}$options = "Y/n";
341371
$input = Console::promptInput($prompt,$options,"Y");
342372

343373
if ($input == "y") {
344374

345-
// handle plug-in values
346-
if (isset($optionValue["plugins"])) {
347-
$optionValue = array_replace_recursive($currentOption, $optionValue);
348-
}
349-
350375
// update the config option
351376
self::writeUpdateConfigOption($optionName,$optionValue);
352-
Console::writeInfo("config option ".$optionName." updated...", false, true);
377+
Console::writeInfo("config option ".$optionNameOutput." updated...", false, true);
353378

354379
} else {
355-
Console::writeWarning("config option <desc>".$optionName."</desc> not updated...", false, true);
380+
Console::writeWarning("config option <desc>".$optionNameOutput."</desc> not updated...", false, true);
356381
}
357382

358383
}

0 commit comments

Comments
 (0)