diff options
Diffstat (limited to 'inc/poche')
-rw-r--r-- | inc/poche/Database.class.php | 16 | ||||
-rw-r--r-- | inc/poche/Poche.class.php | 19 |
2 files changed, 35 insertions, 0 deletions
diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index 9f553fa1..58583bf5 100644 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php | |||
@@ -241,6 +241,22 @@ class Database { | |||
241 | return isset($entry[0]) ? $entry[0] : null; | 241 | return isset($entry[0]) ? $entry[0] : null; |
242 | } | 242 | } |
243 | 243 | ||
244 | public function retrieveOneByURL($url, $user_id) { | ||
245 | $entry = NULL; | ||
246 | $sql = "SELECT * FROM entries WHERE url=? AND user_id=?"; | ||
247 | $params = array($url, $user_id); | ||
248 | $query = $this->executeQuery($sql, $params); | ||
249 | $entry = $query->fetchAll(); | ||
250 | |||
251 | return isset($entry[0]) ? $entry[0] : null; | ||
252 | } | ||
253 | |||
254 | public function reassignTags($old_entry_id, $new_entry_id) { | ||
255 | $sql = "UPDATE tags_entries SET entry_id=? WHERE entry_id=?"; | ||
256 | $params = array($new_entry_id, $old_entry_id); | ||
257 | $query = $this->executeQuery($sql, $params); | ||
258 | } | ||
259 | |||
244 | public function getEntriesByView($view, $user_id, $limit = '') { | 260 | public function getEntriesByView($view, $user_id, $limit = '') { |
245 | switch ($_SESSION['sort']) | 261 | switch ($_SESSION['sort']) |
246 | { | 262 | { |
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index d0e2de1f..76169297 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php | |||
@@ -374,6 +374,11 @@ class Poche | |||
374 | $title = ($content['rss']['channel']['item']['title'] != '') ? $content['rss']['channel']['item']['title'] : _('Untitled'); | 374 | $title = ($content['rss']['channel']['item']['title'] != '') ? $content['rss']['channel']['item']['title'] : _('Untitled'); |
375 | $body = $content['rss']['channel']['item']['description']; | 375 | $body = $content['rss']['channel']['item']['description']; |
376 | 376 | ||
377 | //search for possible duplicate if not in import mode | ||
378 | if (!$import) { | ||
379 | $duplicate = $this->store->retrieveOneByURL($url->getUrl(), $this->user->getId()); | ||
380 | } | ||
381 | |||
377 | if ($this->store->add($url->getUrl(), $title, $body, $this->user->getId())) { | 382 | if ($this->store->add($url->getUrl(), $title, $body, $this->user->getId())) { |
378 | Tools::logm('add link ' . $url->getUrl()); | 383 | Tools::logm('add link ' . $url->getUrl()); |
379 | $sequence = ''; | 384 | $sequence = ''; |
@@ -386,6 +391,20 @@ class Poche | |||
386 | Tools::logm('updating content article'); | 391 | Tools::logm('updating content article'); |
387 | $this->store->updateContent($last_id, $content, $this->user->getId()); | 392 | $this->store->updateContent($last_id, $content, $this->user->getId()); |
388 | } | 393 | } |
394 | |||
395 | if ($duplicate != NULL) { | ||
396 | // duplicate exists, so, older entry needs to be deleted (as new entry should go to the top of list), BUT favorite mark and tags should be preserved | ||
397 | Tools::logm('link ' . $url->getUrl() . ' is a duplicate'); | ||
398 | // 1) - preserve tags and favorite, then drop old entry | ||
399 | $this->store->reassignTags($duplicate['id'], $last_id); | ||
400 | if ($duplicate['is_fav']) { | ||
401 | $this->store->favoriteById($last_id, $this->user->getId()); | ||
402 | } | ||
403 | if ($this->store->deleteById($duplicate['id'], $this->user->getId())) { | ||
404 | Tools::logm('previous link ' . $url->getUrl() .' entry deleted'); | ||
405 | } | ||
406 | } | ||
407 | |||
389 | if (!$import) { | 408 | if (!$import) { |
390 | $this->messages->add('s', _('the link has been added successfully')); | 409 | $this->messages->add('s', _('the link has been added successfully')); |
391 | } | 410 | } |