Add remove link on history page and remove old items automatically

This commit is contained in:
Frederic Guillot 2013-04-22 22:44:28 -04:00
parent 9a947b8eab
commit 5a2869e258
2 changed files with 50 additions and 12 deletions

View File

@ -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'
)));

View File

@ -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();
}