From: dj3c1t Date: Fri, 13 Jun 2014 21:08:25 +0000 (+0200) Subject: reorganisation init X-Git-Tag: mtweb.1.0.0~1 X-Git-Url: http://git.dj3c1t.com/index.cgi?a=commitdiff_plain;h=9ee7a4d6f88c5982c43dd7326030149cdd0ac251;p=mtweb reorganisation init --- diff --git a/mw/app/controllers/install/index.php b/mw/app/controllers/install/index.php index 16cc9e4..79734f3 100644 --- a/mw/app/controllers/install/index.php +++ b/mw/app/controllers/install/index.php @@ -191,12 +191,12 @@ if(!$plugin["installed"]){ $env->run("config/plugins/install", array("get" => array("id" => $plugin_name)), false); if($env->erreurs()) return; - $env->init_plugins("DESC", true); + $env->load_plugin($plugin_name); } 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->load_plugin($plugin_name); } } $env->redirect( diff --git a/mw/app/init/0102_data.php b/mw/app/init/0102_data.php deleted file mode 100644 index 9d376e2..0000000 --- a/mw/app/init/0102_data.php +++ /dev/null @@ -1,53 +0,0 @@ -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é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); diff --git a/mw/app/init/0106_init_plugins.php b/mw/app/init/0106_init_plugins.php deleted file mode 100644 index 02cdcff..0000000 --- a/mw/app/init/0106_init_plugins.php +++ /dev/null @@ -1,11 +0,0 @@ -bdd_ready() !== true) return; - if(($plugins = $this->plugins("DESC")) !== false){ - foreach($plugins as $plugin_name => $plugin){ - if($plugin["installed"] && $plugin["enabled"]){ - if(!$plugin["impl"]->init($this)) $this->erreur("erreur lors de l'initialisation du plugin ".$plugin_name, true); - } - } - } - else $this->erreur("erreur lors de l'initialisation des plugins", true); diff --git a/mw/app/init/0100_functions.php b/mw/app/init/0110_functions.php similarity index 100% rename from mw/app/init/0100_functions.php rename to mw/app/init/0110_functions.php diff --git a/mw/app/init/0101_inputs.php b/mw/app/init/0120_inputs.php similarity index 100% rename from mw/app/init/0101_inputs.php rename to mw/app/init/0120_inputs.php diff --git a/mw/app/init/0103_config.php b/mw/app/init/0130_config.php similarity index 99% rename from mw/app/init/0103_config.php rename to mw/app/init/0130_config.php index 20a1d6b..4704fbc 100644 --- a/mw/app/init/0103_config.php +++ b/mw/app/init/0130_config.php @@ -5,9 +5,7 @@ if(($config = $data->config()) === false){ $this->erreur("Impossible de lire la configuration en base", true); } - $this->set_config($config); - $this->set_config( array( "start_action_params" => ( diff --git a/mw/app/init/0104_users.php b/mw/app/init/0140_users.php similarity index 61% rename from mw/app/init/0104_users.php rename to mw/app/init/0140_users.php index 8af3db8..f7e9cbd 100644 --- a/mw/app/init/0104_users.php +++ b/mw/app/init/0140_users.php @@ -5,11 +5,9 @@ if($data->load_session() === false){ $this->erreur("Impossible de charger la session", true); } - if($data->init_roles() === false){ - $this->erreur("Impossible de charger les statuts des utilisateurs", true); + $this->erreur("Impossible de charger les roles des utilisateurs", true); } - if($data->init_actions_roles() === false){ - $this->erreur("Impossible de charger les statuts des actions", true); + $this->erreur("Impossible de charger les roles pour les actions", true); } diff --git a/mw/app/init/0105_links.php b/mw/app/init/0150_links.php similarity index 93% rename from mw/app/init/0105_links.php rename to mw/app/init/0150_links.php index e4a2b27..1a3b705 100644 --- a/mw/app/init/0105_links.php +++ b/mw/app/init/0150_links.php @@ -1,7 +1,5 @@ bdd_ready() !== true) return; - if(!$this->init_links()){ $this->erreur("impossible de charger les liens", true); } diff --git a/mw/env/modules/mw_env_data.php b/mw/env/modules/mw_env_data.php index 7d12265..f0ddeba 100644 --- a/mw/env/modules/mw_env_data.php +++ b/mw/env/modules/mw_env_data.php @@ -12,6 +12,27 @@ return isset($this->data) ? $this->data : false; } + public function load_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_env($this); + $this->set_data($data); + } + } // ------------------------------------------------------------------------------------------- diff --git a/mw/env/modules/mw_env_data_upgrade.php b/mw/env/modules/mw_env_data_upgrade.php index f326bfe..ff5e1b0 100644 --- a/mw/env/modules/mw_env_data_upgrade.php +++ b/mw/env/modules/mw_env_data_upgrade.php @@ -9,7 +9,7 @@ return $this->data_upgrades; } - public function init_data_upgrades(){ + public function load_data_upgrades(){ $impl_dir = ($this->bdd("sgbd") == "xml" ? "xml" : "sql")."/"; $versions_dir = $this->path("mw_dir")."app/data/upgrades/".$impl_dir; if(is_dir($versions_dir)){ @@ -47,7 +47,7 @@ public function data_upgrade_required($RELOAD = false){ if(!isset($this->data_upgrades)){ - if(($res = $this->init_data_upgrades()) !== true){ + if(($res = $this->load_data_upgrades()) !== true){ return $res; } } diff --git a/mw/env/modules/mw_env_init.php b/mw/env/modules/mw_env_init.php index c2975df..773d547 100644 --- a/mw/env/modules/mw_env_init.php +++ b/mw/env/modules/mw_env_init.php @@ -3,6 +3,7 @@ class mw_env_init extends mw_env{ public function init(){ + $data = $this->data(); $init_files = array(); if(($plugins = $this->plugins()) !== false){ foreach($plugins as $plugin_name => $plugin){ diff --git a/mw/env/modules/mw_env_plugins.php b/mw/env/modules/mw_env_plugins.php index 286060f..b8c2854 100644 --- a/mw/env/modules/mw_env_plugins.php +++ b/mw/env/modules/mw_env_plugins.php @@ -6,84 +6,122 @@ public $plugins_desc; public function plugins($PRIORITE = "ASC"){ - $this->init_plugins($PRIORITE); + if(!isset($this->plugins_asc) || !isset($this->plugins_desc)){ + return false; + } if($PRIORITE == "ASC") return $this->plugins_asc; if($PRIORITE == "DESC") return $this->plugins_desc; return false; } + public function plugin($plugin_name){ + if(!isset($this->plugins_asc) || isset($this->plugins_desc)){ + return false; + } + if(!isset($this->plugins_asc[$plugin_name])){ + return false; + } + return $this->plugins_asc[$plugin_name]; + } + # --------------------------------------------------------------------------------- # init # - public function init_plugins($PRIORITE = "ASC", $RELOAD = false){ - if(!$RELOAD && (isset($this->plugins_asc) || isset($this->plugins_desc))){ - if($PRIORITE == "ASC"){ - if(!isset($this->plugins_asc)) $this->plugins_asc = $this->ordonne_plugins($this->plugins_desc, $PRIORITE); - } - elseif($PRIORITE == "DESC"){ - if(!isset($this->plugins_desc)) $this->plugins_desc = $this->ordonne_plugins($this->plugins_asc, $PRIORITE); + public function load_plugins($RELOAD = false){ + if(!$RELOAD && isset($this->plugins_asc) && isset($this->plugins_desc)){ + return true; + } + $this->plugins_asc = array(); + $this->plugins_desc = array(); + if(!($dh = opendir($this->path("mw_dir")."plugins/"))){ + return false; + } + $OK = true; + while($OK && ($plugin_name = readdir($dh)) !== false){ + if(substr($plugin_name, 0 ,1) !== "." && is_dir($this->path("mw_dir")."plugins/".$plugin_name)){ + if(($plugin = $this->load_plugin($plugin_name)) === false){ + $OK = false; + } } - return; } - $plugins = array(); - if($dh = opendir($this->path("mw_dir")."plugins/")){ - $OK = true; - while($OK && ($plugin_name = readdir($dh)) !== false){ - if(substr($plugin_name, 0 ,1) !== "." && is_dir($this->path("mw_dir")."plugins/".$plugin_name)){ - if(!isset($plugins[$plugin_name])){ - if(($plugin = $this->plugin_data($plugin_name)) !== false){ - $MAJ = false; - if(!isset($plugin["installed"]) || !isset($plugin["enabled"])){ - $plugin["installed"] = false; - $plugin["enabled"] = false; - $plugin["priorite"] = 0; - $MAJ = true; - } - if(!$plugin["installed"] && $plugin["enabled"]){ - $plugin["enabled"] = false; - $MAJ = true; - } - if($MAJ) $OK = $this->set_plugin_data($plugin_name, $plugin); - if($OK){ - if(($plugin["impl"] = $this->plugin_impl($plugin_name)) !== false){ - $plugin["title"] = ($plugin_title = $this->plugin_call($plugin["impl"], "title")) ? $plugin_title : ""; - $plugin["description"] = ($plugin_description = $this->plugin_call($plugin["impl"], "description")) ? $plugin_description : ""; - $plugin["name"] = $plugin_name; - $plugins[$plugin_name] = $plugin; - } - } - } - else $OK = false; - } + closedir($dh); + if(!$OK){ + return false; + } + if(($plugins = $this->plugins()) === false){ + return false; + } + if(file_exists($this->plugins_data_dir()) && is_dir($this->plugins_data_dir())){ + if(!($dh = opendir($this->plugins_data_dir()))){ + return false; + } + while(($plugin_name = readdir($dh)) !== false){ + if(substr($plugin_name, 0 ,1) != "." && !is_dir($this->plugin_data_file($plugin_name))){ + if(!isset($plugins[$plugin_name])) $this->del_plugin_data($plugin_name); } - if(!$OK) $plugins = false; } closedir($dh); - if($plugins !== false){ - if(file_exists($this->plugins_data_dir()) && is_dir($this->plugins_data_dir())){ - if($dh = opendir($this->plugins_data_dir())){ - $plugins_data_files = array(); - $OK = true; - while($OK && ($plugin_name = readdir($dh)) !== false){ - if(substr($plugin_name, 0 ,1) != "." && !is_dir($this->plugin_data_file($plugin_name))){ - if(!isset($plugins[$plugin_name])) $this->del_plugin_data($plugin_name); - } - if(!$OK) $plugins = false; - } - closedir($dh); - } - } + } + return true; + } + + public function load_plugin($plugin_name){ + if(substr($plugin_name, 0 ,1) == "." || !is_dir($this->path("mw_dir")."plugins/".$plugin_name)){ + return false; + } + if(($plugin = $this->plugin_data($plugin_name)) === false){ + return false; + } + if(($plugin["impl"] = $this->plugin_impl($plugin_name)) === false){ + return false; + } + $MAJ = false; + if(!isset($plugin["installed"]) || !isset($plugin["enabled"])){ + $plugin["installed"] = false; + $plugin["enabled"] = false; + $plugin["priorite"] = 0; + $MAJ = true; + } + if(!$plugin["installed"] && $plugin["enabled"]){ + $plugin["enabled"] = false; + $MAJ = true; + } + if($MAJ){ + if(!$this->set_plugin_data($plugin_name, $plugin)){ + return false; } } - else $plugins = false; - if($plugins !== false){ - if($PRIORITE == "ASC") $this->plugins_asc = $this->ordonne_plugins($plugins, $PRIORITE); - elseif($PRIORITE == "DESC") $this->plugins_desc = $this->ordonne_plugins($plugins, $PRIORITE); + $plugin["title"] = ($plugin_title = $this->plugin_call($plugin["impl"], "title")) ? $plugin_title : ""; + $plugin["description"] = ($plugin_description = $this->plugin_call($plugin["impl"], "description")) ? $plugin_description : ""; + $plugin["name"] = $plugin_name; + if(!isset($this->plugins_asc)) $this->plugins_asc = array(); + $this->plugins_asc[$plugin_name] = $plugin; + $this->plugins_asc = $this->ordonne_plugins($this->plugins_asc, "ASC"); + $this->plugins_desc = $this->ordonne_plugins($this->plugins_asc, "DESC"); + return $plugin; + } + + public function plugins_loaded(){ + if(($plugins = $this->plugins()) === false){ + return; + } + foreach($plugins as $plugin_name => $plugin){ + $plugin["impl"]->loaded($this); } - else{ - $this->plugins_asc = false; - $this->plugins_desc = false; + } + + public function init_plugins(){ + if($this->bdd_ready() !== true) return; + if(($plugins = $this->plugins("DESC")) === false){ + $this->erreur("erreur lors de l'initialisation des plugins", true); + } + foreach($plugins as $plugin_name => $plugin){ + if($plugin["installed"] && $plugin["enabled"]){ + if(!$plugin["impl"]->init($this)){ + $this->erreur("erreur lors de l'initialisation du plugin ".$plugin_name, true); + } + } } } @@ -114,14 +152,6 @@ if(method_exists($impl, $method)) return $impl->$method($this); } - public function loaded_plugins(){ - if($plugins = $this->plugins()){ - foreach($plugins as $plugin_name => $plugin){ - $plugin["impl"]->loaded($this); - } - } - } - # --------------------------------------------------------------------------------- # impl # diff --git a/mw/env/modules/mw_env_sgbds.php b/mw/env/modules/mw_env_sgbds.php index dfdb74f..97a280a 100644 --- a/mw/env/modules/mw_env_sgbds.php +++ b/mw/env/modules/mw_env_sgbds.php @@ -34,6 +34,33 @@ return $this->sgbds; } + public function load_sgbd(){ + if(($data = $this->data()) && $this->bdd("sgbd")){ + $sgbd_impl_file = $this->path("mw_dir")."env/sgbd/mw_".$this->bdd("sgbd").".php"; + 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ée", true); + } + $data->set_sgbd($sgbd); + } + } + } // ------------------------------------------------------------------------------------------- diff --git a/mw/mw_app.php b/mw/mw_app.php index ba88f24..4e328b7 100644 --- a/mw/mw_app.php +++ b/mw/mw_app.php @@ -167,15 +167,15 @@ $env->load_modules($this->pathes["mw_dir"], "env/modules/"); $env->set_config_file($this->config_file); $env->set_PATHES($this->pathes); - $env->init_plugins(); - $env->load_versions(); + $env->load_plugins(); $env->load_config($this->bdd, $this->config); + $env->load_data(); + $env->load_sgbd(); + $env->plugins_loaded(); + $env->load_versions(); + $env->load_data_upgrades(); $env->init(); - $env->loaded_plugins(); - if(($res = $env->init_data_upgrades()) !== true){ - $this->error("impossible de lire les upgrades. ".$res); - return false; - } + $env->init_plugins(); return true; }