return (bool) $this->db->prepare("DELETE from newssync_subscriptions where id is ?", "int")->run($id)->changes();
}
@ -362,7 +359,7 @@ class Database {
return $this->db->prepare(
"WITH RECURSIVE folders(id) as (SELECT id from newssync_folders where owner is ? and parent is ? union select newssync_folders.id from newssync_folders join folders on newssync_folders.parent=folders.id) ".
"SELECT id,name,parent from newssync_folders where id in(SELECT id from folders) order by name",
"str", "int")->run($user, $parent);
"str", "int")->run($user, $parent);
}
}
@ -488,4 +485,18 @@ class Database {
$this->db->commit();
return 1;
}
public function folderRemove(string $user, int $id): bool {
// common table expression to list all descendant folders of the target folder
$cte = "RECURSIVE folders(id) as (SELECT id from newssync_folders where owner is ? and id is ? union select newssync_folders.id from newssync_folders join folders on newssync_folders.parent=folders.id) ";
$changes = 0;
$this->db->begin();
// first delete any feed subscriptions contained within the folder tree (this may not be necesary because of foreign keys)
$changes += $this->db->prepare("WITH $cte"."DELETE FROM newssync_subscriptions where folder in(select id from folders)", "str", "int")->run($user, $id)->changes();
// next delete the folders themselves
$changes += $this->db->prepare("WITH $cte"."DELETE FROM newssync_folders where id in(select id from folders)", "str", "int")->run($user, $id)->changes();
order_typeintnotnulldefault0,-- NextCloud sort order
pinnedbooleannotnulldefault0,-- whether feed is pinned (always sorts at top)
folderintegerreferencesnewssync_folders(id)ondeletesetnull,-- TT-RSS category (nestable); the first-level category (which acts as NextCloud folder) is joined in when needed
folderintegerreferencesnewssync_folders(id)ondeletecascade,-- TT-RSS category (nestable); the first-level category (which acts as NextCloud folder) is joined in when needed
unique(owner,feed)-- a given feed should only appear once for a given owner