Clear autocreated contacts on create/update contact

This commit is contained in:
RainLoop Team 2013-12-04 22:52:44 +04:00
parent 3a4867abea
commit 43f094220c
2 changed files with 44 additions and 0 deletions

View file

@ -82,4 +82,21 @@ class Contact
$this->DisplayInList = 0 < \strlen($sDisplayName) ? $sDisplayName : (!empty($sDisplayEmail) ? $sDisplayEmail : '');
}
/**
* @return array
*/
public function GetEmails()
{
$aResult = array();
foreach ($this->Properties as /* @var $oProperty \RainLoop\Providers\PersonalAddressBook\Classes\Property */ &$oProperty)
{
if ($oProperty && $oProperty->IsEmail())
{
$aResult[] = $oProperty->Value;
}
}
return \array_unique($aResult);
}
}

View file

@ -72,6 +72,33 @@ class MySqlPersonalAddressBook
$oContact->UpdateDependentValues();
$oContact->Changed = \time();
if (\RainLoop\Providers\PersonalAddressBook\Enumerations\ContactType::AUTO != $oContact->Type)
{
$aEmail = $oContact->GetEmails();
if (0 < \count($aEmail))
{
$aEmail = \array_map(function ($mItem) {
return \strtolower(\trim($mItem));
}, $aEmail);
$aEmail = \array_filter($aEmail, function ($mItem) {
return !empty($mItem);
});
if (0 < \strlen($aEmail))
{
// clear autocreated contacts
$this->prepareAndExecute(
'DELETE FROM `rainloop_pab_contacts` WHERE `id_user` = :id_user AND `type` = :type AND `display_in_list` IN ('.\implode(',', $aEmail).')',
array(
':id_user' => array($iUserID, \PDO::PARAM_INT),
':type' => array(\RainLoop\Providers\PersonalAddressBook\Enumerations\ContactType::AUTO, \PDO::PARAM_INT)
)
);
}
}
}
try
{
$this->beginTransaction();