private static function UnregisterLiveFeedEvent($activityID) { $slEntities = CCrmLiveFeed::GetLogEvents(array(), array('ENTITY_TYPE_ID' => CCrmOwnerType::Activity, 'ENTITY_ID' => $activityID), array('ID')); $options = array('UNREGISTER_RELATION' => false); foreach ($slEntities as &$slEntity) { CCrmLiveFeed::DeleteLogEvent($slEntity['ID'], $options); } unset($slEntity); CCrmSonetRelation::UnRegisterRelationsByEntity(CCrmOwnerType::Activity, $activityID); }
public function Delete($ID, $arOptions = array()) { global $DB, $APPLICATION; $ID = intval($ID); $iUserId = CCrmSecurityHelper::GetCurrentUserID(); if (!is_array($arOptions)) { $arOptions = array(); } $sWherePerm = ''; if ($this->bCheckPermission) { $arEntityAttr = $this->cPerms->GetEntityAttr('DEAL', $ID); $sEntityPerm = $this->cPerms->GetPermType('DEAL', 'DELETE', $arEntityAttr[$ID]); if ($sEntityPerm == BX_CRM_PERM_NONE) { return false; } else { if ($sEntityPerm == BX_CRM_PERM_SELF) { $sWherePerm = " AND ASSIGNED_BY_ID = {$iUserId}"; } else { if ($sEntityPerm == BX_CRM_PERM_OPEN) { $sWherePerm = " AND (OPENED = 'Y' OR ASSIGNED_BY_ID = {$iUserId})"; } } } } $APPLICATION->ResetException(); $events = GetModuleEvents('crm', 'OnBeforeCrmDealDelete'); while ($arEvent = $events->Fetch()) { if (ExecuteModuleEventEx($arEvent, array($ID)) === false) { $err = GetMessage("MAIN_BEFORE_DEL_ERR") . ' ' . $arEvent['TO_NAME']; if ($ex = $APPLICATION->GetException()) { $err .= ': ' . $ex->GetString(); } $APPLICATION->throwException($err); return false; } } //By defaut we need to clean up related bizproc entities $processBizproc = isset($arOptions['PROCESS_BIZPROC']) ? (bool) $arOptions['PROCESS_BIZPROC'] : true; if ($processBizproc) { $bizproc = new CCrmBizProc('DEAL'); $bizproc->ProcessDeletion($ID); } $dbRes = $DB->Query("DELETE FROM b_crm_deal WHERE ID = {$ID}{$sWherePerm}", false, 'FILE: ' . __FILE__ . '<br /> LINE: ' . __LINE__); if (is_object($dbRes) && $dbRes->AffectedRowsCount() > 0) { CCrmSearch::DeleteSearch('DEAL', $ID); $DB->Query("DELETE FROM b_crm_entity_perms WHERE ENTITY='DEAL' AND ENTITY_ID = {$ID}", false, 'FILE: ' . __FILE__ . '<br /> LINE: ' . __LINE__); $GLOBALS['USER_FIELD_MANAGER']->Delete(self::$sUFEntityID, $ID); $CCrmFieldMulti = new CCrmFieldMulti(); $CCrmFieldMulti->DeleteByElement('DEAL', $ID); $CCrmEvent = new CCrmEvent(); $CCrmEvent->DeleteByElement('DEAL', $ID); Bitrix\Crm\History\DealStageHistoryEntry::unregister($ID); Bitrix\Crm\Statistics\DealSumStatisticEntry::unregister($ID); Bitrix\Crm\Statistics\DealInvoiceStatisticEntry::unregister($ID); Bitrix\Crm\Statistics\DealActivityStatisticEntry::unregister($ID); // Deletion of deal details CCrmProductRow::DeleteByOwner('D', $ID); CCrmProductRow::DeleteSettings('D', $ID); CCrmActivity::DeleteByOwner(CCrmOwnerType::Deal, $ID); CCrmSonetSubscription::UnRegisterSubscriptionByEntity(CCrmOwnerType::Deal, $ID); CCrmLiveFeed::DeleteLogEvents(array('ENTITY_TYPE_ID' => CCrmOwnerType::Deal, 'ENTITY_ID' => $ID)); self::PullChange('DELETE', array('ID' => $ID)); if (defined("BX_COMP_MANAGED_CACHE")) { $GLOBALS["CACHE_MANAGER"]->ClearByTag("crm_entity_name_" . CCrmOwnerType::Deal . "_" . $ID); } $afterEvents = GetModuleEvents('crm', 'OnAfterCrmDealDelete'); while ($arEvent = $afterEvents->Fetch()) { ExecuteModuleEventEx($arEvent, array($ID)); } } return true; }
public static function ProcessLogEventEditPOST($arPOST, $entityTypeID, $entityID, &$arResult) { $arEntityData = array(); $errors = array(); $enableTitle = isset($arPOST['ENABLE_POST_TITLE']) && strtoupper($arPOST['ENABLE_POST_TITLE']) === 'Y'; $title = $enableTitle && isset($arPOST['POST_TITLE']) ? $arPOST['POST_TITLE'] : ''; $message = isset($arPOST['MESSAGE']) ? htmlspecialcharsback($arPOST['MESSAGE']) : ''; $arResult['EVENT']['MESSAGE'] = $message; $arResult['EVENT']['TITLE'] = $title; $arResult['ENABLE_TITLE'] = $enableTitle; $attachedFiles = array(); $webDavFileFieldName = $arResult['WEB_DAV_FILE_FIELD_NAME']; if ($webDavFileFieldName !== '' && isset($GLOBALS[$webDavFileFieldName]) && is_array($GLOBALS[$webDavFileFieldName])) { foreach ($GLOBALS[$webDavFileFieldName] as $fileID) { if ($fileID === '') { continue; } //fileID: "888|165|16" $attachedFiles[] = $fileID; } if (!empty($attachedFiles) && is_array($arResult['WEB_DAV_FILE_FIELD'])) { $arResult['WEB_DAV_FILE_FIELD']['VALUE'] = $attachedFiles; } } $allowToAll = COption::GetOptionString('socialnetwork', 'allow_livefeed_toall', 'Y') === 'Y'; if ($allowToAll) { $arToAllRights = unserialize(COption::GetOptionString("socialnetwork", "livefeed_toall_rights", 'a:1:{i:0;s:2:"AU";}')); if (!$arToAllRights) { $arToAllRights = array('AU'); } $arUserGroupCode = array_merge(array('AU'), CAccess::GetUserCodesArray($arResult['USER_ID'])); if (count(array_intersect($arToAllRights, $arUserGroupCode)) <= 0) { $allowToAll = false; } } $arSocnetRights = array(); if (!empty($arPOST['SPERM'])) { foreach ($arPOST['SPERM'] as $v => $k) { if (strlen($v) > 0 && is_array($k) && !empty($k)) { foreach ($k as $vv) { if (strlen($vv) > 0) { $arSocnetRights[] = $vv; } } } } } if (in_array('UA', $arSocnetRights) && !$allowToAll) { foreach ($arSocnetRights as $key => $value) { if ($value == 'UA') { unset($arSocnetRights[$key]); break; } } } foreach ($arSocnetRights as $key => $value) { if ($value == 'UA') { $arSocnetRights[] = 'AU'; unset($arSocnetRights[$key]); break; } } $arSocnetRights = array_unique($arSocnetRights); $allFeedEtityTypes = CCrmLiveFeedEntity::GetAll(); $userPerms = CCrmPerms::GetCurrentUserPermissions(); foreach ($arSocnetRights as $key => $value) { $groupCodeData = array(); if (CCrmLiveFeed::TryParseGroupCode($value, $groupCodeData) && in_array($groupCodeData['ENTITY_TYPE'], $allFeedEtityTypes, true)) { $groupCodeEntityType = $groupCodeData['ENTITY_TYPE']; $groupCodeEntityID = $groupCodeData['ENTITY_ID']; if (!CCrmLiveFeed::CheckCreatePermission($groupCodeEntityType, $groupCodeEntityID, $userPerms)) { $canonicalEntityTypeID = CCrmLiveFeedEntity::ResolveEntityTypeID($groupCodeEntityType); $errors[] = GetMessage('CRM_SL_EVENT_EDIT_PERMISSION_DENIED', array('#TITLE#' => CCrmOwnerType::GetCaption($canonicalEntityTypeID, $groupCodeEntityID, false))); } else { $arEntityData[] = array('ENTITY_TYPE' => $groupCodeEntityType, 'ENTITY_ID' => $groupCodeEntityID); } } } if (!(CCrmOwnerType::IsDefined($entityTypeID) && $entityID > 0) && !empty($arEntityData)) { $entityData = $arEntityData[0]; $entityTypeID = CCrmLiveFeedEntity::ResolveEntityTypeID($entityData['ENTITY_TYPE']); $entityID = $entityData['ENTITY_ID']; } if (!empty($arEntityData)) { $arResult['ENTITY_DATA'] = $arEntityData; } if (!(CCrmOwnerType::IsDefined($entityTypeID) && $entityID > 0)) { $errors[] = GetMessage('CRM_SL_EVENT_EDIT_ENTITY_NOT_DEFINED'); } if ($message === '') { $errors[] = GetMessage('CRM_SL_EVENT_EDIT_EMPTY_MESSAGE'); } if (empty($errors)) { $fields = array('ENTITY_TYPE_ID' => $entityTypeID, 'ENTITY_ID' => $entityID, 'USER_ID' => $arResult['USER_ID'], 'TITLE' => $title, 'MESSAGE' => $message, 'RIGHTS' => $arSocnetRights); $parents = array(); CCrmOwnerType::TryGetOwnerInfos($entityTypeID, $entityID, $parents, array('ENABLE_MAPPING' => true)); foreach ($arEntityData as $entityData) { $curEntityTypeID = CCrmLiveFeedEntity::ResolveEntityTypeID($entityData['ENTITY_TYPE']); $curEntityID = $entityData['ENTITY_ID']; $entityKey = "{$curEntityTypeID}_{$curEntityID}"; if (!isset($parents[$entityKey]) && !($curEntityTypeID === $entityTypeID && $curEntityID === $entityID)) { $parents[$entityKey] = array('ENTITY_TYPE_ID' => $curEntityTypeID, 'ENTITY_ID' => $curEntityID); } } if (!empty($parents)) { $fields['PARENTS'] = array_values($parents); } if (!empty($attachedFiles)) { $fields['WEB_DAV_FILES'] = array($webDavFileFieldName => $attachedFiles); } $messageID = CCrmLiveFeed::CreateLogMessage($fields); if (!(is_int($messageID) && $messageID > 0)) { $errors[] = isset($fields['ERROR']) ? $fields['ERROR'] : 'UNKNOWN ERROR'; } else { preg_match_all("/\\[user\\s*=\\s*([^\\]]*)\\](.+?)\\[\\/user\\]/is" . BX_UTF_PCRE_MODIFIER, $message, $arMention); if (!empty($arMention) && !empty($arMention[1]) && CModule::IncludeModule("im")) { $arMention = $arMention[1]; $arMention = array_unique($arMention); $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => "", "FROM_USER_ID" => $arResult['USER_ID'], "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "crm", "NOTIFY_EVENT" => "mention"); $genderSuffix = ""; $dbUser = CUser::GetByID($arResult['USER_ID']); if ($arUser = $dbUser->Fetch()) { switch ($arUser["PERSONAL_GENDER"]) { case "M": $genderSuffix = "_M"; break; case "F": $genderSuffix = "_F"; break; default: $genderSuffix = ""; } } $strIMMessageTitle = str_replace(array("\r\n", "\n"), " ", strlen($title) > 0 ? $title : $message); if (CModule::IncludeModule("blog")) { $strIMMessageTitle = trim(blogTextParser::killAllTags($strIMMessageTitle)); } $strIMMessageTitle = TruncateText($strIMMessageTitle, 100); $strIMMessageTitleOut = TruncateText($strIMMessageTitle, 255); $strLogEntryURL = COption::GetOptionString("socialnetwork", "log_entry_page", SITE_DIR . "company/personal/log/#log_id#/", SITE_ID); $strLogEntryURL = CComponentEngine::MakePathFromTemplate($strLogEntryURL, array("log_id" => $messageID)); $strLogEntryCrmURL = CComponentEngine::MakePathFromTemplate(SITE_DIR . "crm/stream/?log_id=#log_id#", array("log_id" => $messageID)); $serverName = (CMain::IsHTTPS() ? "https" : "http") . "://" . (defined("SITE_SERVER_NAME") && strlen(SITE_SERVER_NAME) > 0 ? SITE_SERVER_NAME : COption::GetOptionString("main", "server_name", "")); foreach ($arMention as $val) { $val = IntVal($val); if ($val > 0 && $val != $arResult['USER_ID']) { $bHasAccess = false; if (in_array('U' . $val, $arSocnetRights)) { $url = $strLogEntryURL; $bHasAccess = true; } if (!$bHasAccess) { $arAccessCodes = array(); $dbAccess = CAccess::GetUserCodes($val); while ($arAccess = $dbAccess->Fetch()) { $arAccessCodes[] = $arAccess["ACCESS_CODE"]; } $arTmp = array_intersect($arAccess, $arSocnetRights); if (!empty($arTmp)) { $url = $strLogEntryURL; $bHasAccess = true; } } if (!$bHasAccess) { $userPermissions = CCrmPerms::GetUserPermissions($val); foreach ($arEntityData as $arEntity) { if (CCrmAuthorizationHelper::CheckReadPermission(CCrmOwnerType::ResolveName(CCrmLiveFeedEntity::ResolveEntityTypeID($arEntity['ENTITY_TYPE'])), $arEntity['ENTITY_ID'], $userPermissions)) { $url = $strLogEntryCrmURL; $bHasAccess = true; break; } } } if ($bHasAccess) { $arMessageFields["TO_USER_ID"] = $val; $arMessageFields["NOTIFY_TAG"] = "CRM|MESSAGE_MENTION|" . $messageID; $arMessageFields["NOTIFY_MESSAGE"] = GetMessage("CRM_SL_EVENT_IM_MENTION_POST" . $genderSuffix, array("#title#" => "<a href=\"" . $url . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($strIMMessageTitle) . "</a>")); $arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("CRM_SL_EVENT_IM_MENTION_POST" . $genderSuffix, array("#title#" => htmlspecialcharsbx($strIMMessageTitleOut))) . " (" . $serverName . $url . ")"; CIMNotify::Add($arMessageFields); } } } } return $messageID; } } return $errors; }
protected function rebind($seedID, $targID) { \CCrmDeal::Rebind(\CCrmOwnerType::Contact, $seedID, $targID); \CCrmQuote::Rebind(\CCrmOwnerType::Contact, $seedID, $targID); \CCrmActivity::Rebind(\CCrmOwnerType::Contact, $seedID, $targID); \CCrmLiveFeed::Rebind(\CCrmOwnerType::Contact, $seedID, $targID); \CCrmSonetRelation::RebindRelations(\CCrmOwnerType::Contact, $seedID, $targID); \CCrmEvent::Rebind(\CCrmOwnerType::Contact, $seedID, $targID); }
public function Delete($ID, $arOptions = array()) { global $DB, $APPLICATION; $ID = intval($ID); $iUserId = CCrmSecurityHelper::GetCurrentUserID(); $this->LAST_ERROR = ''; $APPLICATION->ResetException(); if (!is_array($arOptions)) { $arOptions = array(); } if (isset($arOptions['CHECK_DEPENDENCIES']) && (bool) $arOptions['CHECK_DEPENDENCIES']) { $dbRes = self::GetListEx(array(), array('=ID' => $ID), false, false, array('TITLE', 'STATUS_ID', 'COMPANY_ID', 'CONTACT_ID')); $arFields = $dbRes ? $dbRes->Fetch() : null; if (is_array($arFields) && isset($arFields['STATUS_ID']) && $arFields['STATUS_ID'] === 'CONVERTED' && (CCrmCompany::Exists(isset($arFields['COMPANY_ID']) ? intval($arFields['COMPANY_ID']) : 0) || CCrmContact::Exists(isset($arFields['CONTACT_ID']) ? intval($arFields['CONTACT_ID']) : 0))) { $title = isset($arFields['TITLE']) && $arFields['TITLE'] !== '' ? $arFields['TITLE'] : $ID; $err = GetMessage('CRM_LEAD_DELETION_DEPENDENCIES_FOUND', array('#TITLE#' => $title)); $this->LAST_ERROR = $err; $APPLICATION->throwException($err); return false; } } $sWherePerm = ''; if ($this->bCheckPermission) { $arEntityAttr = $this->cPerms->GetEntityAttr('LEAD', $ID); $sEntityPerm = $this->cPerms->GetPermType('LEAD', 'DELETE', $arEntityAttr[$ID]); if ($sEntityPerm == BX_CRM_PERM_NONE) { return false; } else { if ($sEntityPerm == BX_CRM_PERM_SELF) { $sWherePerm = " AND ASSIGNED_BY_ID = {$iUserId}"; } else { if ($sEntityPerm == BX_CRM_PERM_OPEN) { $sWherePerm = " AND (OPENED = 'Y' OR ASSIGNED_BY_ID = {$iUserId})"; } } } } $events = GetModuleEvents('crm', 'OnBeforeCrmLeadDelete'); while ($arEvent = $events->Fetch()) { if (ExecuteModuleEventEx($arEvent, array($ID)) === false) { $err = GetMessage("MAIN_BEFORE_DEL_ERR") . ' ' . $arEvent['TO_NAME']; if ($ex = $APPLICATION->GetException()) { $err .= ': ' . $ex->GetString(); } $APPLICATION->throwException($err); $this->LAST_ERROR = $err; return false; } } //By defaut we need to clean up related bizproc entities $processBizproc = isset($arOptions['PROCESS_BIZPROC']) ? (bool) $arOptions['PROCESS_BIZPROC'] : true; if ($processBizproc) { $bizproc = new CCrmBizProc('LEAD'); $bizproc->ProcessDeletion($ID); } $tableName = CCrmLead::TABLE_NAME; $sSql = "DELETE FROM {$tableName} WHERE ID = {$ID}{$sWherePerm}"; $obRes = $DB->Query($sSql, false, 'FILE: ' . __FILE__ . '<br /> LINE: ' . __LINE__); if (is_object($obRes) && $obRes->AffectedRowsCount() > 0) { CCrmSearch::DeleteSearch('LEAD', $ID); $DB->Query("DELETE FROM b_crm_entity_perms WHERE ENTITY='LEAD' AND ENTITY_ID = {$ID}", false, 'FILE: ' . __FILE__ . '<br /> LINE: ' . __LINE__); $GLOBALS['USER_FIELD_MANAGER']->Delete(self::$sUFEntityID, $ID); $CCrmFieldMulti = new CCrmFieldMulti(); $CCrmFieldMulti->DeleteByElement('LEAD', $ID); $CCrmEvent = new CCrmEvent(); $CCrmEvent->DeleteByElement('LEAD', $ID); \Bitrix\Crm\EntityAddress::unregister(CCrmOwnerType::Lead, $ID, \Bitrix\Crm\EntityAddress::Primary); \Bitrix\Crm\Integrity\DuplicateEntityRanking::unregisterEntityStatistics(CCrmOwnerType::Lead, $ID); \Bitrix\Crm\Integrity\DuplicatePersonCriterion::unregister(CCrmOwnerType::Lead, $ID); \Bitrix\Crm\Integrity\DuplicateOrganizationCriterion::unregister(CCrmOwnerType::Lead, $ID); \Bitrix\Crm\Integrity\DuplicateCommunicationCriterion::unregister(CCrmOwnerType::Lead, $ID); \Bitrix\Crm\Integrity\DuplicateIndexMismatch::unregisterEntity(CCrmOwnerType::Lead, $ID); $enableDupIndexInvalidation = is_array($arOptions) && isset($arOptions['ENABLE_DUP_INDEX_INVALIDATION']) ? (bool) $arOptions['ENABLE_DUP_INDEX_INVALIDATION'] : true; if ($enableDupIndexInvalidation) { \Bitrix\Crm\Integrity\DuplicateIndexBuilder::markAsJunk(CCrmOwnerType::Lead, $ID); } // Deletion of lead details CCrmProductRow::DeleteByOwner('L', $ID); CCrmProductRow::DeleteSettings('L', $ID); CCrmActivity::DeleteByOwner(CCrmOwnerType::Lead, $ID); CCrmSonetSubscription::UnRegisterSubscriptionByEntity(CCrmOwnerType::Lead, $ID); CCrmLiveFeed::DeleteLogEvents(array('ENTITY_TYPE_ID' => CCrmOwnerType::Lead, 'ENTITY_ID' => $ID)); if (defined("BX_COMP_MANAGED_CACHE")) { $GLOBALS["CACHE_MANAGER"]->ClearByTag("crm_entity_name_" . CCrmOwnerType::Lead . "_" . $ID); } $afterEvents = GetModuleEvents('crm', 'OnAfterCrmLeadDelete'); while ($arEvent = $afterEvents->Fetch()) { ExecuteModuleEventEx($arEvent, array($ID)); } } return true; }
public function RegisterBundle($logEntityID, $logEventID, $entityTypeID, $entityID, &$parents, $options = array()) { if (!CCrmOwnerType::IsDefined($entityTypeID)) { return; } $logEntityID = intval($logEntityID); $entityID = intval($entityID); if ($logEntityID <= 0 || $entityID <= 0) { return; } if (!is_array($parents)) { return; } if (!is_array($options)) { $options = array(); } $entityTypeIDKey = isset($options['ENTITY_TYPE_ID_KEY']) ? $options['ENTITY_TYPE_ID_KEY'] : ''; if ($entityTypeIDKey === '') { $entityTypeIDKey = 'ENTITY_TYPE_ID'; } $entityIDKey = isset($options['ENTITY_ID_KEY']) ? $options['ENTITY_ID_KEY'] : ''; if ($entityIDKey === '') { $entityIDKey = 'ENTITY_ID'; } $defaultTypeID = isset($options['TYPE_ID']) ? intval($options['TYPE_ID']) : CCrmOwnerType::Undefined; if (!CCrmSonetRelationType::IsDefined($defaultTypeID)) { $defaultTypeID = CCrmSonetRelationType::Ownership; } $items = array(); $slEntityType = CCrmLiveFeedEntity::GetByEntityTypeID($entityTypeID); $logLastUpdateTime = CCrmLiveFeed::GetLogEventLastUpdateTime($logEntityID, false); foreach ($parents as &$parent) { $parentEntityTypeID = isset($parent[$entityTypeIDKey]) ? intval($parent[$entityTypeIDKey]) : CCrmOwnerType::Undefined; $parentEntityID = isset($parent[$entityIDKey]) ? intval($parent[$entityIDKey]) : 0; if (!CCrmOwnerType::IsDefined($parentEntityTypeID) || $parentEntityID <= 0) { continue; } $key = "{$parentEntityTypeID}_{$parentEntityID}"; if (isset($items[$key])) { continue; } $typeID = isset($parent['TYPE_ID']) ? intval($parent['TYPE_ID']) : CCrmSonetRelationType::Undefined; if (!CCrmSonetRelationType::IsDefined($typeID)) { $typeID = $defaultTypeID; } $level = isset($parent['LEVEL']) ? max(intval($parent['LEVEL']), 1) : 1; $items[$key] = array('SL_ID' => $logEntityID, 'SL_EVENT_ID' => $logEventID, 'SL_ENTITY_TYPE' => $slEntityType, 'ENTITY_ID' => $entityID, 'SL_PARENT_ENTITY_TYPE' => CCrmLiveFeedEntity::GetByEntityTypeID($parentEntityTypeID), 'PARENT_ENTITY_ID' => $parentEntityID, 'SL_LAST_UPDATED' => $logLastUpdateTime, 'TYPE_ID' => $typeID, 'LVL' => $level); } unset($parent); global $DB; CTimeZone::Disable(); $bulkColumns = ''; $bulkValues = array(); foreach ($items as &$item) { $data = $DB->PrepareInsert(self::TABLE_NAME, $item); if (strlen($bulkColumns) == 0) { $bulkColumns = $data[0]; } $bulkValues[] = $data[1]; } unset($item); CTimeZone::Enable(); if (count($bulkValues) == 0) { return; } $query = ''; foreach ($bulkValues as &$value) { if ($query !== '') { $query .= ','; } $query .= "({$value})"; } if (strlen($query) == 0) { return; } $DB->Query('INSERT INTO ' . self::TABLE_NAME . '(' . $bulkColumns . ') VALUES' . $query, false, 'File: ' . __FILE__ . '<br/>Line: ' . __LINE__); }
public function Delete($ID, $arOptions = array()) { global $DB, $APPLICATION; $ID = intval($ID); $iUserId = CCrmSecurityHelper::GetCurrentUserID(); $sWherePerm = ''; if ($this->bCheckPermission) { $arEntityAttr = $this->cPerms->GetEntityAttr('COMPANY', $ID); $sEntityPerm = $this->cPerms->GetPermType('COMPANY', 'DELETE', $arEntityAttr[$ID]); if ($sEntityPerm == BX_CRM_PERM_NONE) { return false; } else { if ($sEntityPerm == BX_CRM_PERM_SELF) { $sWherePerm = " AND ASSIGNED_BY_ID = {$iUserId}"; } else { if ($sEntityPerm == BX_CRM_PERM_OPEN) { $sWherePerm = " AND (OPENED = 'Y' OR ASSIGNED_BY_ID = {$iUserId})"; } } } } $APPLICATION->ResetException(); $events = GetModuleEvents('crm', 'OnBeforeCrmCompanyDelete'); while ($arEvent = $events->Fetch()) { if (ExecuteModuleEventEx($arEvent, array($ID)) === false) { $err = GetMessage("MAIN_BEFORE_DEL_ERR") . ' ' . $arEvent['TO_NAME']; if ($ex = $APPLICATION->GetException()) { $err .= ': ' . $ex->GetString(); } $APPLICATION->throwException($err); return false; } } $obRes = $DB->Query("DELETE FROM b_crm_company WHERE ID = {$ID}{$sWherePerm}", false, 'FILE: ' . __FILE__ . '<br /> LINE: ' . __LINE__); if (is_object($obRes) && $obRes->AffectedRowsCount() > 0) { $DB->Query("DELETE FROM b_crm_entity_perms WHERE ENTITY='COMPANY' AND ENTITY_ID = {$ID}", false, 'FILE: ' . __FILE__ . '<br /> LINE: ' . __LINE__); $GLOBALS['USER_FIELD_MANAGER']->Delete(self::$sUFEntityID, $ID); $CCrmFieldMulti = new CCrmFieldMulti(); $CCrmFieldMulti->DeleteByElement('COMPANY', $ID); $CCrmEvent = new CCrmEvent(); $CCrmEvent->DeleteByElement('COMPANY', $ID); \Bitrix\Crm\Integrity\DuplicateEntityRanking::unregisterEntityStatistics(CCrmOwnerType::Company, $ID); \Bitrix\Crm\Integrity\DuplicateOrganizationCriterion::unregister(CCrmOwnerType::Company, $ID); \Bitrix\Crm\Integrity\DuplicateCommunicationCriterion::unregister(CCrmOwnerType::Company, $ID); \Bitrix\Crm\Integrity\DuplicateIndexMismatch::unregisterEntity(CCrmOwnerType::Company, $ID); $enableDupIndexInvalidation = is_array($arOptions) && isset($arOptions['ENABLE_DUP_INDEX_INVALIDATION']) ? (bool) $arOptions['ENABLE_DUP_INDEX_INVALIDATION'] : true; if ($enableDupIndexInvalidation) { \Bitrix\Crm\Integrity\DuplicateIndexBuilder::markAsJunk(CCrmOwnerType::Company, $ID); } CCrmActivity::DeleteByOwner(CCrmOwnerType::Company, $ID); CCrmSearch::DeleteSearch('COMPANY', $ID); CCrmSonetSubscription::UnRegisterSubscriptionByEntity(CCrmOwnerType::Company, $ID); CCrmLiveFeed::DeleteLogEvents(array('ENTITY_TYPE_ID' => CCrmOwnerType::Company, 'ENTITY_ID' => $ID)); if (defined("BX_COMP_MANAGED_CACHE")) { $GLOBALS["CACHE_MANAGER"]->ClearByTag("crm_entity_name_" . CCrmOwnerType::Company . "_" . $ID); } } return true; }
private static function UnregisterLiveFeedEvent($invoiceID) { $invoiceID = intval($invoiceID); if ($invoiceID <= 0) { return; } $slEntities = CCrmLiveFeed::GetLogEvents(array(), array('ENTITY_TYPE_ID' => CCrmOwnerType::Invoice, 'ENTITY_ID' => $invoiceID), array('ID')); $options = array('UNREGISTER_RELATION' => false); foreach ($slEntities as &$slEntity) { CCrmLiveFeed::DeleteLogEvent($slEntity['ID'], $options); } unset($slEntity); CCrmSonetRelation::UnRegisterRelationsByEntity(CCrmOwnerType::Invoice, $invoiceID); }