bdd("sgbd") == "mysql" || $env->bdd("sgbd") == "pdo_mysql" ){ return $this->install_mysql($env); } elseif( $env->bdd("sgbd") == "pdo_sqlite" ){ return $this->install_sqlite($env); } elseif( $env->bdd("sgbd") == "xml" ){ return $this->install_xml($env); } else{ return "Mode de stockage pour Mtweb (".$env->bdd("sgbd").") non supporté par mw_thumbs"; } return true; } public function install_mysql($env){ $data = $env->data(); $sgbd = $data->sgbd(); try{ $EXISTS = $sgbd->table_exists("#--thumbs"); } catch(Exception $e){ return "impossible de savoir si la table #--thumbs existe"; } if($EXISTS){ return "la table #--thumbs existe deja"; } try{ $sql = "CREATE TABLE #--thumbs(" ." `id` int(11) NOT NULL AUTO_INCREMENT," ." `src` varchar(255) NOT NULL DEFAULT ''," ." `src_width` int(11) NOT NULL DEFAULT '0'," ." `src_height` int(11) NOT NULL DEFAULT '0'," ." `max_width` int(11) NOT NULL DEFAULT '0'," ." `max_height` int(11) NOT NULL DEFAULT '0'," ." `thumb_file` varchar(255) NOT NULL," ." `thumb_width` int(11) NOT NULL DEFAULT '0'," ." `thumb_height` int(11) NOT NULL DEFAULT '0'," ." `creation_date` datetime NOT NULL," ." PRIMARY KEY (`id`)" .")"; $sgbd->query($sql); } catch(Exception $e){ return "imposible de creer la table #--thumbs"; } return true; } public function install_sqlite($env){ $data = $env->data(); $sgbd = $data->sgbd(); try{ $EXISTS = $sgbd->table_exists("#--thumbs"); } catch(Exception $e){ return "impossible de savoir si la table #--thumbs existe"; } if($EXISTS){ return "la table #--thumbs existe deja"; } try{ $sql = "CREATE TABLE #--thumbs(" ." `id` INTEGER PRIMARY KEY AUTOINCREMENT," ." `src` TEXT NOT NULL DEFAULT ''," ." `src_width` INTEGER NOT NULL DEFAULT '0'," ." `src_height` INTEGER NOT NULL DEFAULT '0'," ." `max_width` INTEGER NOT NULL DEFAULT '0'," ." `max_height` INTEGER NOT NULL DEFAULT '0'," ." `thumb_file` TEXT NOT NULL," ." `thumb_width` INTEGER NOT NULL DEFAULT '0'," ." `thumb_height` INTEGER NOT NULL DEFAULT '0'," ." `creation_date` TEXT NOT NULL" .")"; $sgbd->query($sql); } catch(Exception $e){ return "imposible de creer la table #--thumbs"; } return true; } public function install_xml($env){ $data = $env->data(); $sgbd = $data->sgbd(); $EXISTS = $sgbd->data_exists("thumbs"); if(!isset($EXISTS)){ return "impossible de savoir si la table #--thumbs existe"; } if($EXISTS){ return "la table #--thumbs existe deja"; } if(!$sgbd->create_data("thumbs")){ return "imposible de creer la table #--thumbs"; } return true; } function uninstall($env){ if($env->bdd("sgbd") == "xml") return $this->uninstall_xml($env); else return $this->uninstall_sql($env); } public function uninstall_xml($env){ $data = $env->data(); $sgbd = $data->sgbd(); if(!$this->disable($env)) return "impossible de desactiver le plugin"; $EXISTS = $sgbd->data_exists("thumbs"); if(!isset($EXISTS)){ return "impossible de savoir si la table #--thumbs existe"; } if(!$EXISTS){ // return "la table #--thumbs n'existe pas"; } elseif(!$sgbd->remove_data("thumbs")){ return "imposible de supprimer la table #--thumbs"; } return true; } public function uninstall_sql($env){ $data = $env->data(); $sgbd = $data->sgbd(); if(!$this->disable($env)) return "impossible de desactiver le plugin"; try{ $EXISTS = $sgbd->table_exists("#--thumbs"); } catch(Exception $e){ return "impossible de savoir si la table #--thumbs existe"; } if(!$EXISTS){ // return "la table #--thumbs n'existe pas"; } else{ try{ $sgbd->query("DROP TABLE #--thumbs"); } catch(Exception $e){ return "imposible de supprimer la table #--thumbs"; } } return true; } }