1 | <?php |
||
2 | |||
3 | /* |
||
4 | * @copyright 2014 Mautic Contributors. All rights reserved |
||
5 | * @author Mautic |
||
6 | * |
||
7 | * @link http://mautic.org |
||
8 | * |
||
9 | * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html |
||
10 | */ |
||
11 | |||
12 | namespace Mautic\CampaignBundle\EventListener; |
||
13 | |||
14 | use Mautic\CampaignBundle\CampaignEvents; |
||
15 | use Mautic\CampaignBundle\Entity\Campaign; |
||
16 | use Mautic\CampaignBundle\Event as Events; |
||
17 | use Mautic\CampaignBundle\Service\Campaign as CampaignService; |
||
18 | use Mautic\CoreBundle\EventListener\CommonSubscriber; |
||
0 ignored issues
–
show
|
|||
19 | use Mautic\CoreBundle\Helper\IpLookupHelper; |
||
20 | use Mautic\CoreBundle\Model\AuditLogModel; |
||
21 | use Mautic\CoreBundle\Service\FlashBag; |
||
22 | use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
||
23 | |||
24 | class CampaignSubscriber implements EventSubscriberInterface |
||
25 | { |
||
26 | /** |
||
27 | * @var IpLookupHelper |
||
28 | */ |
||
29 | private $ipLookupHelper; |
||
30 | |||
31 | /** |
||
32 | * @var AuditLogModel |
||
33 | */ |
||
34 | private $auditLogModel; |
||
35 | |||
36 | /** |
||
37 | * @var CampaignService |
||
38 | */ |
||
39 | private $campaignService; |
||
40 | |||
41 | /** |
||
42 | * @var FlashBag |
||
43 | */ |
||
44 | private $flashBag; |
||
45 | |||
46 | public function __construct( |
||
47 | IpLookupHelper $ipLookupHelper, |
||
48 | AuditLogModel $auditLogModel, |
||
49 | CampaignService $campaignService, |
||
50 | FlashBag $flashBag |
||
51 | ) { |
||
52 | $this->ipLookupHelper = $ipLookupHelper; |
||
53 | $this->auditLogModel = $auditLogModel; |
||
54 | $this->campaignService = $campaignService; |
||
55 | $this->flashBag = $flashBag; |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * @return array |
||
60 | */ |
||
61 | public static function getSubscribedEvents() |
||
62 | { |
||
63 | return [ |
||
64 | CampaignEvents::CAMPAIGN_POST_SAVE => ['onCampaignPostSave', 0], |
||
65 | CampaignEvents::CAMPAIGN_POST_DELETE => ['onCampaignDelete', 0], |
||
66 | ]; |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * Add an entry to the audit log. |
||
71 | */ |
||
72 | public function onCampaignPostSave(Events\CampaignEvent $event) |
||
73 | { |
||
74 | $campaign = $event->getCampaign(); |
||
75 | $details = $event->getChanges(); |
||
76 | |||
77 | if ($campaign->isPublished() && $this->campaignService->hasUnpublishedEmail($campaign->getId())) { |
||
78 | $this->setUnpublishedMailFlashMessage($campaign); |
||
79 | } |
||
80 | |||
81 | //don't set leads |
||
82 | unset($details['leads']); |
||
83 | |||
84 | if (!empty($details)) { |
||
85 | $log = [ |
||
86 | 'bundle' => 'campaign', |
||
87 | 'object' => 'campaign', |
||
88 | 'objectId' => $campaign->getId(), |
||
89 | 'action' => ($event->isNew()) ? 'create' : 'update', |
||
90 | 'details' => $details, |
||
91 | 'ipAddress' => $this->ipLookupHelper->getIpAddressFromRequest(), |
||
92 | ]; |
||
93 | $this->auditLogModel->writeToLog($log); |
||
94 | } |
||
95 | } |
||
96 | |||
97 | /** |
||
98 | * Add a delete entry to the audit log. |
||
99 | */ |
||
100 | public function onCampaignDelete(Events\CampaignEvent $event) |
||
101 | { |
||
102 | $campaign = $event->getCampaign(); |
||
103 | $log = [ |
||
104 | 'bundle' => 'campaign', |
||
105 | 'object' => 'campaign', |
||
106 | 'objectId' => $campaign->deletedId, |
||
107 | 'action' => 'delete', |
||
108 | 'details' => ['name' => $campaign->getName()], |
||
109 | 'ipAddress' => $this->ipLookupHelper->getIpAddressFromRequest(), |
||
110 | ]; |
||
111 | $this->auditLogModel->writeToLog($log); |
||
112 | } |
||
113 | |||
114 | private function setUnpublishedMailFlashMessage(Campaign $campaign) |
||
115 | { |
||
116 | $this->flashBag->add( |
||
117 | 'mautic.core.notice.campaign.unpublished.email', |
||
118 | [ |
||
119 | '%name%' => $campaign->getName(), |
||
120 | ] |
||
121 | ); |
||
122 | } |
||
123 | } |
||
124 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths