diff --git a/miniflux/index.php b/miniflux/index.php index 893adb0..6168bb4 100644 --- a/miniflux/index.php +++ b/miniflux/index.php @@ -133,6 +133,14 @@ Router\get_action('mark-item-unread', function() { }); +Router\get_action('mark-item-removed', function() { + + $id = Request\param('id'); + Model\set_item_removed($id); + Response\Redirect('?action=history'); +}); + + Router\post_action('mark-item-read', function() { $id = Request\param('id'); @@ -162,7 +170,7 @@ Router\post_action('change-item-status', function() { Router\get_action('history', function() { - Response\html(Template\layout('read_items', array( + Response\html(Template\layout('history', array( 'items' => Model\get_read_items(), 'menu' => 'history' ))); diff --git a/miniflux/model.php b/miniflux/model.php index e6b2fac..33f5872 100644 --- a/miniflux/model.php +++ b/miniflux/model.php @@ -261,6 +261,15 @@ function get_nav_item($item) } +function set_item_removed($id) +{ + \PicoTools\singleton('db') + ->table('items') + ->eq('id', $id) + ->save(array('status' => 'removed')); +} + + function set_item_read($id) { \PicoTools\singleton('db') @@ -339,27 +348,48 @@ function flush_read() function update_items($feed_id, array $items) { + $items_in_feed = array(); $db = \PicoTools\singleton('db'); $db->startTransaction(); foreach ($items as $item) { - if ($item->id && ! $db->table('items')->eq('id', $item->id)->count()) { + // Item parsed correctly? + if ($item->id) { - $db->table('items')->save(array( - 'id' => $item->id, - 'title' => $item->title, - 'url' => $item->url, - 'updated' => $item->updated, - 'author' => $item->author, - 'content' => $item->content, - 'status' => 'unread', - 'feed_id' => $feed_id - )); + // Insert only new item + if ($db->table('items')->eq('id', $item->id)->count() !== 1) { + + $db->table('items')->save(array( + 'id' => $item->id, + 'title' => $item->title, + 'url' => $item->url, + 'updated' => $item->updated, + 'author' => $item->author, + 'content' => $item->content, + 'status' => 'unread', + 'feed_id' => $feed_id + )); + } + + // Items inside this feed + $items_in_feed[] = $item->id; } } + // Remove from the database items marked as "removed" + // and not present inside the feed + if (! empty($items_in_feed)) { + + \PicoTools\singleton('db') + ->table('items') + ->notin('id', $items_in_feed) + ->eq('status', 'removed') + ->eq('feed_id', $feed_id) + ->remove(); + } + $db->closeTransaction(); }