Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

Commit 0fd493c

Browse files
committed
Massive changes for better handling parameters values in ajxp_conf driver.
1 parent f8d767f commit 0fd493c

File tree

1 file changed

+68
-17
lines changed

1 file changed

+68
-17
lines changed

core/src/plugins/access.ajxp_conf/class.ajxp_confAccessDriver.php

Lines changed: 68 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ public function switchAction($action, $httpVars, $fileVars)
562562
}
563563
if (isSet($httpVars["format"]) && $httpVars["format"] == "json") {
564564
HTMLWriter::charsetHeader("application/json");
565-
$roleData = $role->getDataArray();
565+
$roleData = $role->getDataArray(true);
566566
$allReps = ConfService::getRepositoriesList("all", false);
567567
$repos = array();
568568
if(!empty($userObject)){
@@ -673,11 +673,14 @@ public function switchAction($action, $httpVars, $fileVars)
673673
$parsed,
674674
($userObject!=null?$usrId:null),
675675
"ROLE_PARAM_",
676-
$binariesContext
676+
$binariesContext,
677+
AJXP_Role::$cypheredPassPrefix
677678
);
678679
$roleData["PARAMETERS"][$repoScope][$plugId] = $parsed;
679680
}
680681
}
682+
$existingParameters = $originalRole->listParameters(true);
683+
$this->mergeExistingParameters($roleData["PARAMETERS"], $existingParameters);
681684
if (isSet($userObject) && isSet($data["USER"]) && isSet($data["USER"]["PROFILE"])) {
682685
$userObject->setAdmin(($data["USER"]["PROFILE"] == "admin"));
683686
$userObject->setProfile($data["USER"]["PROFILE"]);
@@ -718,7 +721,7 @@ public function switchAction($action, $httpVars, $fileVars)
718721
} else {
719722
AuthService::updateRole($originalRole);
720723
}
721-
$output = array("ROLE" => $originalRole->getDataArray(), "SUCCESS" => true);
724+
$output = array("ROLE" => $originalRole->getDataArray(true), "SUCCESS" => true);
722725
} catch (Exception $e) {
723726
$output = array("ERROR" => $e->getMessage());
724727
}
@@ -1004,7 +1007,7 @@ public function switchAction($action, $httpVars, $fileVars)
10041007
if(!is_array($custom)) $custom = array();
10051008

