]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Fix setting multiple config resources at once
authorMarcin Haba <marcin.haba@bacula.pl>
Sun, 28 Apr 2019 11:44:49 +0000 (13:44 +0200)
committerMarcin Haba <marcin.haba@bacula.pl>
Sun, 28 Apr 2019 14:58:31 +0000 (16:58 +0200)
gui/baculum/protected/API/Class/BaculaSetting.php

index 193bd193eb2e1df9d1a23ff759b60a0cf509b64e..95911d1a61cdc62fdb08b2b532651790259af170 100644 (file)
@@ -167,7 +167,7 @@ class BaculaSetting extends APIModule {
                $result = $json_tools->execCommand($component_type, $params);
                if ($result['exitcode'] === 0 && is_array($result['output'])) {
                        $config_orig = $result['output'];
-                       if (!is_null($resource_type)) {
+                       if (!is_null($resource_type) && !is_null($resource_name)) {
                                // Set single resource
                                $config_new = array($resource_type => $config);
                        } else {
@@ -200,7 +200,8 @@ class BaculaSetting extends APIModule {
        }
 
        private function updateConfig(array $config_orig, array $config_new) {
-               $config = array();
+               $config = $config_orig;
+               $updated_res = array();
                for ($i = 0; $i < count($config_new); $i++) {
                        $resource_new = $config_new[$i];
                        $found = false;
@@ -208,7 +209,8 @@ class BaculaSetting extends APIModule {
                                $resource_orig = $config_orig[$j];
                                if ($this->compareResources(array($resource_orig, $resource_new)) === true) {
                                        // Resource type and name are the same. Update directives.
-                                       $config[] = $this->updateResource($resource_orig, $resource_new);
+                                       $config[$j] = $this->updateResource($resource_orig, $resource_new);
+                                       $updated_res[] = $config[$j];
                                        $found = true;
                                        break;
                                }
@@ -218,6 +220,22 @@ class BaculaSetting extends APIModule {
                                $config[] = $resource_new;
                        }
                }
+
+               /**
+                * Now there is needed to update all resources to get
+                * formatted directive values in all config directives.
+                */
+               for ($i = 0; $i < count($config); $i++) {
+                       $resource = $config[$i];
+                       for ($j = 0; $j < count($updated_res); $j++) {
+                               if ($this->compareResources(array($resource, $updated_res[$j])) === true) {
+                                       // skip already formatted resources
+                                       continue 2;
+                               }
+                       }
+                       // Rewrite not modified resource
+                       $config[$i] = $this->updateResource($resource, $resource);
+               }
                return $config;
        }