Пример #1
0
 protected function tryResolveRootEntity(Duplicate $item, $matchHash, array &$entityInfo)
 {
     $entityTypeID = $this->getEntityTypeID();
     $entities = $item->getEntitiesByType($entityTypeID);
     /** @var DuplicateEntity[] $entities */
     $qty = count($entities);
     if ($qty == 0) {
         return false;
     } elseif ($qty === 1) {
         $entity = $entities[0];
         $entityID = $entity->getEntityID();
         $entityInfo['ENTITY_ID'] = $entityID;
         return true;
     }
     $entityID = $item->getRootEntityID();
     $entity = $entityID > 0 ? $item->findEntity($entityTypeID, $entityID) : null;
     if ($entity) {
         if ($this->checkRootEntityMismatches($entityID, $matchHash, $entities)) {
             $entityInfo['ENTITY_ID'] = $entityID;
             return true;
         }
     }
     usort($entities, array('Bitrix\\Crm\\Integrity\\DuplicateEntity', 'compareByRanking'));
     for ($i = $qty - 1; $i >= 0; $i--) {
         $entity = $entities[$i];
         if ($entity->getCriterion() !== null) {
             continue;
         }
         $entityID = $entity->getEntityID();
         if ($this->checkRootEntityMismatches($entityID, $matchHash, $entities)) {
             $entityInfo['ENTITY_ID'] = $entityID;
             return true;
         }
     }
     return false;
 }