- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/lib/volume/contact.php
- Класс: Bitrix\Crm\Volume\Contact
- Вызов: Contact::clearEntity
public function clearEntity()
{
if (!$this->canClearEntity())
{
return -1;
}
$query = $this->prepareQuery();
$dropped = -1;
if ($this->prepareFilter($query))
{
$query
->addSelect('ID', 'CONTACT_ID')
->setLimit(self::MAX_ENTITY_PER_INTERACTION)
->setOrder(array('ID' => 'ASC'))
;
if ($this->getProcessOffset() > 0)
{
$query->where('ID', '>', $this->getProcessOffset());
}
$res = $query->exec();
$connection = \Bitrix\Main\Application::getConnection();
$userPermissions = \CCrmPerms::GetUserPermissions($this->getOwner());
$crmContact = new \CCrmContact(false);
$dropped = 0;
while ($contact = $res->fetch())
{
$this->setProcessOffset($contact['CONTACT_ID']);
$entityAttr = $userPermissions->GetEntityAttr('CONTACT', array($contact['CONTACT_ID']));
if ($userPermissions->CheckEnityAccess('CONTACT', 'DELETE', $entityAttr[$contact['CONTACT_ID']]))
{
$connection->startTransaction();
if ($crmContact->delete($contact['CONTACT_ID'], array('CURRENT_USER' => $this->getOwner())))
{
$connection->commitTransaction();
$this->incrementDroppedEntityCount();
$dropped ++;
}
else
{
$connection->rollbackTransaction();
$err = '';
global $APPLICATION;
if ($APPLICATION instanceof \CMain)
{
$err = $APPLICATION->GetException();
}
if ($err == '')
{
$err = 'Deletion failed with contact #'.$contact['CONTACT_ID'];
}
$this->collectError(new Main\Error($err, self::ERROR_DELETION_FAILED));
$this->incrementFailCount();
}
}
else
{
$this->collectError(new Main\Error('Access denied to drop contact #'.$contact['CONTACT_ID'], self::ERROR_PERMISSION_DENIED));
$this->incrementFailCount();
}
if ($this->hasTimeLimitReached())
{
break;
}
}
}
else
{
$this->collectError(new Main\Error('Filter error', self::ERROR_DELETION_FAILED));
}
return $dropped;
}