Skip to content

Commit

Permalink
Fix If value is empty. Skip that
Browse files Browse the repository at this point in the history
  • Loading branch information
kuzmany committed Sep 30, 2019
1 parent 5047238 commit de2563b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
2 changes: 0 additions & 2 deletions Command/CustomDeduplicateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Mautic\LeadBundle\Command\DeduplicateCommand;
use Mautic\LeadBundle\Deduplicate\ContactDeduper;
use Mautic\PluginBundle\Helper\IntegrationHelper;
use Mautic\UserBundle\Entity\User;
use Mautic\UserBundle\Model\UserModel;
use Monolog\Logger;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -122,7 +121,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

$notify = (bool) $input->getOption('notify');

$key = __CLASS__;
if (!$this->checkRunStatus($input, $output, $key)) {
if ($notify) {
Expand Down
15 changes: 7 additions & 8 deletions Deduplicate/CustomDuplications.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,15 @@ private function getContactsByUniqueFields($uniqueFieldsWithData, $leadId = null
$q = $this->entityManager->getConnection()->createQueryBuilder()
->select('l.*')
->from(MAUTIC_TABLE_PREFIX.'leads', 'l');

// loop through the fields and
foreach ($uniqueFieldsWithData as $col => $val) {
$q->andWhere("l.$col = :".$col)
->setParameter($col, $val);
$q->andWhere(
$q->expr()->andX(
$q->expr()->eq('l.'.$col, ':'.$col),
$q->expr()->neq('l.'.$col, $q->expr()->literal('')),
$q->expr()->isNotNull('l.'.$col)
)
)->setParameter($col, $val);
}

// if we have a lead ID lets use it
Expand All @@ -114,7 +118,6 @@ private function getContactsByUniqueFields($uniqueFieldsWithData, $leadId = null
$q->setMaxResults($limit);
}
$results = $q->execute()->fetchAll();

// Collect the IDs
$leads = [];
foreach ($results as $r) {
Expand Down Expand Up @@ -147,10 +150,6 @@ private function getCustomUniqueData(array $queryFields)
$uniqueLeadFields = $this->fields->getCustomUniqueFields();
$uniqueLeadFieldData = [];
foreach ($queryFields as $k => $v) {
// Don't use empty values when checking for duplicates
if (empty($v)) {
continue;
}
if (in_array($k, $uniqueLeadFields)) {
$uniqueLeadFieldData[$k] = $v;
}
Expand Down

0 comments on commit de2563b

Please sign in to comment.