From 29c6fd460700e67fa538af337dcfce2787f2cc4e Mon Sep 17 00:00:00 2001 From: nicosomb Date: Tue, 23 Apr 2013 09:38:57 +0200 Subject: [PATCH] messages d'erreur si pas possible d'ajouter ou de supprimer un lien --- inc/functions.php | 35 +++++++++++++++++++++++------------ inc/store/sqlite.class.php | 2 ++ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/inc/functions.php b/inc/functions.php index 205f396..750d430 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -125,8 +125,6 @@ function prepare_url($url) } } - $msg->add('e', 'error during url preparation'); - logm('error during url preparation'); return FALSE; } @@ -311,26 +309,39 @@ function action_to_do($action, $url, $id = 0) if (MyTool::isUrl($url)) { if($parametres_url = prepare_url($url)) { - $store->add($url, $parametres_url['title'], $parametres_url['content']); - $last_id = $store->getLastId(); - if (DOWNLOAD_PICTURES) { - $content = filtre_picture($parametres_url['content'], $url, $last_id); + if ($store->add($url, $parametres_url['title'], $parametres_url['content'])) { + $last_id = $store->getLastId(); + if (DOWNLOAD_PICTURES) { + $content = filtre_picture($parametres_url['content'], $url, $last_id); + } + $msg->add('s', 'the link has been added successfully'); } - $msg->add('s', 'the link has been added successfully'); + else { + $msg->add('e', 'error during insertion : the link wasn\'t added'); + } + } + else { + $msg->add('e', 'error during url preparation : the link wasn\'t added'); + logm('error during url preparation'); } } else { - $msg->add('e', 'the link has been added successfully'); + $msg->add('e', 'error during url preparation : the link is not valid'); logm($url . ' is not a valid url'); } logm('add link ' . $url); break; case 'delete': - remove_directory(ABS_PATH . $id); - $store->deleteById($id); - $msg->add('s', 'the link has been deleted successfully'); - logm('delete link #' . $id); + if ($store->deleteById($id)) { + remove_directory(ABS_PATH . $id); + $msg->add('s', 'the link has been deleted successfully'); + logm('delete link #' . $id); + } + else { + $msg->add('e', 'the link wasn\'t deleted'); + logm('error : can\'t delete link #' . $id); + } break; case 'toggle_fav' : $store->favoriteById($id); diff --git a/inc/store/sqlite.class.php b/inc/store/sqlite.class.php index d5208a2..cda412e 100644 --- a/inc/store/sqlite.class.php +++ b/inc/store/sqlite.class.php @@ -107,6 +107,7 @@ class Sqlite extends Store { $sql_action = 'INSERT INTO entries ( url, title, content ) VALUES (?, ?, ?)'; $params_action = array($url, $title, $content); $query = $this->executeQuery($sql_action, $params_action); + return $query; } public function deleteById($id) { @@ -114,6 +115,7 @@ class Sqlite extends Store { $sql_action = "DELETE FROM entries WHERE id=?"; $params_action = array($id); $query = $this->executeQuery($sql_action, $params_action); + return $query; } public function favoriteById($id) {