delegation tiny_mce et install pour sqlite
[mw_pages] / mw_pages.php
index d1c1664..c33eb05 100644 (file)
     //
 
     function install($env){
-      if($env->bdd("sgbd") == "xml") return $this->install_xml($env);
-      if($env->bdd("sgbd") == "sqlite") return $this->install_sqlite($env);
-      if($env->bdd("sgbd") == "mysql") return $this->install_mysql($env);
-    }
-
-    function install_xml($env){
-      $data = $env->data();
-      $sgbd = $data->sgbd();
-      $EXISTS = $sgbd->data_exists("pages");
-      if(!isset($EXISTS)){
-        return "impossible de savoir si la table #--pages existe";
+      if(
+            $env->bdd("sgbd") == "mysql"
+        ||  $env->bdd("sgbd") == "pdo_mysql"
+      ){
+        return $this->install_mysql($env);
       }
-      if($EXISTS){
-        return "la table #--pages existe deja";
+      elseif(
+            $env->bdd("sgbd") == "pdo_sqlite"
+      ){
+        return $this->install_sqlite($env);
       }
-      if(!$sgbd->create_data("pages")){
-        return "imposible de creer la table #--pages";
+      elseif(
+            $env->bdd("sgbd") == "xml"
+      ){
+        return $this->install_xml($env);
       }
-      if(!$sgbd->add_data("actions_roles", array("action" => "pages/admin", "id_role" => "1"))){
-        $sgbd->remove_data("pages");
-        return "impossible d'ajouter un statut pour l'action pages/admin";
+      else{
+        return "Mode de stockage pour Mtweb (".$env->bdd("sgbd").") non supporté par mw_pages";
       }
       return true;
     }
 
-    function install_sqlite($env){
+    function install_mysql($env){
       $data = $env->data();
       $sgbd = $data->sgbd();
       try{
       try{
         $sql =
          "CREATE TABLE #--pages"
-        ."( id INTEGER NOT NULL PRIMARY KEY"
-        .", id_parent INTEGER NULL"
-        .", title VARCHAR NULL"
+        ."( id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY"
+        .", id_parent INT(11) NULL"
+        .", title VARCHAR(255) NULL"
         .", content TEXT NULL"
-        .", date_creation TEXT NOT NULL"
-        .", user_creation INTEGER NOT NULL"
-        .", date_last_update TEXT NOT NULL"
-        .", user_last_update INTEGER NOT NULL"
-        .", enabled INTEGER NOT NULL DEFAULT 1"
-        .", position INTEGER NOT NULL DEFAULT 0"
-        .")";
+        .", date_creation DATETIME NOT NULL"
+        .", user_creation INT(11) NOT NULL"
+        .", date_last_update DATETIME NOT NULL"
+        .", user_last_update INT(11) NOT NULL"
+        .", enabled TINYINT NOT NULL DEFAULT '1'"
+        .", position INT(11) NOT NULL DEFAULT '0'"
+        .") DEFAULT CHARSET=utf8";
         $sgbd->query($sql);
       }
       catch(Exception $e){
         return "imposible de creer la table #--pages";
       }
-      $DELETE_TABLE = false;
       try{
         $sgbd->query("INSERT INTO #--actions_roles(action, id_role) VALUES('pages/admin', 1)");
       }
       catch(Exception $e){
         try{
-          $sgbd->query("DROP TABLE \"main\".\"#--pages\"");
+          $sgbd->query("DROP TABLE #--pages");
         }
         catch(Exception $e){}
         return "impossible d'ajouter un statut pour l'action pages/admin";
       return true;
     }
 
-    function install_mysql($env){
+    function install_sqlite($env){
       $data = $env->data();
       $sgbd = $data->sgbd();
       try{
       }
       try{
         $sql =
-         "CREATE TABLE #--pages"
-        ."( id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY"
-        .", id_parent INT(11) NULL"
-        .", title VARCHAR(255) NULL"
+         "CREATE TABLE #--pages("
+        ." `id` INTEGER PRIMARY KEY AUTOINCREMENT"
+        .", id_parent INTEGER NULL"
+        .", title TEXT NULL"
         .", content TEXT NULL"
-        .", date_creation DATETIME NOT NULL"
-        .", user_creation INT(11) NOT NULL"
-        .", date_last_update DATETIME NOT NULL"
-        .", user_last_update INT(11) NOT NULL"
-        .", enabled TINYINT NOT NULL DEFAULT '1'"
-        .", position INT(11) NOT NULL DEFAULT '0'"
-        .") DEFAULT CHARSET=utf8";
+        .", date_creation TEXT NOT NULL"
+        .", user_creation INTEGER NOT NULL"
+        .", date_last_update TEXT NOT NULL"
+        .", user_last_update INTEGER NOT NULL"
+        .", enabled INTEGER NOT NULL DEFAULT '1'"
+        .", position INTEGER NOT NULL DEFAULT '0'"
+        .")";
         $sgbd->query($sql);
       }
       catch(Exception $e){
       return true;
     }
 
+    function install_xml($env){
+      $data = $env->data();
+      $sgbd = $data->sgbd();
+      $EXISTS = $sgbd->data_exists("pages");
+      if(!isset($EXISTS)){
+        return "impossible de savoir si la table #--pages existe";
+      }
+      if($EXISTS){
+        return "la table #--pages existe deja";
+      }
+      if(!$sgbd->create_data("pages")){
+        return "imposible de creer la table #--pages";
+      }
+      if(!$sgbd->add_data("actions_roles", array("action" => "pages/admin", "id_role" => "1"))){
+        $sgbd->remove_data("pages");
+        return "impossible d'ajouter un statut pour l'action pages/admin";
+      }
+      return true;
+    }
+
     // ---------------------------------------------------------------------------------
     //                                                                         uninstall
     //
 
     function uninstall($env){
       if($env->bdd("sgbd") == "xml") return $this->uninstall_xml($env);
-      if($env->bdd("sgbd") == "sqlite") return $this->uninstall_sqlite($env);
-      if($env->bdd("sgbd") == "mysql") return $this->uninstall_mysql($env);
+      else return $this->uninstall_sql($env);
     }
 
     function uninstall_xml($env){
       return true;
     }
 
-    function uninstall_sqlite($env){
-      $data = $env->data();
-      $sgbd = $data->sgbd();
-      if(!$this->disable($env)) return "impossible de desactiver le plugin";
-      $data->del_config("plugins_pages_start_id");
-      try{
-        $EXISTS = $sgbd->table_exists("#--pages");
-      }
-      catch(Exception $e){
-        return "impossible de savoir si la table #--pages existe";
-      }
-      if(!$EXISTS){
-        // return "la table #--pages n'existe pas";
-      }
-      else{
-        try{
-          $sgbd->query("DROP TABLE \"main\".\"#--pages\"");
-        }
-        catch(Exception $e){
-          return "imposible de supprimer la table #--pages";
-        }
-      }
-      try{
-        $sgbd->query("DELETE FROM #--actions_roles WHERE action='pages/admin'");
-      }
-      catch(Exception $e){
-        return
-         "Le plugin a bien été désinstallé"
-        ." mais impossible d'enlever les droits pages/admin/* de la table actions_roles";
-      }
-      return true;
-    }
-
-    function uninstall_mysql($env){
+    function uninstall_sql($env){
       $data = $env->data();
       $sgbd = $data->sgbd();
       if(!$this->disable($env)) return "impossible de desactiver le plugin";