gestion des erreurs en exceptions
[mw_pages] / mw_pages.php
index 19119b9..bb6d9b6 100644 (file)
     function install_sqlite($env){
       $data = $env->data();
       $sgbd = $data->sgbd();
-      $EXISTS = $sgbd->table_exists("#--pages");
-      if(!isset($EXISTS)){
+      try{
+        $EXISTS = $sgbd->table_exists("#--pages");
+      }
+      catch(Exception $e){
         return "impossible de savoir si la table #--pages existe";
       }
       if($EXISTS){
         return "la table #--pages existe deja";
       }
-      $sql =
-       "CREATE TABLE #--pages"
-      ."( id INTEGER NOT NULL PRIMARY KEY"
-      .", id_parent INTEGER NULL"
-      .", title VARCHAR 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"
-      .")";
-      if(!$sgbd->query($sql)){
+      try{
+        $sql =
+         "CREATE TABLE #--pages"
+        ."( id INTEGER NOT NULL PRIMARY KEY"
+        .", id_parent INTEGER NULL"
+        .", title VARCHAR 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"
+        .")";
+        $sgbd->query($sql);
+      }
+      catch(Exception $e){
         return "imposible de creer la table #--pages";
       }
-      if(!$sgbd->query("INSERT INTO #--action_status(action, id_status) VALUES('pages/admin', 1)")){
-        $sgbd->query("DROP TABLE \"main\".\"#--pages\"");
+      $DELETE_TABLE = false;
+      try{
+        $sgbd->query("INSERT INTO #--action_status(action, id_status) VALUES('pages/admin', 1)");
+      }
+      catch(Exception $e){
+        try{
+          $sgbd->query("DROP TABLE \"main\".\"#--pages\"");
+        }
+        catch(Exception $e){}
         return "impossible d'ajouter un statut pour l'action pages/admin";
       }
       return true;
     function install_mysql($env){
       $data = $env->data();
       $sgbd = $data->sgbd();
-      $EXISTS = $sgbd->table_exists("#--pages");
-      if(!isset($EXISTS)){
+      try{
+        $EXISTS = $sgbd->table_exists("#--pages");
+      }
+      catch(Exception $e){
         return "impossible de savoir si la table #--pages existe";
       }
       if($EXISTS){
         return "la table #--pages existe deja";
       }
-      $sql =
-       "CREATE TABLE #--pages"
-      ."( id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY"
-      .", id_parent INT(11) NULL"
-      .", title VARCHAR(255) 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";
-      if(!$sgbd->query($sql)){
+      try{
+        $sql =
+         "CREATE TABLE #--pages"
+        ."( id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY"
+        .", id_parent INT(11) NULL"
+        .", title VARCHAR(255) 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";
+        $sgbd->query($sql);
+      }
+      catch(Exception $e){
         return "imposible de creer la table #--pages";
       }
-      if(!$sgbd->query("INSERT INTO #--action_status(action, id_status) VALUES('pages/admin', 1)")){
-        $sgbd->query("DROP TABLE #--pages");
+      try{
+        $sgbd->query("INSERT INTO #--action_status(action, id_status) VALUES('pages/admin', 1)");
+      }
+      catch(Exception $e){
+        try{
+          $sgbd->query("DROP TABLE #--pages");
+        }
+        catch(Exception $e){}
         return "impossible d'ajouter un statut pour l'action pages/admin";
       }
       return true;
       $sgbd = $data->sgbd();
       if(!$this->disable($env)) return "impossible de desactiver le plugin";
       $data->del_config("plugins_pages_start_id");
-      $EXISTS = $sgbd->table_exists("#--pages");
-      if(!isset($EXISTS)){
+      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";
       }
-      elseif(!$sgbd->query("DROP TABLE \"main\".\"#--pages\"")){
-        return "imposible de supprimer la table #--pages";
+      else{
+        try{
+          $sgbd->query("DROP TABLE \"main\".\"#--pages\"");
+        }
+        catch(Exception $e){
+          return "imposible de supprimer la table #--pages";
+        }
+      }
+      try{
+        $sgbd->query("DELETE FROM #--action_status 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 action_status";
       }
-      $sgbd->query("DELETE FROM #--action_status WHERE action='pages/admin'");
       return true;
     }
 
       $sgbd = $data->sgbd();
       if(!$this->disable($env)) return "impossible de desactiver le plugin";
       $data->del_config("plugins_pages_start_id");
-      $EXISTS = $sgbd->table_exists("#--pages");
-      if(!isset($EXISTS)){
+      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";
       }
-      elseif(!$sgbd->query("DROP TABLE #--pages")){
-        return "imposible de supprimer la table #--pages";
+      else{
+        try{
+          $sgbd->query("DROP TABLE #--pages");
+        }
+        catch(Exception $e){
+          return "imposible de supprimer la table #--pages";
+        }
+      }
+      try{
+        $sgbd->query("DELETE FROM #--action_status 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 action_status";
       }
-      $sgbd->query("DELETE FROM #--action_status WHERE action='pages/admin'");
       return true;
     }