public function calculateEntityCount(DuplicateCriterion $criterion, array $options = null)
 {
     $entityTypeID = $this->getEntityTypeID();
     $enablePermissionCheck = $this->isPermissionCheckEnabled();
     $userID = $this->getUserID();
     $query = new Main\Entity\Query(DuplicateCommunicationMatchCodeTable::getEntity());
     $query->addSelect('QTY');
     $query->registerRuntimeField('', new Main\Entity\ExpressionField('QTY', 'COUNT(*)'));
     $query->addFilter('=ENTITY_TYPE_ID', $entityTypeID);
     if ($enablePermissionCheck) {
         $permissionSql = $this->preparePermissionSql();
         if ($permissionSql === false) {
             //Access denied;
             return 0;
         }
         if (is_string($permissionSql) && $permissionSql !== '') {
             $query->addFilter('@ENTITY_ID', new Main\DB\SqlExpression($permissionSql));
         }
     }
     $matches = $criterion->getMatches();
     $type = isset($matches['TYPE']) ? $matches['TYPE'] : '';
     if ($type === '') {
         throw new Main\ArgumentException("Parameter 'TYPE' is required.", 'matches');
     }
     $value = isset($matches['VALUE']) ? $matches['VALUE'] : '';
     if ($type === '') {
         throw new Main\ArgumentException("Parameter 'VALUE' is required.", 'matches');
     }
     $query->addFilter('=TYPE', $type);
     $query->addFilter('=VALUE', $value);
     $rootEntityID = 0;
     if (is_array($options) && isset($options['ROOT_ENTITY_ID'])) {
         $rootEntityID = (int) $options['ROOT_ENTITY_ID'];
     }
     if ($rootEntityID > 0) {
         $query->addFilter('!ENTITY_ID', $rootEntityID);
         $query->addFilter('!@ENTITY_ID', DuplicateIndexMismatch::prepareQueryField($criterion, $entityTypeID, $rootEntityID, $userID));
     }
     $limit = 0;
     if (is_array($options) && isset($options['LIMIT'])) {
         $limit = (int) $options['LIMIT'];
     }
     if ($limit > 0) {
         $query->setLimit($limit);
     }
     $dbResult = $query->exec();
     $fields = $dbResult->fetch();
     return is_array($fields) && isset($fields['QTY']) ? intval($fields['QTY']) : 0;
 }
 public static function prepareQueryField(DuplicateCriterion $criterion, $entityTypeID, $entityID, $userID)
 {
     $typeID = $criterion->getIndexTypeID();
     $matchHash = $criterion->getMatchHash();
     $sql = array();
     $query = new Main\Entity\Query(Entity\DuplicateIndexMismatchTable::getEntity());
     $query->addSelect('R_ENTITY_ID', 'ENTITY_ID');
     $query->addFilter('=USER_ID', $userID);
     $query->addFilter('=ENTITY_TYPE_ID', $entityTypeID);
     $query->addFilter('=TYPE_ID', $typeID);
     $query->addFilter('=MATCH_HASH', $matchHash);
     $query->addFilter('=L_ENTITY_ID', $entityID);
     $sql[] = $query->getQuery();
     $query = new Main\Entity\Query(Entity\DuplicateIndexMismatchTable::getEntity());
     $query->addSelect('L_ENTITY_ID', 'ENTITY_ID');
     $query->addFilter('=USER_ID', $userID);
     $query->addFilter('=ENTITY_TYPE_ID', $entityTypeID);
     $query->addFilter('=TYPE_ID', $typeID);
     $query->addFilter('=MATCH_HASH', $matchHash);
     $query->addFilter('=R_ENTITY_ID', $entityID);
     $sql[] = $query->getQuery();
     return new Main\DB\SqlExpression(implode(' UNION ALL ', $sql));
 }
Пример #3
0
 public function processEntityDeletion(DuplicateCriterion $criterion, $entityID)
 {
     if (!is_int($entityID)) {
         $entityID = (int) $entityID;
     }
     if ($entityID <= 0) {
         return;
     }
     $matchHash = $criterion->getMatchHash();
     $rootEntityID = $this->getRootEntityID($matchHash);
     if ($rootEntityID <= 0) {
         return;
     }
     $entityTypeID = $this->getEntityTypeID();
     $userID = $this->getUserID();
     $enablePermissionCheck = $this->isPermissionCheckEnabled();
     $quantity = $criterion->getActualCount($entityTypeID, $rootEntityID, $userID, $enablePermissionCheck, 100);
     if ($quantity === 0) {
         Entity\DuplicateIndexTable::delete($this->getPrimaryKey($matchHash));
         return;
     }
     if ($entityID !== $rootEntityID) {
         return;
     }
     $dataSource = $this->getDataSource();
     $result = $dataSource->getList(0, 100);
     $item = $result->getItem($matchHash);
     if (!$item) {
         return;
     }
     $rankings = $item->getAllRankings();
     DuplicateEntityRanking::initializeBulk($rankings, array('CHECK_PERMISSIONS' => $enablePermissionCheck, 'USER_ID' => $userID));
     $rootEntityInfo = array();
     if (!$this->tryResolveRootEntity($item, $matchHash, $rootEntityInfo)) {
         Entity\DuplicateIndexTable::delete($this->getPrimaryKey($matchHash));
         return;
     }
     $rootEntityID = $rootEntityInfo['ENTITY_ID'];
     $item->setRootEntityID($rootEntityID);
     $sortParams = $this->prepareSortParams(array($rootEntityID));
     $data = $this->prepareTableData($matchHash, $item, $sortParams, true);
     Entity\DuplicateIndexTable::upsert($data);
 }
Пример #4
0
 public function registerCriterionMismatch(Integrity\DuplicateCriterion $criterion, $leftEntityID, $rightEntityID)
 {
     $entityTypeID = $this->entityTypeID;
     $userID = $this->userID;
     $typeID = $criterion->getIndexTypeID();
     $matchHash = $criterion->getMatchHash();
     if ($matchHash === '') {
         throw new Main\ArgumentException('Match hash is empty', 'criterion');
     }
     Integrity\DuplicateIndexMismatch::register($entityTypeID, $leftEntityID, $rightEntityID, $typeID, $matchHash, $userID);
 }
 public function equals(DuplicateCriterion $item)
 {
     if (!$item instanceof DuplicatePersonCriterion) {
         return false;
     }
     /** @var DuplicatePersonCriterion $item */
     return $this->name === $item->getName() && $this->secondName === $item->getSecondName() && $this->lastName === $item->getLastName();
 }
 public function equals(DuplicateCriterion $item)
 {
     if (!$item instanceof DuplicateOrganizationCriterion) {
         return false;
     }
     /** @var DuplicateOrganizationCriterion $item */
     return $this->title === $item->getTitle();
 }
 public function equals(DuplicateCriterion $item)
 {
     if (!$item instanceof DuplicateCommunicationCriterion) {
         return false;
     }
     /** @var DuplicateCommunicationCriterion $item */
     if ($this->communicationType !== $item->getCommunicationType()) {
         return false;
     }
     if ($this->communicationType === 'PHONE') {
         return self::normalizePhone($this->value) === self::normalizePhone($item->getValue());
     }
     return $this->value === $item->getValue();
 }