From: Nicolas Iooss Date: Sun, 5 Oct 2014 14:35:14 +0000 (+0200) Subject: Delete profile_addresses_components rows where deleting profile_addresses ones X-Git-Url: http://git.polytechnique.org/?p=platal.git;a=commitdiff_plain;h=1aff3b59c0f46dafe3396c1123a252645805e233 Delete profile_addresses_components rows where deleting profile_addresses ones Commit 02228cb2df1e ("Properly deletes address components on address deletion") only changed Address::delete, not Address::deleteAddresses, which is used to delete a bunch of related addresses. As a consequence, addresses deleted with this function were not cleany removed from the database. --- diff --git a/classes/address.php b/classes/address.php index e325d1e..62e7350 100644 --- a/classes/address.php +++ b/classes/address.php @@ -834,8 +834,26 @@ class Address if (!$where) { throw new Exception("Unable to delete all addresses of the given type, the request was too generic"); } + $where_pub = $where . (($deletePrivate) ? '' : ' AND pub IN (\'public\', \'ax\')'); + + if ($deletePrivate) { + XDB::execute('DELETE FROM profile_addresses_components + WHERE type = {?}' . $where, + $type); + } else { + // Delete address components one by one if $deletePrivate is not requested + $res = XDB::iterator('SELECT pid, jobid, groupid, type, id + FROM profile_addresses + WHERE type = {?}' . $where_pub, + $type); + while (($values = $res->next())) { + XDB::execute('DELETE FROM profile_addresses_components + WHERE pid = {?} AND jobid = {?} AND groupid = {?} AND type = {?} AND id = {?}', + $values['pid'], $values['jobid'], $values['groupid'], $values['type'], $values['id']); + } + } XDB::execute('DELETE FROM profile_addresses - WHERE type = {?}' . $where . (($deletePrivate) ? '' : ' AND pub IN (\'public\', \'ax\')'), + WHERE type = {?}' . $where_pub, $type); if ($type == self::LINK_PROFILE) { Phone::deletePhones($pid, Phone::LINK_ADDRESS, null, $deletePrivate);