...Человеческий поиск в разработке...
- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/lib/recycling/activitycontroller.php
- Класс: Bitrix\Crm\Recycling\ActivityController
- Вызов: ActivityController::recover
public function recover($entityID, array $params = array()) { if($entityID <= 0) { return false; } $recyclingEntityID = isset($params['ID']) ? (int)$params['ID'] : 0; if($recyclingEntityID <= 0) { return false; } $slots = isset($params['SLOTS']) ? $params['SLOTS'] : null; if(!is_array($slots)) { return false; } $fields = isset($slots['FIELDS']) ? $slots['FIELDS'] : null; if(!(is_array($fields) && !empty($fields))) { return false; } unset($fields['ID'], $fields['COMPANY_ID'], $fields['COMPANY_IDS'], $fields['LEAD_ID']); $relationMap = RelationMap::createByEntity(\CCrmOwnerType::Activity, $entityID, $recyclingEntityID); $relationMap->build(); $ownerTypeID = isset($fields['OWNER_TYPE_ID']) ? (int)$fields['OWNER_TYPE_ID'] : 0; $ownerID = isset($fields['OWNER_ID']) ? (int)$fields['OWNER_ID'] : 0; if($ownerTypeID > 0 && $ownerID > 0) { $newOwnerID = $relationMap->findRenewedEntityID($ownerTypeID, $ownerID); if($newOwnerID > 0) { $fields['OWNER_ID'] = $ownerID = $newOwnerID; } if(empty(Crm\Entity\EntityManager::selectExisted($ownerTypeID, [ $ownerID ]))) { $errorMessage = ''; $controller = ControllerManager::resolveController($ownerTypeID); if($controller) { $errorMessage = $controller->getActivityOwnerNotFoundMessage( $ownerTypeID, $ownerID, [ 'ID' => $entityID, 'title' => isset($params['ENTITY']) ? $params['ENTITY']->getTitle() : '' ] ); } if($errorMessage === '') { $errorMessage = $this->getActivityOwnerNotFoundMessage($ownerTypeID, $ownerID, []); } throw new Main\InvalidOperationException($errorMessage); } } ActivityRelationManager::getInstance()->prepareRecoveryFields($fields, $relationMap); //region Convert User Fields from Suspended Type $userFields = $this->prepareRestoredUserFields($recyclingEntityID); if(!empty($userFields)) { $fields = array_merge($fields, $userFields); } //endregion $communications = isset($slots['COMMUNICATIONS']) ? $slots['COMMUNICATIONS'] : null; if(is_array($communications)) { for($i = 0, $length = count($communications); $i < $length; $i++) { $commEntityTypeID = isset($communications[$i]['ENTITY_TYPE_ID']) ? (int)$communications[$i]['ENTITY_TYPE_ID'] : \CCrmOwnerType::Undefined; $commEntityID = isset($communications[$i]['ENTITY_ID']) ? (int)$communications[$i]['ENTITY_ID'] : 0; if(!$relationMap->isEmpty()) { $newCommEntityID = $relationMap->findRenewedEntityID($commEntityTypeID, $commEntityID); if($newCommEntityID > 0) { $communications[$i]['ENTITY_ID'] = $newCommEntityID; } } } $fields['COMMUNICATIONS'] = $communications; } $bindingMap = array(); if($ownerTypeID > 0 && $ownerID > 0) { $bindingMap["{$ownerTypeID}_{$ownerID}"] = array('OWNER_TYPE_ID' => $ownerTypeID, 'OWNER_ID' => $ownerID); } $entityInfos = array_merge( $relationMap->getSourceEntityInfos(), $relationMap->getDestinationEntityInfos() ); foreach($entityInfos as $entityInfo) { $bindingKey = "{$entityInfo['ENTITY_TYPE_ID']}_{$entityInfo['ENTITY_ID']}"; if(!isset($bindingMap[$bindingKey])) { $bindingMap[$bindingKey] = array( 'OWNER_TYPE_ID' => $entityInfo['ENTITY_TYPE_ID'], 'OWNER_ID' => $entityInfo['ENTITY_ID'] ); } } $fields['BINDINGS'] = array_values($bindingMap); //region Files $files = isset($params['FILES']) ? $params['FILES'] : null; if(is_array($files)) { $storageElementIDs = []; foreach($files as $file) { $storageElementIDs[] = (int)$file['FILE_ID']; } $fields['STORAGE_ELEMENT_IDS'] = $storageElementIDs; } //endregion $newEntityID = 0; $provider = \CCrmActivity::GetActivityProvider($fields); if($provider) { $result = $provider::processRestorationFromRecycleBin( $fields, [ 'creationParams' => [ 'IS_RESTORATION' => true, 'DISABLE_USER_FIELD_CHECK' => true ] ] ); if($result->isSuccess()) { $resultData = $result->getData(); if(is_array($resultData) && isset($resultData['entityId'])) { $newEntityID = $resultData['entityId']; } } } if($newEntityID <= 0) { $newEntityID = \CCrmActivity::Add( $fields, false, false, array( 'IS_RESTORATION' => true, 'DISABLE_USER_FIELD_CHECK' => true ) ); } if($newEntityID <= 0) { return false; } $this->notifyTimelineMonitorAboutMoveFromBin($fields['BINDINGS'] ?? []); //region Relations ActivityRelationManager::getInstance()->recoverBindings($newEntityID, $relationMap); Relation::updateEntityID(\CCrmOwnerType::Activity, $entityID, $newEntityID, $recyclingEntityID); //endregion $this->eraseSuspendedUserFields($recyclingEntityID); $this->recoverTimeline($recyclingEntityID, $newEntityID); $this->recoverLiveFeed($recyclingEntityID, $newEntityID); $this->recoverBadges((int)$recyclingEntityID, (int)$newEntityID); $this->recoverNotes((int)$recyclingEntityID, (int)$newEntityID); //region Relations Relation::unregisterRecycleBin($recyclingEntityID); Relation::deleteJunks(); //endregion unset($this->entityIdToRecyclingEntityId[$entityID]); $this->rebuildSearchIndex($newEntityID); $this->fireAfterRecoverEvent($recyclingEntityID, $newEntityID); return true; }