maj version 1.2.0 dans config
[mw_sourceml] / mw_sourceml.php
index 301f9ca..286c455 100644 (file)
       return "Publication de sources musicales";
     }
 
+    function loaded($env){
+      $AUTO_ACTIVATE = false;
+      if(!$env->bdd("sgbd") || ($plugin_data = $env->plugin_data("mw_sourceml")) === false) return;
+      if(!isset($plugin_data["installed"]) || !$plugin_data["installed"]){
+        $data = $env->data();
+        $sgbd = $data->sgbd();
+        if($env->bdd("sgbd") == "xml"){
+          $AUTO_ACTIVATE = $sgbd->data_exists("sources");
+        }
+        else{
+          $AUTO_ACTIVATE = $sgbd->table_exists("#--sources");
+        }
+      }
+      if($AUTO_ACTIVATE){
+        if(
+          $env->set_plugin_data(
+            "mw_sourceml",
+            array(
+              "installed" => true,
+              "enabled" => true,
+              "priorite" => 0
+            )
+          )
+        ){
+          $env->init_plugins("ASC", $RELOAD = true);
+        }
+      }
+    }
+
     function init($env){
 
       $env->set_link("admin/sourceml", $env->url("admin/sourceml"), "SourceML", 50);
     }
 
     function enable($env){
+      $data = $env->data();
+      if(
+            ($data->config("site_name") == "mtweb")
+        &&  (($plugins = $env->plugins()) !== false)
+        &&  (count($plugins) == 1)
+      ){
+        $data->set_config("site_name", "SourceML");
+      }
       return true;
     }
 
     function disable($env){
+      $data = $env->data();
+      if(
+            ($data->config("site_name") == "SourceML")
+        &&  (($plugins = $env->plugins()) !== false)
+        &&  (count($plugins) == 1)
+      ){
+        $data->set_config("site_name", "mtweb");
+      }
       return true;
     }
 
     function install($env){
       $data = $env->data();
-
+      $res = true;
       if(
             $env->bdd("sgbd") == "mysql"
         ||  $env->bdd("sgbd") == "pdo_mysql"
       ){
         $data->load_modules($env->path("mw_dir")."plugins/mw_sourceml/app/", "data/modules/sql/");
-        return $data->mw_sourceml_install_mysql($this, $env);
+        $res = $data->mw_sourceml_install_mysql($this, $env);
       }
       elseif(
             $env->bdd("sgbd") == "pdo_sqlite"
       ){
         $data->load_modules($env->path("mw_dir")."plugins/mw_sourceml/app/", "data/modules/sql/");
-        return $data->mw_sourceml_install_sqlite($this, $env);
+        $res = $data->mw_sourceml_install_sqlite($this, $env);
       }
       elseif(
             $env->bdd("sgbd") == "xml"
       ){
         $data->load_modules($env->path("mw_dir")."plugins/mw_sourceml/app/", "data/modules/xml/");
-        return $data->mw_sourceml_install_xml($this, $env);
+        $res = $data->mw_sourceml_install_xml($this, $env);
+      }
+      else{
+        $res = "Mode de stockage pour Mtweb (".$env->bdd("sgbd").") non supporté par SourceML";
       }
-      return "Mode de stockage pour Mtweb (".$env->bdd("sgbd").") non supporté par SourceML";
+      return $res;
     }
 
     function uninstall($env){
       $data = $env->data();
+      $res = true;
       if(
             $env->bdd("sgbd") == "mysql"
         ||  $env->bdd("sgbd") == "pdo_mysql"
         ||  $env->bdd("sgbd") == "pdo_sqlite"
       ){
         $data->load_modules($env->path("mw_dir")."plugins/mw_sourceml/app/", "data/modules/sql/");
-        return $data->mw_sourceml_uninstall_sql($this, $env);
+        $res = $data->mw_sourceml_uninstall_sql($this, $env);
       }
-      if(
+      elseif(
             $env->bdd("sgbd") == "xml"
       ){
         $data->load_modules($env->path("mw_dir")."plugins/mw_sourceml/app/", "data/modules/xml/");
-        return $data->mw_sourceml_uninstall_xml($this, $env);
+        $res = $data->mw_sourceml_uninstall_xml($this, $env);
+      }
+      else{
+        $res = "Mode de stockage pour Mtweb (".$env->bdd("sgbd").") non supporté par SourceML";
       }
-      return "Mode de stockage pour Mtweb (".$env->bdd("sgbd").") non supporté par SourceML";
+      return $res;
     }
 
   }