From b4de56a64ea4c0a98b9f7ac371b0b4de82eb9910 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Fri, 21 Dec 2018 17:02:34 -0500 Subject: [PATCH] Work around MySQL silliness with same-table foreign keys --- lib/Database.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Database.php b/lib/Database.php index dd94cf3..4a6fc40 100644 --- a/lib/Database.php +++ b/lib/Database.php @@ -272,7 +272,7 @@ class Database { if (!ValueInfo::id($id)) { throw new Db\ExceptionInput("typeViolation", ["action" => __FUNCTION__, "field" => "folder", 'type' => "int > 0"]); } - $changes = $this->db->prepare("DELETE FROM arsse_folders where owner = ? and id = ?", "str", "int")->run($user, $id)->changes(); + $changes = $this->db->prepare("WITH RECURSIVE folders(folder) as (SELECT ? union select id from arsse_folders join folders on parent = folder) DELETE FROM arsse_folders where owner = ? and id in (select folder from folders)", "int", "str")->run($id, $user)->changes(); if (!$changes) { throw new Db\ExceptionInput("subjectMissing", ["action" => __FUNCTION__, "field" => "folder", 'id' => $id]); }