CAllCrmQuote::Delete

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CAllCrmQuote
  4. Delete
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_quote.php
  • Класс: \CAllCrmQuote
  • Вызов: CAllCrmQuote::Delete
public function Delete($ID, $options = array())
{
	$this->lastErrors = null;

	$ID = (int)$ID;

	if(!is_array($options))
	{
		$options = array();
	}

	if($this->isUseOperation())
	{
		return $this->getCompatibilityAdapter()->performDelete($ID, $options);
	}

	global $DB, $APPLICATION;

	if(isset($options['CURRENT_USER']))
	{
		$iUserId = intval($options['CURRENT_USER']);
	}
	else
	{
		$iUserId = CCrmSecurityHelper::GetCurrentUserID();
	}

	$dbResult = CCrmQuote::GetList(
		array(),
		array('=ID' => $ID, 'CHECK_PERMISSIONS' => 'N'),
		false,
		false,
		array('QUOTE_NUMBER', 'TITLE')
	);

	$arFields = is_object($dbResult) ? $dbResult->Fetch() : null;
	if(!is_array($arFields))
	{
		return false;
	}

	$sWherePerm = '';
	if ($this->bCheckPermission)
	{
		$arEntityAttr = $this->cPerms->GetEntityAttr(self::$TYPE_NAME, $ID);
		$sEntityPerm = $this->cPerms->GetPermType(self::$TYPE_NAME, '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();
	foreach (GetModuleEvents('crm', 'OnBeforeCrmQuoteDelete', true) as $arEvent)
	{
		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;
		}
	}

	if (!(isset($options['SKIP_FILES']) && $options['SKIP_FILES']))
	{
		if(!self::DeleteStorageElements($ID))
			return false;

		if(!$DB->Query(
			'DELETE FROM '.CCrmQuote::ELEMENT_TABLE_NAME.' WHERE QUOTE_ID = '.$ID,
			false, 'File: '.__FILE__.'
Line: '.__LINE__)) { $APPLICATION->throwException(GetMessage('CRM_QUOTE_ERR_DELETE_STORAGE_ELEMENTS_QUERY_MSGVER_1')); return false; } } $dbRes = $DB->Query("DELETE FROM b_crm_quote WHERE ID = {$ID}{$sWherePerm}", false, 'FILE: '.__FILE__.'
LINE: '.__LINE__); if (is_object($dbRes) && $dbRes->AffectedRowsCount() > 0) { Bitrix\Crm\Kanban\SortTable::clearEntity($ID, \CCrmOwnerType::QuoteName); Crm\Security\Manager::getEntityController(CCrmOwnerType::Quote) ->unregister(self::$TYPE_NAME, $ID) ; QuoteContactTable::unbindAllContacts($ID); $GLOBALS['USER_FIELD_MANAGER']->Delete(self::$sUFEntityID, $ID); $CCrmFieldMulti = new CCrmFieldMulti(); $CCrmFieldMulti->DeleteByElement('QUOTE', $ID); $CCrmEvent = new CCrmEvent(); $CCrmEvent->DeleteByElement('QUOTE', $ID); CCrmSearch::DeleteSearch('QUOTE', $ID); // Deletion of quote details CCrmProductRow::DeleteByOwner(self::OWNER_TYPE, $ID); CCrmProductRow::DeleteSettings(self::OWNER_TYPE, $ID); /*CCrmActivity::DeleteByOwner(CCrmOwnerType::Quote, $ID);*/ \Bitrix\Crm\Requisite\EntityLink::unregister(CCrmOwnerType::Quote, $ID); self::getCommentsAdapter()->performDelete((int)$ID, $options); // delete utm fields UtmTable::deleteEntityUtm(CCrmOwnerType::Quote, $ID); Tracking\Entity::deleteTrace(CCrmOwnerType::Quote, $ID); if(Bitrix\Crm\Settings\HistorySettings::getCurrent()->isQuoteDeletionEventEnabled()) { CCrmEvent::RegisterDeleteEvent(CCrmOwnerType::Quote, $ID, $iUserId, array('FIELDS' => $arFields)); } if(defined("BX_COMP_MANAGED_CACHE")) { $GLOBALS['CACHE_MANAGER']->CleanDir('b_crm_quote'); $GLOBALS["CACHE_MANAGER"]->ClearByTag("crm_entity_name_".CCrmOwnerType::Quote."_".$ID); } $afterEvents = GetModuleEvents('crm', 'OnAfterCrmQuoteDelete'); while ($arEvent = $afterEvents->Fetch()) { ExecuteModuleEventEx($arEvent, array($ID)); } } return true; }

Добавить комментарий