|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MailMarketing\Jobs; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Bus\Queueable; |
|
6
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue; |
|
7
|
|
|
use Illuminate\Foundation\Bus\Dispatchable; |
|
8
|
|
|
use Illuminate\Queue\InteractsWithQueue; |
|
9
|
|
|
use Illuminate\Queue\SerializesModels; |
|
10
|
|
|
use Illuminate\Support\Arr; |
|
11
|
|
|
use MailMarketing\Drivers\MailMarketingInterface; |
|
12
|
|
|
use MailMarketing\Entities\ResponseInterface; |
|
13
|
|
|
use MailMarketing\Facades\MailMarketing; |
|
14
|
|
|
|
|
15
|
|
|
class UpdateMemberInMailMarketingListJob implements ShouldQueue |
|
16
|
|
|
{ |
|
17
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; |
|
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
public ?string $listId = null; |
|
20
|
|
|
|
|
21
|
|
|
public \ArrayAccess|array $member = []; |
|
22
|
|
|
|
|
23
|
|
|
public bool $isAdd = true; |
|
24
|
|
|
|
|
25
|
|
|
public ?string $driver = null; |
|
26
|
|
|
|
|
27
|
|
|
public array $tags; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* AddMembersToMailMarketingList constructor. |
|
31
|
|
|
*/ |
|
32
|
5 |
|
public function __construct(?string $listId, \ArrayAccess|array $member, bool $isAdd = true, array $tags = []) |
|
33
|
|
|
{ |
|
34
|
5 |
|
$this->listId = $listId; |
|
35
|
5 |
|
$this->member = $member; |
|
36
|
5 |
|
$this->isAdd = $isAdd; |
|
37
|
5 |
|
$this->tags = $tags; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
|
|
41
|
3 |
|
public function handle(): ?ResponseInterface |
|
42
|
|
|
{ |
|
43
|
3 |
|
if (!app()->environment(config('mail-marketing.marketing_jobs.envs'))) { |
|
|
|
|
|
|
44
|
1 |
|
return null; |
|
45
|
|
|
} |
|
46
|
2 |
|
if ($this->isAdd) { |
|
47
|
1 |
|
return $this->addMemberToList(); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
1 |
|
return $this->removeMemberFromList(); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
2 |
|
public function setDriver(?string $driver): static |
|
54
|
|
|
{ |
|
55
|
2 |
|
$this->driver = $driver; |
|
56
|
|
|
|
|
57
|
2 |
|
return $this; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
1 |
|
protected function addMemberToList(): ResponseInterface |
|
61
|
|
|
{ |
|
62
|
1 |
|
$driver = $this->driver(); |
|
63
|
|
|
|
|
64
|
1 |
|
$response = $driver->addMemberToList( |
|
65
|
1 |
|
$this->listId, |
|
66
|
1 |
|
$this->member |
|
67
|
1 |
|
); |
|
68
|
|
|
|
|
69
|
1 |
|
if (count($this->tags)) { |
|
70
|
1 |
|
$driver->manageMemberTags( |
|
71
|
1 |
|
$this->listId, |
|
72
|
1 |
|
Arr::get($this->member, 'email'), |
|
73
|
1 |
|
$this->tags |
|
74
|
1 |
|
); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
1 |
|
return $response; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
1 |
|
protected function removeMemberFromList(): ResponseInterface |
|
81
|
|
|
{ |
|
82
|
1 |
|
return $this->driver()->removeMemberFromList( |
|
83
|
1 |
|
$this->listId, |
|
84
|
1 |
|
$this->member |
|
85
|
1 |
|
); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
3 |
|
public function driver(): MailMarketingInterface |
|
89
|
|
|
{ |
|
90
|
3 |
|
return MailMarketing::driver($this->driver); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|