From ee1b081447634ee85330bd9ff797f005bbf17b4c Mon Sep 17 00:00:00 2001 From: Lukas Metzger Date: Mon, 2 Apr 2018 13:45:24 +0200 Subject: [PATCH] Fixed bug where remotes without records or domains were left in the db --- backend/src/operations/Domains.php | 9 ++++++++- backend/src/operations/Records.php | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/backend/src/operations/Domains.php b/backend/src/operations/Domains.php index e87a7cb..a5c089f 100644 --- a/backend/src/operations/Domains.php +++ b/backend/src/operations/Domains.php @@ -191,7 +191,10 @@ class Domains throw new \Exceptions\NotFoundException(); } - $query = $this->db->prepare('DELETE FROM domains WHERE id=:id'); + $query = $this->db->prepare(' + DELETE E FROM remote E + LEFT OUTER JOIN records R ON R.id=E.record + WHERE R.domain_id=:id'); $query->bindValue(':id', $id, \PDO::PARAM_INT); $query->execute(); @@ -199,6 +202,10 @@ class Domains $query->bindValue(':id', $id, \PDO::PARAM_INT); $query->execute(); + $query = $this->db->prepare('DELETE FROM domains WHERE id=:id'); + $query->bindValue(':id', $id, \PDO::PARAM_INT); + $query->execute(); + $this->db->commit(); } diff --git a/backend/src/operations/Records.php b/backend/src/operations/Records.php index 484a975..518de71 100644 --- a/backend/src/operations/Records.php +++ b/backend/src/operations/Records.php @@ -215,6 +215,10 @@ class Records throw new \Exceptions\NotFoundException(); } + $query = $this->db->prepare('DELETE FROM remote WHERE record=:id'); + $query->bindValue(':id', $id, \PDO::PARAM_INT); + $query->execute(); + $query = $this->db->prepare('DELETE FROM records WHERE id=:id'); $query->bindValue(':id', $id, \PDO::PARAM_INT); $query->execute();