Append selector instead of overwritting previous ones in Address::deleteAddresses
authorNicolas Iooss <nicolas.iooss_git@polytechnique.org>
Sun, 5 Oct 2014 14:03:00 +0000 (16:03 +0200)
committerNicolas Iooss <nicolas.iooss_git@polytechnique.org>
Sun, 5 Oct 2014 14:28:53 +0000 (16:28 +0200)
While at it, add a safety check in Address::deleteAddresses.

classes/address.php

index 7034196..e325d1e 100644 (file)
@@ -822,13 +822,17 @@ class Address
     {
         $where = '';
         if (!is_null($pid)) {
-            $where = XDB::format(' AND pid = {?}', $pid);
+            $where .= XDB::format(' AND pid = {?}', $pid);
         }
         if (!is_null($jobid)) {
-            $where = XDB::format(' AND jobid = {?}', $jobid);
+            $where .= XDB::format(' AND jobid = {?}', $jobid);
         }
         if (!is_null($groupid)) {
-            $where = XDB::format(' AND groupid = {?}', $groupid);
+            $where .= XDB::format(' AND groupid = {?}', $groupid);
+        }
+        // Prevent buggy callers from accidentally dropping profile_addresses
+        if (!$where) {
+            throw new Exception("Unable to delete all addresses of the given type, the request was too generic");
         }
         XDB::execute('DELETE FROM  profile_addresses
                             WHERE  type = {?}' . $where . (($deletePrivate) ? '' : ' AND pub IN (\'public\', \'ax\')'),