re-orga num. dans init
[mtweb] / mw / app / init / 0102_data.php
diff --git a/mw/app/init/0102_data.php b/mw/app/init/0102_data.php
new file mode 100644 (file)
index 0000000..9d376e2
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+
+  // -------------------------------------------------------------------------
+  //                                                                      sgbd
+  //
+
+  $sgbd_impl_file = $this->path("mw_dir")."env/sgbd/mw_".$this->bdd("sgbd").".php";
+  if($this->bdd("sgbd")){
+    if(!file_exists($sgbd_impl_file)){
+      $this->erreur("Impossible de trouver le fichier d'implementation du sgbd ".$this->bdd("sgbd"), true);
+    }
+    $sgbd_impl = "mw_".$this->bdd("sgbd");
+    if(!class_exists($sgbd_impl)) require_once $sgbd_impl_file;
+    if(!class_exists($sgbd_impl)){
+      $this->erreur("Impossible de trouver la classe d'implementation du sgbd ".$this->bdd("sgbd"), true);
+    }
+    $sgbd = new $sgbd_impl(
+      $this,
+      array(
+        "host" => $this->bdd("host"),
+        "base" => $this->bdd("base"),
+        "user" => $this->bdd("user"),
+        "password" => $this->bdd("password")
+      )
+    );
+    if(!$sgbd->extention_ok()){
+      $this->erreur("L'extention php ".$this->bdd("sgbd")." n'est pas install&eacute;e", true);
+    }
+  }
+
+  // -------------------------------------------------------------------------
+  //                                                                      data
+  //
+
+  if(($plugins = $this->plugins("DESC")) === false){
+    $this->erreur("Impossible de lire les plugins pour charger les modules de donnees", true);
+  }
+  $data = new mw_data(true);
+  foreach($plugins as $plugin_name => $plugin){
+    if($plugin["installed"] && $plugin["enabled"]){
+      $data->load_modules($this->path("mw_dir")."plugins/".$plugin_name."/app/", "data/modules/share/");
+      if($this->bdd("sgbd")){
+        $data->load_modules($this->path("mw_dir")."plugins/".$plugin_name."/app/", "data/modules/".($this->bdd("sgbd") == "xml" ? "xml" : "sql")."/");
+      }
+    }
+  }
+  $data->load_modules($this->path("mw_dir")."app/", "data/modules/share/");
+  if($this->bdd("sgbd")){
+    $data->load_modules($this->path("mw_dir")."app/", "data/modules/".($this->bdd("sgbd") == "xml" ? "xml" : "sql")."/");
+    $data->set_sgbd($sgbd);
+  }
+  $data->set_env($this);
+  $this->set_data($data);