X-Git-Url: http://git.dj3c1t.com/?a=blobdiff_plain;f=mw%2Fmw_app.php;h=4355487c0cba27c8dd130c930b0c59c360df3e4c;hb=e038560c5eed39411ef5a761fe32ad8de69982bb;hp=1c18b21f4a3089d2a1b41d2cf4f6b9ef6b7a3b88;hpb=b91d4ed0a098b00708072de6fecd8c5047cb586b;p=mtweb diff --git a/mw/mw_app.php b/mw/mw_app.php index 1c18b21..4355487 100644 --- a/mw/mw_app.php +++ b/mw/mw_app.php @@ -9,10 +9,10 @@ var $config; var $bdd; var $error; - var $DO_SETUP; + var $DO_INSTALL; - function mw_app($path_file, $DO_SETUP = true){ - $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 = ""; @@ -29,13 +29,34 @@ return $this->env; } + function param($name){ + if(!isset($this->env)) return false; + return $this->env->param($name); + } + function init(){ - if(!$this->init_pathes()) return false; - if(!$this->init_config()) return false; - if(!$this->init_env()) return false; - if($this->config_file) return true; - if($this->DO_SETUP) $this->setup(); - return false; + 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){ + if($this->DO_INSTALL){ + $this->install(); + exit; + } + return $this->get_error(); + } + $env = $this->env(); + if(($res = $env->data_upgrade_required()) === true){ + $this->upgrade(); + exit; + } + else{ + if($res !== false){ + $this->error($res); + return $this->get_error(); + } + } + return true; } function init_pathes(){ @@ -52,12 +73,12 @@ $this->error("le fichier des chemins est introuvable"); return false; } - require_once $this->path_file; + require $this->path_file; if( !isset($PATHES) || !is_array($PATHES) ){ - $this->erreur("variable PATHES non defini"); + $this->error("variable PATHES non defini"); return false; } foreach($PATHES as $path_name => $path_value){ @@ -108,7 +129,7 @@ } } else{ - if(!$this->DO_SETUP){ + if(!$this->DO_INSTALL){ $this->error("fichier config.php manquant"); return false; } @@ -142,24 +163,52 @@ $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(); + if(($res = $env->init_data_upgrades()) !== true){ + $this->error("impossible de lire les upgrades. ".$res); + return false; + } return true; } function run($etat = "", $params = array(), $valid_role = true){ $env = $this->env(); if(!is_callable(array($env, "run"))) return false; - $env->run( - $etat ? - $etat - : (isset($_GET[$env->param("e")]) ? $_GET[$env->param("e")] : ""), - $params, - $valid_role - ); + $env->run($etat); 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()){ @@ -169,20 +218,12 @@ } } - 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; } - function show_error(){ - echo $this->error; + function get_error(){ + return isset($this->error) && $this->error ? $this->error : false; } }