diff --git a/lib/Backend/DavListener.php b/lib/Backend/DavListener.php index 08481960..db25bb8c 100644 --- a/lib/Backend/DavListener.php +++ b/lib/Backend/DavListener.php @@ -563,23 +563,24 @@ private function handler(array $objectData, array $calendarData, bool $isDelete) } // create client - try{ - $client = new Client(); - $client->setName($to_name); - $client->setEmail($to_email); - $client->setProviderId($userId); - $client->setDescription(""); - $client->setPhoneNumber( $this->getPhoneFromDescription($om_info)); - $client->setTimezone($this->getTimezoneFromDescription($om_info)); - - $newClient = $this->mapper->insert($client); - - //publish the new client actitivty - $this->publishClientActivity($newClient, $userId); - } - catch(Exception $e){ - if($e->getCode() != 1062) // ignores duplicate email exception + if(!$this->mapper->findByEmail($to_email, $userId)){ + try{ + $client = new Client(); + $client->setName($to_name); + $client->setEmail($to_email); + $client->setProviderId($userId); + $client->setDescription(""); + $client->setPhoneNumber( $this->getPhoneFromDescription($om_info)); + $client->setTimezone($this->getTimezoneFromDescription($om_info)); + + $newClient = $this->mapper->insert($client); + + //publish the new client actitivty + $this->publishClientActivity($newClient, $userId); + } + catch(Exception $e){ $this->logger->error($e->getMessage()); + } } // ----------------------