|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Spatie\EmailCampaigns\Jobs; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Bus\Queueable; |
|
6
|
|
|
use Illuminate\Queue\InteractsWithQueue; |
|
7
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue; |
|
8
|
|
|
use Illuminate\Foundation\Bus\Dispatchable; |
|
9
|
|
|
use Spatie\EmailCampaigns\Models\CampaignSend; |
|
10
|
|
|
use Spatie\EmailCampaigns\Models\Subscriber; |
|
11
|
|
|
use Spatie\EmailCampaigns\Models\CampaignLink; |
|
12
|
|
|
use Spatie\EmailCampaigns\Events\CampaignLinkClicked; |
|
13
|
|
|
|
|
14
|
|
|
class RegisterClickJob implements ShouldQueue |
|
15
|
|
|
{ |
|
16
|
|
|
use Dispatchable, InteractsWithQueue, Queueable; |
|
17
|
|
|
|
|
18
|
|
|
/** @var string */ |
|
19
|
|
|
public $campaignLinkUuid; |
|
20
|
|
|
|
|
21
|
|
|
/** @var string */ |
|
22
|
|
|
public $campaignSendUuid; |
|
23
|
|
|
|
|
24
|
|
|
/** @var string */ |
|
25
|
|
|
public $queue; |
|
26
|
|
|
|
|
27
|
|
|
public function __construct(string $campaignLinkUuid, string $campaignSendUuid) |
|
28
|
|
|
{ |
|
29
|
|
|
$this->campaignLinkUuid = $campaignLinkUuid; |
|
30
|
|
|
|
|
31
|
|
|
$this->campaignSendUuid = $campaignSendUuid; |
|
32
|
|
|
|
|
33
|
|
|
$this->queue = config('email-campaigns.perform_on_queue.register_click_job'); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function handle() |
|
37
|
|
|
{ |
|
38
|
|
|
/** @var \Spatie\EmailCampaigns\Models\CampaignLink|null $campaignLink */ |
|
39
|
|
|
if (! $campaignLink = CampaignLink::findByUuid($this->campaignLinkUuid)) { |
|
40
|
|
|
return; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** @var \Spatie\EmailCampaigns\Models\CampaignSend|null $campaignSend */ |
|
44
|
|
|
if (! $campaignSend = CampaignSend::findByUuid($this->campaignSendUuid)) { |
|
45
|
|
|
return; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
$campaignClick = $campaignLink->clicks()->create([ |
|
49
|
|
|
'campaign_send_id' => $campaignSend->id, |
|
50
|
|
|
'email_list_subscriber_id' => $campaignSend->subscription->subscriber->id, |
|
51
|
|
|
]); |
|
52
|
|
|
|
|
53
|
|
|
event(new CampaignLinkClicked($campaignClick)); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|