public function __construct($userID, $enablePermissionCheck = false) { parent::__construct(\CCrmOwnerType::Contact, $userID, $enablePermissionCheck); }
public function merge($seedID, $targID, Integrity\DuplicateCriterion $targCriterion) { if (!is_int($seedID)) { $seedID = (int) $seedID; } if (!is_int($targID)) { $targID = (int) $targID; } $entityTypeID = $this->entityTypeID; if ($this->enablePermissionCheck && !$this->userIsAdmin) { $userPermissions = $this->getUserPermissions(); if (!$this->checkEntityReadPermission($seedID, $userPermissions)) { throw new EntityMergerException($entityTypeID, $seedID, self::ROLE_SEED, EntityMergerException::READ_DENIED); } if (!$this->checkEntityDeletePermission($seedID, $userPermissions)) { throw new EntityMergerException($entityTypeID, $seedID, self::ROLE_SEED, EntityMergerException::DELETE_DENIED); } if (!$this->checkEntityReadPermission($targID, $userPermissions)) { throw new EntityMergerException($entityTypeID, $targID, self::ROLE_TARG, EntityMergerException::READ_DENIED); } if (!$this->checkEntityUpdatePermission($targID, $userPermissions)) { throw new EntityMergerException($entityTypeID, $targID, self::ROLE_TARG, EntityMergerException::UPDATE_DENIED); } } $collisions = self::getMergeCollisions($seedID, $targID); $seed = $this->getEntityFields($seedID, self::ROLE_SEED); $targ = $this->getEntityFields($targID, self::ROLE_TARG); $entityFieldInfos = $this->getEntityFieldsInfo(); $userFieldInfos = $this->getEntityUserFieldsInfo(); EntityMerger::mergeEntityFields($seed, $targ, $entityFieldInfos); EntityMerger::mergeUserFields($seed, $targ, $userFieldInfos); $seedMultiFields = $this->getEntityMultiFields($seedID, self::ROLE_SEED); $targMultiFields = $this->getEntityMultiFields($targID, self::ROLE_TARG); EntityMerger::mergeMultiFields($seedMultiFields, $targMultiFields); if (!empty($targMultiFields)) { $targ['FM'] = $targMultiFields; } //$recoveryData = self::prepareRecoveryData($seed, $entityFieldInfos, $userFieldInfos); //$recoveryData->setEntityTypeID($entityTypeID); //$recoveryData->setEntityID($seedID); //$this->setupRecoveryData($recoveryData, $seed); //if(!empty($seedMultiFields)) //{ // $recoveryData->setDataItem('MULTI_FIELDS', $seedMultiFields); //} //$activityIDs = \CCrmActivity::GetBoundIDs($entityTypeID, $seedID); //if(!empty($activityIDs)) //{ // $recoveryData->setDataItem('ACTIVITY_IDS', $activityIDs); //} //$eventIDs = array(); //$result = \CCrmEvent::GetListEx( // array('EVENT_REL_ID' => 'ASC'), // array( // 'ENTITY_TYPE' => $entityTypeName, // 'ENTITY_ID' => $seedID, // 'EVENT_TYPE' => 0, // 'CHECK_PERMISSIONS' => 'N' // ), // false, // false, // array('EVENT_REL_ID') //); //if(is_object($result)) //{ // while($eventFields = $result->Fetch()) // { // $eventIDs[] = (int)$eventFields['EVENT_REL_ID']; // } //} //if(!empty($eventIDs)) //{ // $recoveryData->setDataItem('EVENT_IDS', $eventIDs); //} //$recoveryData->setUserID($this->userID); //$recoveryData->save(); $this->updateEntity($targID, $targ, self::ROLE_TARG); $this->rebind($seedID, $targID); $matches = $this->getRegisteredEntityMatches($entityTypeID, $seedID); $targIndexTypeID = $targCriterion->getIndexTypeID(); if (!isset($matches[$targIndexTypeID])) { $matches[$targIndexTypeID] = array(); } $targetMatchHash = $targCriterion->getMatchHash(); if (!isset($matches[$targIndexTypeID][$targetMatchHash])) { $matches[$targIndexTypeID][$targetMatchHash] = $targCriterion->getMatches(); } $this->deleteEntity($seedID, self::ROLE_SEED, array('ENABLE_DUP_INDEX_INVALIDATION' => false)); if (!empty($matches)) { $this->processEntityDeletion($entityTypeID, $seedID, $matches); } Integrity\DuplicateIndexBuilder::markAsJunk($entityTypeID, $seedID); if (!empty($collisions)) { $messageFields = $this->prepareCollisionMessageFields($collisions, $seed, $targ); if (is_array($messageFields) && !empty($messageFields) && Main\Loader::includeModule('im')) { $messageFields['FROM_USER_ID'] = $this->userID; $messageFields['MESSAGE_TYPE'] = IM_MESSAGE_SYSTEM; $messageFields['NOTIFY_TYPE'] = IM_NOTIFY_FROM; $messageFields['NOTIFY_MODULE'] = 'crm'; $messageFields['NOTIFY_EVENT'] = 'merge'; $messageFields['NOTIFY_TAG'] = 'CRM|MERGE|COLLISION'; \CIMNotify::Add($messageFields); } } }
__CrmDedupeListEndResonse(array('ERROR' => "Entity type '{$entityTypeName}' is not supported in current context.")); } $leftEntityID = isset($_POST['LEFT_ENTITY_ID']) ? (int) $_POST['LEFT_ENTITY_ID'] : 0; if ($leftEntityID <= 0) { __CrmDedupeListEndResonse(array('ERROR' => 'Left entity ID is not is not specified.')); } $rightEntityID = isset($_POST['RIGHT_ENTITY_ID']) ? (int) $_POST['RIGHT_ENTITY_ID'] : 0; if ($rightEntityID <= 0) { __CrmDedupeListEndResonse(array('ERROR' => 'Right entity ID is not is not specified.')); } $typeID = isset($_POST['INDEX_TYPE_NAME']) ? Integrity\DuplicateIndexType::resolveID($_POST['INDEX_TYPE_NAME']) : Integrity\DuplicateIndexType::UNDEFINED; if (!Integrity\DuplicateIndexType::isDefined($typeID)) { __CrmDedupeListEndResonse(array('ERROR' => 'Index type ID is not specified or invalid.')); } $enablePermissionCheck = !CCrmPerms::IsAdmin($currentUserID); $merger = Merger\EntityMerger::create($entityTypeID, $currentUserID, $enablePermissionCheck); $leftEntityMatches = isset($_POST['LEFT_ENTITY_INDEX_MATCHES']) && is_array($_POST['LEFT_ENTITY_INDEX_MATCHES']) ? $_POST['LEFT_ENTITY_INDEX_MATCHES'] : array(); $leftEntityCriterion = Integrity\DuplicateManager::createCriterion($typeID, $leftEntityMatches); $rightEntityMatches = isset($_POST['RIGHT_ENTITY_INDEX_MATCHES']) && is_array($_POST['RIGHT_ENTITY_INDEX_MATCHES']) ? $_POST['RIGHT_ENTITY_INDEX_MATCHES'] : array(); if (empty($rightEntityMatches)) { $rightEntityMatches = $leftEntityMatches; } $rightEntityCriterion = Integrity\DuplicateManager::createCriterion($typeID, $rightEntityMatches); try { $merger->registerCriterionMismatch($rightEntityCriterion, $leftEntityID, $rightEntityID); $builder = Integrity\DuplicateManager::createIndexBuilder($typeID, $entityTypeID, $currentUserID, $enablePermissionCheck); $builder->processMismatchRegistration($leftEntityCriterion, $leftEntityID); } catch (Merger\EntityMergerException $e) { __CrmDedupeListEndResonse(array('ERROR' => __CrmDedupeListErrorText($e))); } catch (Exception $e) { __CrmDedupeListEndResonse(array('ERROR' => $e->getMessage()));