10061009
$options = $custom;
1007-
$this->parseParameters($httpVars, $options, $userId);
1010+
$this->parseParameters($httpVars, $options, $userId, false, $custom);
10081011
$custom = $options;
10091012
$user->setPref("CUSTOM_PARAMS", $custom);
10101013
$user->save();
@@ -1037,7 +1040,8 @@ public function switchAction($action, $httpVars, $fileVars)
10371040
$wallet[$repoID] = array();
10381041
}
10391042
$options = $wallet[$repoID];
1040-
$this->parseParameters($httpVars, $options, $userId);
1043+
$existing = $options;
1044+
$this->parseParameters($httpVars, $options, $userId, false, $existing);
10411045
$wallet[$repoID] = $options;
10421046
$user->setPref("AJXP_WALLET", $wallet);
10431047
$user->save();
@@ -1277,6 +1281,7 @@ public function switchAction($action, $httpVars, $fileVars)
12771281
}
12781282
}
12791283
$nested = array();
1284+
$definitions = $plug->getConfigsDefinitions();
12801285
print("<repository index=\"$repId\"");
12811286
foreach ($repository as $name => $option) {
12821287
if(strstr($name, " ")>-1) continue;
@@ -1300,7 +1305,10 @@ public function switchAction($action, $httpVars, $fileVars)
13001305
} else {
13011306
if (is_bool($optValue)) {
13021307
$optValue = ($optValue?"true":"false");
1308+
} else if(isSet($definitions[$key]) && $definitions[$key]["type"] == "password" && !empty($optValue)){
1309+
$optValue = "__AJXP_VALUE_SET__";
13031310
}
1311+
13041312
$optValue = AJXP_Utils::xmlEntities($optValue, true);
13051313
print("<param name=\"$key\" value=\"$optValue\"/>");
13061314
}
@@ -1373,7 +1381,10 @@ public function switchAction($action, $httpVars, $fileVars)
13731381
$res = ConfService::replaceRepository($repId, $repo);
13741382
} else {
13751383
$options = array();
1376-
$this->parseParameters($httpVars, $options, null, true);
1384+
$existing = $repo->getOptionsDefined();
1385+
$existingValues = array();
1386+
foreach($existing as $exK) $existingValues[$exK] = $repo->getOption($exK, true);
1387+
$this->parseParameters($httpVars, $options, null, true, $existingValues);
13771388
if (count($options)) {
13781389
foreach ($options as $key=>$value) {
13791390
if ($key == "AJXP_SLUG") {
@@ -1502,6 +1513,9 @@ public function switchAction($action, $httpVars, $fileVars)
15021513
$options = array();
15031514
$this->parseParameters($httpVars, $options, null, true);
15041515
}
1516+
if(isset($repoOptions[$metaSourceId])){
1517+
$this->mergeExistingParameters($options, $repoOptions[$metaSourceId]);
1518+
}
15051519
$repoOptions[$metaSourceId] = $options;
15061520
uksort($repoOptions, array($this,"metaSourceOrderingFunction"));
15071521
$repo->addOption("META_SOURCES", $repoOptions);
@@ -1597,6 +1611,7 @@ public function switchAction($action, $httpVars, $fileVars)
15971611
$fullManifest = $ajxpPlugin->getManifestRawContent("", "xml");
15981612
$xPath = new DOMXPath($fullManifest->ownerDocument);
15991613
$addParams = "";
1614+
$instancesDefinitions = array();
16001615
$pInstNodes = $xPath->query("server_settings/global_param[contains(@type, 'plugin_instance:')]");
16011616
foreach ($pInstNodes as $pInstNode) {
16021617
$type = $pInstNode->getAttribute("type");
@@ -1617,33 +1632,48 @@ public function switchAction($action, $httpVars, $fileVars)
16171632
$addParams .= str_replace("<param", "<global_param group_switch_name=\"${fieldName}\" group_switch_label=\"".$typePlug->getManifestLabel().$checkErrorMessage."\" group_switch_value=\"".$typePlug->getId()."\" ", $tParams);
16181633
$addParams .= str_replace("<param", "<global_param", AJXP_XMLWriter::replaceAjxpXmlKeywords($typePlug->getManifestRawContent("server_settings/param[@group_switch_name]")));
16191634
$addParams .= AJXP_XMLWriter::replaceAjxpXmlKeywords($typePlug->getManifestRawContent("server_settings/global_param"));
1635+
$instancesDefs = $typePlug->getConfigsDefinitions();
1636+
if(!empty($instancesDefs) && is_array($instancesDefs)) {
1637+
foreach($instancesDefs as $defKey => $defData){
1638+
$instancesDefinitions[$fieldName."/".$defKey] = $defData;
1639+
}
1640+
}
16201641
}
16211642
}
16221643
$allParams = AJXP_XMLWriter::replaceAjxpXmlKeywords($fullManifest->ownerDocument->saveXML($fullManifest));
16231644
$allParams = str_replace('type="plugin_instance:', 'type="group_switch:', $allParams);
16241645
$allParams = str_replace("</server_settings>", $addParams."</server_settings>", $allParams);
16251646

16261647
echo($allParams);
1627-
$definitions = $ajxpPlugin->getConfigsDefinitions();
1648+
$definitions = $ajxpPlugin->getConfigsDefinitions() + $instancesDefinitions;
16281649
$values = $ajxpPlugin->getConfigs();
16291650
if(!is_array($values)) $values = array();
16301651
echo("<plugin_settings_values>");
1652+
// First flatten keys
1653+
$flattenedKeys = array();
1654+
foreach ($values as $key => $value){
1655+
$type = $definitions[$key]["type"];
1656+
if ((strpos($type, "group_switch:") === 0 || strpos($type, "plugin_instance:") === 0 ) && is_array($value)) {
1657+
$res = array();
1658+
$this->flattenKeyValues($res, $definitions, $value, $key);
1659+
$flattenedKeys += $res;
1660+
// Replace parent key by new flat value
1661+
$values[$key] = $flattenedKeys[$key];
1662+
}
1663+
}
1664+
$values += $flattenedKeys;
1665+
16311666
foreach ($values as $key => $value) {
16321667
$attribute = true;
16331668
$type = $definitions[$key]["type"];
16341669
if ($type == "array" && is_array($value)) {
16351670
$value = implode(",", $value);
1636-
} else if ((strpos($type, "group_switch:") === 0 || strpos($type, "plugin_instance:") === 0 ) && is_array($value)) {
1637-
$res = array();
1638-
$this->flattenKeyValues($res, $value, $key);
1639-
foreach ($res as $newKey => $newVal) {
1640-
echo("<param name=\"$newKey\" value=\"".AJXP_Utils::xmlEntities($newVal)."\"/>");
1641-
}
1642-
continue;
16431671
} else if ($type == "boolean") {
16441672
$value = ($value === true || $value === "true" || $value == 1?"true":"false");
16451673
} else if ($type == "textarea") {
16461674
$attribute = false;
1675+
} else if ($type == "password" && !empty($value)){
1676+
$value = "__AJXP_VALUE_SET__";
16471677
}
16481678
if ($attribute) {
16491679
echo("<param name=\"$key\" value=\"".AJXP_Utils::xmlEntities($value)."\"/>");
@@ -1692,6 +1722,9 @@ public function switchAction($action, $httpVars, $fileVars)
16921722
$options = array();
16931723
$this->parseParameters($httpVars, $options, null, true);
16941724
$confStorage = ConfService::getConfStorageImpl();
1725+
list($pType, $pName) = explode(".", $httpVars["plugin_id"]);
1726+
$existing = $confStorage->loadPluginConfig($pType, $pName);
1727+
$this->mergeExistingParameters($options, $existing);
16951728
$confStorage->savePluginConfig($httpVars["plugin_id"], $options);
16961729
AJXP_PluginsService::clearPluginsCache();
16971730
AJXP_XMLWriter::header();
@@ -2404,22 +2437,40 @@ public function updateUserRole($userId, $roleId, $addOrRemove, $updateSubUsers =
24042437
}
24052438

24062439

2407-
public function parseParameters(&$repDef, &$options, $userId = null, $globalBinaries = false)
2440+
protected function parseParameters(&$repDef, &$options, $userId = null, $globalBinaries = false, $existingValues = array())
24082441
{
24092442
AJXP_Utils::parseStandardFormParameters($repDef, $options, $userId, "DRIVER_OPTION_", ($globalBinaries?array():null));
2443+
if(!count($existingValues)){
2444+
return;
2445+
}
2446+
$this->mergeExistingParameters($options, $existingValues);
2447+
}
24102448

2449+
protected function mergeExistingParameters(&$parsed, $existing){
2450+
foreach($parsed as $k => &$v){
2451+
if($v === "__AJXP_VALUE_SET__" && isSet($existing[$k])){
2452+
$parsed[$k] = $existing[$k];
2453+
}else if(is_array($v) && is_array($existing[$k])){
2454+
$this->mergeExistingParameters($v, $existing[$k]);
2455+
}
2456+
}
24112457
}
24122458

2413-
public function flattenKeyValues(&$result, $values, $parent = "")
2459+
public function flattenKeyValues(&$result, &$definitions, $values, $parent = "")
24142460
{
24152461
foreach ($values as $key => $value) {
24162462
if (is_array($value)) {
2417-
$this->flattenKeyValues($result, $value, $parent."/".$key);
2463+
$this->flattenKeyValues($result, $definitions, $value, $parent."/".$key);
24182464
} else {
24192465
if ($key == "group_switch_value" || $key == "instance_name") {
24202466
$result[$parent] = $value;
24212467
} else {
24222468
$result[$parent.'/'.$key] = $value;
2469+
if(isSet($definitions[$key])){
2470+
$definitions[$parent.'/'.$key] = $definitions[$key];
2471+
}else if(isSet($definitions[dirname($parent)."/".$key])){
2472+
$definitions[$parent.'/'.$key] = $definitions[dirname($parent)."/".$key];
2473+
}
24232474
}
24242475
}
24252476
}

0 commit comments

Comments
 (0)