Browse Source

Fixed bug where remotes without records or domains were left in the db

Lukas Metzger 7 years ago
parent
commit
ee1b081447
2 changed files with 12 additions and 1 deletions
  1. 8 1
      backend/src/operations/Domains.php
  2. 4 0
      backend/src/operations/Records.php

+ 8 - 1
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();
     }
 

+ 4 - 0
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();