From: Nicolas Iooss Date: Sun, 5 Oct 2014 14:03:00 +0000 (+0200) Subject: Append selector instead of overwritting previous ones in Address::deleteAddresses X-Git-Url: http://git.polytechnique.org/?p=platal.git;a=commitdiff_plain;h=e0e01724d7ef7f388307d62639867ea0dbac0fdb Append selector instead of overwritting previous ones in Address::deleteAddresses While at it, add a safety check in Address::deleteAddresses. --- diff --git a/classes/address.php b/classes/address.php index 7034196..e325d1e 100644 --- a/classes/address.php +++ b/classes/address.php @@ -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\')'),