diff --git a/apps/maarch_entreprise/Models/ContactsModelAbstract.php b/apps/maarch_entreprise/Models/ContactsModelAbstract.php index a206e86a06dcbc6d47ad777d3eae305b6cde1581..008cd7f498150bdea7238953636716978e9613b2 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']] + ]); + } + } +}