Skip to content

Commit

Permalink
added email check before creating a client (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliveiraigorm authored Jun 17, 2022
1 parent 674a22c commit 1530ed4
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions lib/Backend/DavListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
// ----------------------

Expand Down

0 comments on commit 1530ed4

Please sign in to comment.