1+ <?php namespace App \Jobs ;
2+ /*
3+ * Copyright 2023 OpenStack Foundation
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ * Unless required by applicable law or agreed to in writing, software
9+ * distributed under the License is distributed on an "AS IS" BASIS,
10+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+ * See the License for the specific language governing permissions and
12+ * limitations under the License.
13+ **/
14+
15+ use Illuminate \Bus \Queueable ;
16+ use Illuminate \Contracts \Queue \ShouldQueue ;
17+ use Illuminate \Foundation \Bus \Dispatchable ;
18+ use Illuminate \Queue \InteractsWithQueue ;
19+ use Illuminate \Queue \SerializesModels ;
20+ use Illuminate \Support \Facades \Log ;
21+ use models \exceptions \EntityNotFoundException ;
22+ use models \summit \ISummitAttendeeTicketRepository ;
23+ use models \summit \SummitAttendeeTicket ;
24+
25+ /**
26+ * Class SendAttendeeInvitationEmail
27+ * @package App\Jobs
28+ */
29+ final class SendAttendeeInvitationEmail implements ShouldQueue
30+ {
31+ use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
32+
33+ public $ tries = 3 ;
34+
35+ public $ ticket_id ;
36+
37+
38+ /**
39+ * @param int $ticket_id
40+ */
41+ public function __construct (int $ ticket_id )
42+ {
43+ Log::debug (sprintf ("SendAttendeeInvitationEmail::constructor ticket_id %s " , $ ticket_id ));
44+ $ this ->ticket_id = $ ticket_id ;
45+ }
46+
47+ public function handle
48+ (
49+ ISummitAttendeeTicketRepository $ ticketRepository
50+ )
51+ {
52+ Log::debug (sprintf ( "SendAttendeeInvitationEmail::handle ticket_id %s " , $ this ->ticket_id ));
53+
54+ try {
55+ $ ticket = $ ticketRepository ->getById ($ this ->ticket_id );
56+
57+ if (!$ ticket instanceof SummitAttendeeTicket) {
58+
59+ throw new EntityNotFoundException (sprintf ("Ticket %s not found. " , $ this ->ticket_id ));
60+ }
61+
62+ if (!$ ticket ->hasOwner ()) {
63+
64+ Log::warning
65+ (
66+ sprintf
67+ (
68+ "SendAttendeeInvitationEmail::handle ticket %s has no owner " ,
69+ $ this ->ticket_id
70+ )
71+ );
72+
73+ return ;
74+ }
75+
76+ $ attendee = $ ticket ->getOwner ();
77+
78+ $ attendee ->sendInvitationEmail ($ ticket );
79+ }
80+ catch (\Exception $ ex ){
81+ Log::error ($ ex );
82+ throw $ ex ;
83+ }
84+ }
85+
86+ public function failed (\Throwable $ exception )
87+ {
88+ Log::error ($ exception );
89+ }
90+
91+ }
0 commit comments