nouveau module "models" dans l'environnement
[mtweb] / mw / app / data / modules / share / mw_data_check_instance.php
index b471eaa..82f5a98 100644 (file)
@@ -3,9 +3,47 @@
   class mw_data_check_instance extends mw_data{
 
     function check_instance(){
+//      return $this->check_instance_normalise_config();
       return true;
     }
 
+    function check_instance_normalise_config(){
+      $env = $this->env();
+      if($env->bdd("sgbd") == "xml"){
+        debug("start normalise config");
+        $data = $env->data();
+        $sgbd = $data->sgbd();
+        $configs = array();
+        $erreur = false;
+        if($rst = $sgbd->open_data("config")){
+          while($v_rst = $sgbd->fetch_data($rst)){
+            if(!isset($v_rst)){
+              $erreur = "erreur lors de la lecture de la configuration (check_instance)";
+              break;
+            }
+            if(!isset($v_rst["key"]) || !isset($v_rst["value"])){
+              foreach($v_rst as $config_key => $config_value){
+                $configs[$v_rst["id"]] = array(
+                  "key" => $config_key,
+                  "value" => $config_value
+                );
+                break;
+              }
+            }
+          }
+          $sgbd->close_data($rst);
+        }
+        else return "impossible de lire la configuration (check_instance)";
+        if($erreur) return $erreur;
+        foreach($configs as $config_id => $config){
+          if(!$sgbd->set_data("config", $config_id, $config)){
+            return "erreur lors de l'enregistrement de la configuration";
+          }
+        }
+        return "end normalise config";
+      }
+    }
+
   }
 
 ?>
\ No newline at end of file