...Человеческий поиск в разработке...
- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_email.php
- Класс: \CCrmEMail
- Вызов: CCrmEMail::OnImapEmailMessageObsolete
static function OnImapEmailMessageObsolete(\Bitrix\Main\Event $event) { global $DB; $resp = $event->getParameter('user'); $hash = $event->getParameter('hash'); $res = \Bitrix\Crm\Activity\MailMetaTable::getList(array( 'select' => array('ACTIVITY_ID'), 'filter' => array('=MSG_HEADER_HASH' => $hash), )); while ($mailMeta = $res->fetch()) { if ($activity = \CCrmActivity::getById($mailMeta['ACTIVITY_ID'], false)) { if ($activity['TYPE_ID'] != \CCrmActivityType::Email || $activity['DIRECTION'] != \CCrmActivityDirection::Incoming) break; if ($resp > 0 && $activity['RESPONSIBLE_ID'] != $resp) break; $response = $DB->query(sprintf('SELECT 1 FROM b_crm_act WHERE PARENT_ID = %u', $activity['ID']))->fetch(); if (!$response) { $bindRes = $DB->query(sprintf( 'SELECT OWNER_ID FROM b_crm_act_bind WHERE ACTIVITY_ID = %u AND OWNER_TYPE_ID = %u', $activity['ID'], \CCrmOwnerType::Lead )); $leadIds = array(); while ($bind = $bindRes->fetch()) $leadIds[] = $bind['OWNER_ID']; \CCrmActivity::delete($activity['ID'], false, false); \Bitrix\Crm\Activity\MailMetaTable::delete($activity['ID']); if (!empty($leadIds)) { $leadRes = \CCrmLead::getListEx( array(), array( 'ID' => $leadIds, 'ORIGINATOR_ID' => 'email-tracker', 'STATUS_ID' => 'NEW', 'CHECK_PERMISSIONS' => 'N' ), false, false, array('ID', 'DATE_CREATE', 'DATE_MODIFY') ); while ($lead = $leadRes->fetch()) { if ($lead['DATE_CREATE'] == $lead['DATE_MODIFY']) { $response = $DB->query(sprintf( 'SELECT 1 FROM b_crm_act_bind WHERE OWNER_ID = %u AND OWNER_TYPE_ID = %u', $lead['ID'], \CCrmOwnerType::Lead ))->fetch(); if (!$response) { $obsoleteLead = new \CCrmLead(false); $obsoleteLead->delete($lead['ID']); } } } } } break; } } }