From 65eea1f6ea73371abf1f10d38b56dfe4d6c8b60f Mon Sep 17 00:00:00 2001 From: Laurent Giovannoni <laurent.giovannoni@maarch.org> Date: Fri, 24 Mar 2017 15:56:44 +0100 Subject: [PATCH] new method for contact purge --- .../Models/ContactsModelAbstract.php | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/apps/maarch_entreprise/Models/ContactsModelAbstract.php b/apps/maarch_entreprise/Models/ContactsModelAbstract.php index a206e86a06d..008cd7f4981 100644 --- a/apps/maarch_entreprise/Models/ContactsModelAbstract.php +++ b/apps/maarch_entreprise/Models/ContactsModelAbstract.php @@ -84,4 +84,37 @@ class ContactsModelAbstract extends Apps_Table_Service return $aReturn; } -} \ No newline at end of file + + public static function purgeContact($aArgs) + { + static::checkRequired($aArgs, ['id']); + static::checkNumeric($aArgs, ['id']); + + $aReturn = static::select([ + 'select' => ['count(*)'], + 'table' => ['res_view_letterbox'], + 'where' => ['contact_id = ?'], + 'data' => [$aArgs['id']], + ]); + + $aReturnBis = static::select([ + 'select' => ['count(*)'], + 'table' => ['contacts_res'], + 'where' => ['contact_id = ?'], + 'data' => [$aArgs['id']], + ]); + + if ($aReturn[0]['count'] < 1 && $aReturnBis[0]['count'] < 1) { + $aDelete = static::deleteFrom([ + 'table' => 'contact_addresses', + 'where' => ['contact_id = ?'], + 'data' => [$aArgs['id']] + ]); + $aDelete = static::deleteFrom([ + 'table' => 'contacts_v2', + 'where' => ['contact_id = ?'], + 'data' => [$aArgs['id']] + ]); + } + } +} -- GitLab