|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
/** |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace CommerceLeague\ActiveCampaign\Controller\Webhook\Contact; |
|
7
|
|
|
|
|
8
|
|
|
use CommerceLeague\ActiveCampaign\Controller\AbstractWebhook; |
|
9
|
|
|
use CommerceLeague\ActiveCampaign\Helper\Config as ConfigHelper; |
|
10
|
|
|
use CommerceLeague\ActiveCampaign\Logger\Logger; |
|
11
|
|
|
use Magento\Framework\App\Action\Context; |
|
12
|
|
|
use Magento\Framework\Controller\Result\RawFactory as RawResultFactory; |
|
|
|
|
|
|
13
|
|
|
use Magento\Framework\Exception\LocalizedException; |
|
14
|
|
|
use Magento\Newsletter\Model\SubscriberFactory; |
|
|
|
|
|
|
15
|
|
|
use Magento\Newsletter\Model\Subscriber; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Class Unsubscribe |
|
19
|
|
|
*/ |
|
20
|
|
|
class Unsubscribe extends AbstractWebhook |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @var SubscriberFactory |
|
24
|
|
|
*/ |
|
25
|
|
|
private $subscriberFactory; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var Logger |
|
29
|
|
|
*/ |
|
30
|
|
|
private $logger; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param Context $context |
|
34
|
|
|
* @param ConfigHelper $configHelper |
|
35
|
|
|
* @param RawResultFactory $rawResultFactory |
|
36
|
|
|
* @param SubscriberFactory $subscriberFactory |
|
37
|
|
|
* @param Logger $logger |
|
38
|
|
|
*/ |
|
39
|
|
|
public function __construct( |
|
40
|
|
|
Context $context, |
|
41
|
|
|
ConfigHelper $configHelper, |
|
42
|
|
|
RawResultFactory $rawResultFactory, |
|
43
|
|
|
SubscriberFactory $subscriberFactory, |
|
44
|
|
|
Logger $logger |
|
45
|
|
|
) { |
|
46
|
|
|
parent::__construct($context, $configHelper, $rawResultFactory); |
|
47
|
|
|
$this->subscriberFactory = $subscriberFactory; |
|
48
|
|
|
$this->logger = $logger; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @inheritDoc |
|
53
|
|
|
*/ |
|
54
|
|
|
public function execute() |
|
55
|
|
|
{ |
|
56
|
|
|
$params = $this->getRequest()->getParams(); |
|
57
|
|
|
|
|
58
|
|
|
if (!isset($params['contact']) || !(isset($params['contact']['email']))) { |
|
59
|
|
|
$this->logger->error(__('Invalid webhook params received')); |
|
60
|
|
|
return; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
$email = $params['contact']['email']; |
|
64
|
|
|
|
|
65
|
|
|
/** @var Subscriber $subscriber */ |
|
66
|
|
|
$subscriber = $this->subscriberFactory->create(); |
|
67
|
|
|
$subscriber->loadByEmail($email); |
|
68
|
|
|
|
|
69
|
|
|
if (!$subscriber->getId()) { |
|
70
|
|
|
$this->logger->error(__('Unable to find subscriber with email "%s"', $email)); |
|
71
|
|
|
return; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
try { |
|
75
|
|
|
$subscriber->unsubscribe(); |
|
76
|
|
|
} catch (LocalizedException $e) { |
|
77
|
|
|
$this->logger->error($e->getMessage()); |
|
78
|
|
|
return; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
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