-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use a LegacyLeadModel to work around circular dependency for merging …
…leads
- Loading branch information
1 parent
6bad9a0
commit 3a7151a
Showing
4 changed files
with
113 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
/* | ||
* @copyright 2018 Mautic Contributors. All rights reserved | ||
* @author Mautic, Inc. | ||
* | ||
* @link https://mautic.org | ||
* | ||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html | ||
*/ | ||
|
||
namespace Mautic\LeadBundle\Model; | ||
|
||
use Mautic\LeadBundle\Deduplicate\ContactMerger; | ||
use Mautic\LeadBundle\Deduplicate\Exception\SameContactException; | ||
use Mautic\LeadBundle\Entity\Lead; | ||
use Symfony\Component\DependencyInjection\Container; | ||
|
||
/** | ||
* Class LegacyLeadModel. | ||
* | ||
* @deprecated Used temporarily to get around circular depdenency for LeadModel | ||
*/ | ||
class LegacyLeadModel | ||
{ | ||
/** | ||
* @var Container | ||
*/ | ||
private $container; | ||
|
||
/** | ||
* LegacyContactMerger constructor. | ||
* | ||
* @param Container $container | ||
*/ | ||
public function __construct(Container $container) | ||
{ | ||
$this->container = $container; | ||
} | ||
|
||
/** | ||
* @param Lead $lead | ||
* @param Lead $lead2 | ||
* @param bool $autoMode | ||
* | ||
* @return Lead | ||
*/ | ||
public function mergeLeads(Lead $lead, Lead $lead2, $autoMode = true) | ||
{ | ||
$leadId = $lead->getId(); | ||
|
||
if ($autoMode) { | ||
//which lead is the oldest? | ||
$winner = ($lead->getDateAdded() < $lead2->getDateAdded()) ? $lead : $lead2; | ||
$loser = ($winner->getId() === $leadId) ? $lead2 : $lead; | ||
} else { | ||
$winner = $lead2; | ||
$loser = $lead; | ||
} | ||
|
||
try { | ||
/** @var ContactMerger $contactMerger */ | ||
$contactMerger = $this->container->get('mautic.lead.merger'); | ||
|
||
return $contactMerger->merge($winner, $loser); | ||
} catch (SameContactException $exception) { | ||
return $lead; | ||
} | ||
} | ||
} |