mirror of
https://github.com/moparisthebest/wallabag
synced 2024-11-05 00:45:09 -05:00
Merge pull request #460 from mariroz/dev
duplicate check added. fix of issue #400
This commit is contained in:
commit
970cfb1166
@ -241,6 +241,22 @@ class Database {
|
||||
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'])
|
||||
{
|
||||
|
@ -374,6 +374,11 @@ class Poche
|
||||
$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 = '';
|
||||
@ -386,6 +391,20 @@ class Poche
|
||||
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'));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user