1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/** |
4
|
|
|
*/ |
5
|
|
|
namespace CommerceLeague\ActiveCampaign\Model; |
6
|
|
|
|
7
|
|
|
use CommerceLeague\ActiveCampaign\Api\ContactRepositoryInterface; |
8
|
|
|
use CommerceLeague\ActiveCampaign\Api\Data; |
9
|
|
|
use CommerceLeague\ActiveCampaign\Model\ResourceModel\Contact as ContactResource; |
10
|
|
|
use Magento\Customer\Model\Customer; |
11
|
|
|
use Magento\Framework\Exception\CouldNotDeleteException; |
12
|
|
|
use Magento\Framework\Exception\CouldNotSaveException; |
13
|
|
|
use Magento\Framework\Exception\NoSuchEntityException; |
14
|
|
|
use Magento\Framework\Model\AbstractModel; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class ContactRepository |
18
|
|
|
*/ |
19
|
|
|
class ContactRepository implements ContactRepositoryInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var ContactResource |
23
|
|
|
*/ |
24
|
|
|
private $contactResource; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var ContactFactory |
|
|
|
|
28
|
|
|
*/ |
29
|
|
|
private $contactFactory; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param ContactResource $contactResource |
33
|
|
|
* @param ContactFactory $contactFactory |
34
|
|
|
*/ |
35
|
|
|
public function __construct( |
36
|
|
|
ContactResource $contactResource, |
37
|
|
|
ContactFactory $contactFactory |
38
|
|
|
) { |
39
|
|
|
$this->contactResource = $contactResource; |
40
|
|
|
$this->contactFactory = $contactFactory; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param Data\ContactInterface|AbstractModel $contact |
45
|
|
|
* @return Data\ContactInterface |
46
|
|
|
* @throws CouldNotSaveException |
47
|
|
|
*/ |
48
|
|
|
public function save(Data\ContactInterface $contact): Data\ContactInterface |
49
|
|
|
{ |
50
|
|
|
try { |
51
|
|
|
$this->contactResource->save($contact); |
52
|
|
|
} catch (\Exception $e) { |
53
|
|
|
throw new CouldNotSaveException(__($e->getMessage())); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return $contact; |
|
|
|
|
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @inheritDoc |
61
|
|
|
*/ |
62
|
|
|
public function getById($contactId): Data\ContactInterface |
63
|
|
|
{ |
64
|
|
|
/** @var Contact $contact */ |
65
|
|
|
$contact = $this->contactFactory->create(); |
66
|
|
|
$this->contactResource->load($contact, $contactId); |
67
|
|
|
|
68
|
|
|
return $contact; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @inheritDoc |
73
|
|
|
*/ |
74
|
|
|
public function getByCustomerId($customerId): Data\ContactInterface |
75
|
|
|
{ |
76
|
|
|
/** @var Contact $contact */ |
77
|
|
|
$contact = $this->contactFactory->create(); |
78
|
|
|
$this->contactResource->load($contact, $customerId, Data\ContactInterface::CUSTOMER_ID); |
79
|
|
|
|
80
|
|
|
return $contact; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @inheritDoc |
85
|
|
|
*/ |
86
|
|
|
public function getOrCreateByCustomer(Customer $customer): Data\ContactInterface |
87
|
|
|
{ |
88
|
|
|
$contact = $this->getByCustomerId($customer->getId()); |
89
|
|
|
|
90
|
|
|
if (!$contact->getId()) { |
91
|
|
|
$contact->setCustomerId($customer->getId()); |
92
|
|
|
$this->save($contact); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
return $contact; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param Data\ContactInterface|AbstractModel $contact |
100
|
|
|
* @return bool |
101
|
|
|
* @throws CouldNotDeleteException |
102
|
|
|
*/ |
103
|
|
|
public function delete(Data\ContactInterface $contact): bool |
104
|
|
|
{ |
105
|
|
|
try { |
106
|
|
|
$this->contactResource->delete($contact); |
107
|
|
|
} catch (\Exception $e) { |
108
|
|
|
throw new CouldNotDeleteException(__($e->getMessage())); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
return true; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @inheritDoc |
116
|
|
|
*/ |
117
|
|
|
public function deleteById($contactId): bool |
118
|
|
|
{ |
119
|
|
|
$contact = $this->getById($contactId); |
120
|
|
|
|
121
|
|
|
if (!$contact->getId()) { |
122
|
|
|
throw new NoSuchEntityException( |
123
|
|
|
__('The Contact with the "%1" ID doesn\'t exist', $contactId) |
124
|
|
|
); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
return $this->delete($contact); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|
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