1 | <?php |
||
2 | |||
3 | /* |
||
4 | * @copyright 2017 Mautic Contributors. All rights reserved |
||
5 | * @author Mautic, Inc. |
||
6 | * |
||
7 | * @link https://mautic.org |
||
8 | * |
||
9 | * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html |
||
10 | */ |
||
11 | |||
12 | namespace Mautic\CampaignBundle\Executioner\ContactFinder; |
||
13 | |||
14 | use Doctrine\Common\Collections\ArrayCollection; |
||
15 | use Mautic\CampaignBundle\Entity\Event; |
||
16 | use Mautic\CampaignBundle\Entity\LeadRepository as CampaignLeadRepository; |
||
17 | use Mautic\CampaignBundle\Executioner\ContactFinder\Limiter\ContactLimiter; |
||
18 | use Mautic\CampaignBundle\Executioner\Exception\NoContactsFoundException; |
||
19 | use Mautic\LeadBundle\Entity\LeadRepository; |
||
20 | use Psr\Log\LoggerInterface; |
||
21 | |||
22 | class InactiveContactFinder |
||
23 | { |
||
24 | /** |
||
25 | * @var LeadRepository |
||
26 | */ |
||
27 | private $leadRepository; |
||
28 | |||
29 | /** |
||
30 | * @var CampaignLeadRepository |
||
31 | */ |
||
32 | private $campaignLeadRepository; |
||
33 | |||
34 | /** |
||
35 | * @var LoggerInterface |
||
36 | */ |
||
37 | private $logger; |
||
38 | |||
39 | /** |
||
40 | * @var ArrayCollection |
||
41 | */ |
||
42 | private $campaignMemberDatesAdded; |
||
43 | |||
44 | public function __construct( |
||
45 | LeadRepository $leadRepository, |
||
46 | CampaignLeadRepository $campaignLeadRepository, |
||
47 | LoggerInterface $logger |
||
48 | ) { |
||
49 | $this->leadRepository = $leadRepository; |
||
50 | $this->campaignLeadRepository = $campaignLeadRepository; |
||
51 | $this->logger = $logger; |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * @param int $campaignId |
||
56 | * |
||
57 | * @return ArrayCollection |
||
58 | * |
||
59 | * @throws NoContactsFoundException |
||
60 | */ |
||
61 | public function getContacts($campaignId, Event $decisionEvent, ContactLimiter $limiter) |
||
62 | { |
||
63 | if ($limiter->hasCampaignLimit() && 0 === $limiter->getCampaignLimitRemaining()) { |
||
64 | // Limit was reached but do not trigger the NoContactsFoundException |
||
65 | return new ArrayCollection(); |
||
66 | } |
||
67 | |||
68 | // Get list of all campaign leads |
||
69 | $decisionParentEvent = $decisionEvent->getParent(); |
||
70 | $this->campaignMemberDatesAdded = $this->campaignLeadRepository->getInactiveContacts( |
||
0 ignored issues
–
show
|
|||
71 | $campaignId, |
||
72 | $decisionEvent->getId(), |
||
73 | ($decisionParentEvent) ? $decisionParentEvent->getId() : null, |
||
74 | $limiter |
||
75 | ); |
||
76 | |||
77 | if (empty($this->campaignMemberDatesAdded)) { |
||
78 | // No new contacts found in the campaign |
||
79 | throw new NoContactsFoundException(); |
||
80 | } |
||
81 | |||
82 | $campaignContacts = array_keys($this->campaignMemberDatesAdded); |
||
83 | $this->logger->debug('CAMPAIGN: Processing the following contacts: '.implode(', ', $campaignContacts)); |
||
84 | |||
85 | // Fetch entity objects for the found contacts |
||
86 | $contacts = $this->leadRepository->getContactCollection($campaignContacts); |
||
87 | |||
88 | if (!count($contacts)) { |
||
89 | // Just a precaution in case non-existent contacts are lingering in the campaign leads table |
||
90 | $this->logger->debug('CAMPAIGN: No contact entities found.'); |
||
91 | |||
92 | throw new NoContactsFoundException(); |
||
93 | } |
||
94 | |||
95 | return $contacts; |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * @return ArrayCollection |
||
100 | */ |
||
101 | public function getDatesAdded() |
||
102 | { |
||
103 | return $this->campaignMemberDatesAdded; |
||
104 | } |
||
105 | |||
106 | /** |
||
107 | * @param int $campaignId |
||
108 | * |
||
109 | * @return int |
||
110 | */ |
||
111 | public function getContactCount($campaignId, array $decisionEvents, ContactLimiter $limiter) |
||
112 | { |
||
113 | return $this->campaignLeadRepository->getInactiveContactCount($campaignId, $decisionEvents, $limiter); |
||
114 | } |
||
115 | |||
116 | /** |
||
117 | * Clear Lead entities from memory. |
||
118 | */ |
||
119 | public function clear() |
||
120 | { |
||
121 | $this->leadRepository->clear(); |
||
122 | } |
||
123 | } |
||
124 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..