public attr / function, constructeurs __construct
[mtweb] / mw / app / controllers / install / index.php
index 1decc17..0f7b27c 100644 (file)
@@ -2,16 +2,16 @@
 
   class mw_install_index extends mw_controller{
 
-    var $config_file;
+    public $config_file;
 
-    function validate(){
+    public function validate(){
       $env = $this->env();
       $this->config_file = $env->path("content")."config/config.php";
       if(file_exists($this->config_file)) return "le site est deja installé";
       return true;
     }
 
-    function index(){
+    public function index(){
       $env = $this->env();
       $data = $env->data();
       $admin = array(
@@ -29,7 +29,7 @@
           "#--" => $table_prefix
         )
       );
-      $current_sgbd = "mw_pdo_sqlite";
+      $current_sgbd = isset($sgbds["mw_pdo_sqlite"]) ? "mw_pdo_sqlite" : "mw_xml";
       if($_POST){
         if(!isset($_POST["sgbd"])){
           $env->erreur("Parametre de SGBD manquant");
             $env->erreur("impossible de créer le fichier de configuration");
             return;
           }
+          require_once $this->config_file;
+          if(
+                isset($CONFIG)
+            &&  is_array($CONFIG)
+          ){
+            $env->set_config($CONFIG);
+          }
+          if(
+                isset($bdd)
+            &&  is_array($bdd)
+          ){
+            foreach($bdd as $bdd_key => $bdd_value){
+              if($bdd_key == "table_prefix"){
+                if(!($table_prefix = $env->bdd("table_prefix"))){
+                  $env->erreur("impossible de lire les prefixes de tables");
+                  return;
+                }
+                foreach($table_prefix as $prefix_code => $prefix_value) break;
+                if(!isset($prefix_code)){
+                  $env->erreur("impossible de lire le code pour le prefixe de tables");
+                  return;
+                }
+                $table_prefix[$prefix_code] = $bdd_value;
+                $env->add_table_prefix($table_prefix);
+              }
+              else{
+                $env->set_bdd($bdd_key, $bdd_value);
+              }
+            }
+          }
+          if(($plugins = $env->plugins("DESC")) === false){
+            $env->erreur("impossible de lister les plugins");
+          }
+          foreach($plugins as $plugin_name => $plugin){
+            if(!$plugin["installed"]){
+              $env->run("config/plugins/install", array("get" => array("id" => $plugin_name)), false);
+              if($env->erreurs()) return;
+              $env->init_plugins("DESC", true);
+            }
+            if(!$plugin["enabled"]){
+              $env->run("config/plugins/enable", array("get" => array("id" => $plugin_name)), false);
+              if($env->erreurs()) return;
+              $env->init_plugins("DESC", true);
+            }
+          }
           $env->redirect(
             $env->url(),
             "le site a été installé"
     }
 
   }
-
-?>
\ No newline at end of file