reorganisation init
authordj3c1t <dj3c1t@free.fr>
Fri, 13 Jun 2014 21:08:25 +0000 (23:08 +0200)
committerdj3c1t <dj3c1t@free.fr>
Fri, 13 Jun 2014 21:13:29 +0000 (23:13 +0200)
14 files changed:
mw/app/controllers/install/index.php
mw/app/init/0102_data.php [deleted file]
mw/app/init/0106_init_plugins.php [deleted file]
mw/app/init/0110_functions.php [moved from mw/app/init/0100_functions.php with 100% similarity]
mw/app/init/0120_inputs.php [moved from mw/app/init/0101_inputs.php with 100% similarity]
mw/app/init/0130_config.php [moved from mw/app/init/0103_config.php with 99% similarity]
mw/app/init/0140_users.php [moved from mw/app/init/0104_users.php with 61% similarity]
mw/app/init/0150_links.php [moved from mw/app/init/0105_links.php with 93% similarity]
mw/env/modules/mw_env_data.php
mw/env/modules/mw_env_data_upgrade.php
mw/env/modules/mw_env_init.php
mw/env/modules/mw_env_plugins.php
mw/env/modules/mw_env_sgbds.php
mw/mw_app.php

index 16cc9e4..79734f3 100644 (file)
             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 (file)
index 9d376e2..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-<?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);
diff --git a/mw/app/init/0106_init_plugins.php b/mw/app/init/0106_init_plugins.php
deleted file mode 100644 (file)
index 02cdcff..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-<?php
-
-  if($this->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);
similarity index 99%
rename from mw/app/init/0103_config.php
rename to mw/app/init/0130_config.php
index 20a1d6b..4704fbc 100644 (file)
@@ -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" => (
similarity index 61%
rename from mw/app/init/0104_users.php
rename to mw/app/init/0140_users.php
index 8af3db8..f7e9cbd 100644 (file)
@@ -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);
   }
similarity index 93%
rename from mw/app/init/0105_links.php
rename to mw/app/init/0150_links.php
index e4a2b27..1a3b705 100644 (file)
@@ -1,7 +1,5 @@
 <?php
 
-  if($this->bdd_ready() !== true) return;
-
   if(!$this->init_links()){
     $this->erreur("impossible de charger les liens", true);
   }
index 7d12265..f0ddeba 100644 (file)
       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);
+    }
+
   }
 
   // -------------------------------------------------------------------------------------------
index f326bfe..ff5e1b0 100644 (file)
@@ -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;
         }
       }
index c2975df..773d547 100644 (file)
@@ -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){
index 286060f..b8c2854 100644 (file)
     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);
+          }
+        }
       }
     }
 
       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
     #
index dfdb74f..97a280a 100644 (file)
       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&eacute;e", true);
+        }
+        $data->set_sgbd($sgbd);
+      }
+    }
+
   }
 
   // -------------------------------------------------------------------------------------------
index ba88f24..4e328b7 100644 (file)
       $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;
     }