return isset($entry[0]) ? $entry[0] : null;
}
+ public function retrieveOneByURL($url, $user_id) {
+ $entry = NULL;
+ $sql = "SELECT * FROM entries WHERE url=? AND user_id=?";
+ $params = array($url, $user_id);
+ $query = $this->executeQuery($sql, $params);
+ $entry = $query->fetchAll();
+
+ return isset($entry[0]) ? $entry[0] : null;
+ }
+
+ public function reassignTags($old_entry_id, $new_entry_id) {
+ $sql = "UPDATE tags_entries SET entry_id=? WHERE entry_id=?";
+ $params = array($new_entry_id, $old_entry_id);
+ $query = $this->executeQuery($sql, $params);
+ }
+
public function getEntriesByView($view, $user_id, $limit = '') {
switch ($_SESSION['sort'])
{
$title = ($content['rss']['channel']['item']['title'] != '') ? $content['rss']['channel']['item']['title'] : _('Untitled');
$body = $content['rss']['channel']['item']['description'];
+ //search for possible duplicate if not in import mode
+ if (!$import) {
+ $duplicate = $this->store->retrieveOneByURL($url->getUrl(), $this->user->getId());
+ }
+
if ($this->store->add($url->getUrl(), $title, $body, $this->user->getId())) {
Tools::logm('add link ' . $url->getUrl());
$sequence = '';
Tools::logm('updating content article');
$this->store->updateContent($last_id, $content, $this->user->getId());
}
+
+ if ($duplicate != NULL) {
+ // 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
+ Tools::logm('link ' . $url->getUrl() . ' is a duplicate');
+ // 1) - preserve tags and favorite, then drop old entry
+ $this->store->reassignTags($duplicate['id'], $last_id);
+ if ($duplicate['is_fav']) {
+ $this->store->favoriteById($last_id, $this->user->getId());
+ }
+ if ($this->store->deleteById($duplicate['id'], $this->user->getId())) {
+ Tools::logm('previous link ' . $url->getUrl() .' entry deleted');
+ }
+ }
+
if (!$import) {
$this->messages->add('s', _('the link has been added successfully'));
}