diff --git a/models/feed.php b/models/feed.php index 0e2dc6e..6482c91 100644 --- a/models/feed.php +++ b/models/feed.php @@ -435,6 +435,8 @@ function update_cache($feed_id, $last_modified, $etag) function remove($feed_id) { delete_favicon($feed_id); + Group\remove_all($feed_id); + // Items are removed by a sql constraint return Database::getInstance('db')->table('feeds')->eq('id', $feed_id)->remove(); } diff --git a/models/group.php b/models/group.php index d010edc..31d254a 100644 --- a/models/group.php +++ b/models/group.php @@ -151,11 +151,39 @@ function add($feed_id, $group_ids) */ function remove($feed_id, $group_ids) { - return Database::getInstance('db') + $result = Database::getInstance('db') ->table('feeds_groups') ->eq('feed_id', $feed_id) ->in('group_id', $group_ids) ->remove(); + + // remove empty groups + if ($result) { + purge_groups(); + } + + return $result; +} + +/** + * Remove all groups from feed + * + * @param integer $feed_id id of the feed + * @return boolean true on success, false on error + */ +function remove_all($feed_id) +{ + $result = Database::getInstance('db') + ->table('feeds_groups') + ->eq('feed_id', $feed_id) + ->remove(); + + // remove empty groups + if ($result) { + purge_groups(); + } + + return $result; } /** @@ -213,8 +241,5 @@ function update_feed_groups($feed_id, $group_ids, $create_group = '') return false; } - // cleanup - purge_groups(); - return true; }