remove all group from feeds before deleting
Main purpose is to prevent orphaned groups. It's not possible to use the ON DELETE CASCADE trigger here, to remove the group together with the last feed that is assigned to this group. The ON DELETE CASCADE trigger will raise an foreign key violation error in cases where the removed feed is not the last feed associated to a group. The purge_groups() call has been moved to the remove group functions, since it's the only way to create an orphaned group.
This commit is contained in:
parent
47badfd963
commit
c35dd27f01
@ -435,6 +435,8 @@ function update_cache($feed_id, $last_modified, $etag)
|
|||||||
function remove($feed_id)
|
function remove($feed_id)
|
||||||
{
|
{
|
||||||
delete_favicon($feed_id);
|
delete_favicon($feed_id);
|
||||||
|
Group\remove_all($feed_id);
|
||||||
|
|
||||||
// Items are removed by a sql constraint
|
// Items are removed by a sql constraint
|
||||||
return Database::getInstance('db')->table('feeds')->eq('id', $feed_id)->remove();
|
return Database::getInstance('db')->table('feeds')->eq('id', $feed_id)->remove();
|
||||||
}
|
}
|
||||||
|
@ -151,11 +151,39 @@ function add($feed_id, $group_ids)
|
|||||||
*/
|
*/
|
||||||
function remove($feed_id, $group_ids)
|
function remove($feed_id, $group_ids)
|
||||||
{
|
{
|
||||||
return Database::getInstance('db')
|
$result = Database::getInstance('db')
|
||||||
->table('feeds_groups')
|
->table('feeds_groups')
|
||||||
->eq('feed_id', $feed_id)
|
->eq('feed_id', $feed_id)
|
||||||
->in('group_id', $group_ids)
|
->in('group_id', $group_ids)
|
||||||
->remove();
|
->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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// cleanup
|
|
||||||
purge_groups();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user