Add remove link on history page and remove old items automatically
This commit is contained in:
parent
9a947b8eab
commit
5a2869e258
@ -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'
|
||||
)));
|
||||
|
@ -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,13 +348,18 @@ 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) {
|
||||
|
||||
// Insert only new item
|
||||
if ($db->table('items')->eq('id', $item->id)->count() !== 1) {
|
||||
|
||||
$db->table('items')->save(array(
|
||||
'id' => $item->id,
|
||||
@ -358,6 +372,22 @@ function update_items($feed_id, array $items)
|
||||
'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();
|
||||
|
Loading…
Reference in New Issue
Block a user