);
$LIMIT = isset($max) ? " LIMIT ".$max.(isset($start) ? " OFFSET ".$start : "") : "";
$sql = $COUNT_SELECT.$WHERE;
- $rst = $sgbd->query($sql);
- if(!isset($rst)) return false;
- if($v_rst = $sgbd->fetch_assoc($rst)) $pages["total"] = $v_rst["n"];
- $sgbd->free_result($rst);
- if($pages["total"]){
- $sql = $SELECT.$WHERE.$ORDER_BY.$LIMIT;
+ try{
$rst = $sgbd->query($sql);
- if(!isset($rst)) return false;
- while($v_rst = $sgbd->fetch_assoc($rst)) $pages["list"][$v_rst["id"]] = $v_rst;
+ if($v_rst = $sgbd->fetch_assoc($rst)) $pages["total"] = $v_rst["n"];
$sgbd->free_result($rst);
+ if($pages["total"]){
+ $sql = $SELECT.$WHERE.$ORDER_BY.$LIMIT;
+ $rst = $sgbd->query($sql);
+ while($v_rst = $sgbd->fetch_assoc($rst)) $pages["list"][$v_rst["id"]] = $v_rst;
+ $sgbd->free_result($rst);
+ }
}
+ catch(Exception $e) { $pages = false; }
return $pages;
}
: ""
);
$sql = $SELECT.$WHERE.$ORDER_BY;
- $rst = $sgbd->query($sql);
- if(!isset($rst)) return false;
- while($v_rst = $sgbd->fetch_assoc($rst)){
- $params["id_parent"] = $v_rst["id"];
- $arbo["subs"][] = $this->pages_arbo($params);
+ try{
+ $rst = $sgbd->query($sql);
+ while($v_rst = $sgbd->fetch_assoc($rst)){
+ $params["id_parent"] = $v_rst["id"];
+ $arbo["subs"][] = $this->pages_arbo($params);
+ }
+ $sgbd->free_result($rst);
}
- $sgbd->free_result($rst);
+ catch(Exception $e) { $arbo = false; }
return $arbo;
}
$page = array();
$sgbd = $this->sgbd();
$sql = "SELECT * FROM #--pages WHERE id=".$this->eq($id);
- $rst = $sgbd->query($sql);
- if(!isset($rst)) return false;
- if($v_rst = $sgbd->fetch_assoc($rst)) $page = $v_rst;
+ try{
+ $rst = $sgbd->query($sql);
+ if($v_rst = $sgbd->fetch_assoc($rst)) $page = $v_rst;
+ $sgbd->free_result($rst);
+ }
+ catch(Exception $e) { $page = false; }
return $page;
}
.", ".$this->eq($enabled)
.", ".$this->eq($position)
.")";
- if($sgbd->query($sql)) return $sgbd->insert_id();
- return false;
+ try{
+ $sgbd->query($sql);
+ $id_page = $sgbd->insert_id();
+ }
+ catch(Exception $e) { $id_page = false; }
+ return $id_page;
}
function set_page($id, $params, $RAZ = false){
.", enabled=".$this->eq($enabled)
.", position=".$this->eq($position)
." WHERE id=".$this->eq($id);
- if($sgbd->query($sql)) return true;
+ try{
+ $sgbd->query($sql);
+ }
+ catch(Exception $e) { return false; }
+ return true;
}
return false;
}
function del_page($id){
$sgbd = $this->sgbd();
- if($sgbd->query("DELETE FROM #--pages WHERE id=".$this->eq($id))){
- return $sgbd->query("UPDATE #--pages SET id_parent=NULL WHERE id_parent=".$this->eq($id)) ? true : false;
+ try{
+ $sgbd->query("UPDATE #--pages SET id_parent=NULL WHERE id_parent=".$this->eq($id));
+ $sgbd->query("DELETE FROM #--pages WHERE id=".$this->eq($id));
}
- return false;
+ catch(Exception $e) { return false; }
+ return true;
}
}
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;
}