mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 13:12:41 +00:00
Experimental method to remove a folder
This commit is contained in:
parent
ce0584e7f8
commit
b8f9b6070e
2 changed files with 17 additions and 6 deletions
|
@ -298,10 +298,7 @@ class Database {
|
|||
return $sub;
|
||||
}
|
||||
|
||||
public function subscriptionRemove(int $id): bool {
|
||||
$this->db->begin();
|
||||
$user = $this->db->prepare("SELECT owner from newssync_subscriptions where id is ?", "int")->run($id)->getValue();
|
||||
if($user===null) return false;
|
||||
public function subscriptionRemove(string $user, int $id): bool {
|
||||
if(!$this->data->user->authorize($user, __FUNCTION__)) throw new User\ExceptionAuthz("notAuthorized", ["action" => __FUNCTION__, "user" => $user]);
|
||||
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 {
|
||||
if(!$this->data->user->authorize($user, __FUNCTION__)) throw new User\ExceptionAuthz("notAuthorized", ["action" => __FUNCTION__, "user" => $user]);
|
||||
// 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();
|
||||
$this->db->commit();
|
||||
return (bool) $changes;
|
||||
}
|
||||
}
|
|
@ -45,7 +45,7 @@ create table newssync_subscriptions(
|
|||
title TEXT, -- user-supplied title
|
||||
order_type int not null default 0, -- NextCloud sort order
|
||||
pinned boolean not null default 0, -- whether feed is pinned (always sorts at top)
|
||||
folder integer references newssync_folders(id) on delete set null, -- TT-RSS category (nestable); the first-level category (which acts as NextCloud folder) is joined in when needed
|
||||
folder integer references newssync_folders(id) on delete cascade, -- 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
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in a new issue