mecanisme d'upgrade
[mtweb] / mw / mw_app.php
index 9af31bc..5349b79 100644 (file)
@@ -9,10 +9,10 @@
     var $config;
     var $bdd;
     var $error;
-    var $DO_SETUP;
+    var $DO_INSTALL;
 
-    function mw_app($path_file, $DO_SETUP = false){
-      $this->DO_SETUP = $DO_SETUP;
+    function mw_app($path_file, $DO_INSTALL = false){
+      $this->DO_INSTALL = $DO_INSTALL;
       $this->path_file = $path_file;
       $this->pathes = array();
       $this->config_file = "";
       if(!$this->init_pathes()) return $this->get_error();
       if(!$this->init_config()) return $this->get_error();
       if(!$this->init_env()) return $this->get_error();
-      if($this->config_file) return true;
-      if($this->DO_SETUP) $this->setup();
-      return $this->get_error();
+      if(!$this->config_file){
+        if($this->DO_INSTALL){
+          $this->install();
+          exit;
+        }
+        return $this->get_error();
+      }
+      $env = $this->env();
+      if($env->data_upgrade_required()){
+        $this->upgrade();
+        exit;
+      }
+      return true;
     }
 
     function init_pathes(){
         }
       }
       else{
-        if(!$this->DO_SETUP){
+        if(!$this->DO_INSTALL){
           $this->error("fichier config.php manquant");
           return false;
         }
       $env->set_config_file($this->config_file);
       $env->set_PATHES($this->pathes);
       $env->init_plugins();
+      $env->load_versions();
       $env->load_config($this->bdd, $this->config);
       $env->init();
+      $env->init_data_upgrades();
       return true;
     }
 
       return true;
     }
   
+    function run_mod($mod_name, $valid_role = true){
+      $env = $this->env();
+      $etat = false;
+      if(isset($_GET[$env->param("e")])){
+        $etat = $env->valid_etat($_GET[$env->param("e")]);
+        if(!$etat || ($etat["mod"] != $mod_name)){
+          $etat = false;
+        }
+      }
+      if(!$etat){
+        $etat = $env->valid_etat($mod_name);
+      }
+      if(!$etat) return false;
+      $env->run($etat, array(), $valid_role);
+      return true;
+    }
+
+    function install(){
+      if($this->run_mod("install", false)){
+        $this->display();
+      }
+    }
+
+    function upgrade(){
+      if($this->run_mod("upgrade", false)){
+        $this->display();
+      }
+    }
+
     function display(){
       $env = $this->env();
       if($env->etat_is_valid()){
       }
     }
 
-    function setup(){
-      $env = $this->env();
-      $etat = isset($_GET[$env->param("e")]) ? $_GET[$env->param("e")] : "install";
-      $env->run($etat, array(), false);
-      $this->display();
-      exit;
-    }
-
     function error($content){
       $this->error = $content;
     }