1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Gitamin. |
5
|
|
|
* |
6
|
|
|
* Copyright (C) 2015-2016 The Gitamin Team |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Gitamin\Handlers\Events\Issue; |
13
|
|
|
|
14
|
|
|
use Gitamin\Events\Issue\IssueWasAddedEvent; |
15
|
|
|
use Gitamin\Models\Subscriber; |
16
|
|
|
use Illuminate\Contracts\Mail\MailQueue; |
17
|
|
|
use Illuminate\Mail\Message; |
18
|
|
|
use McCool\LaravelAutoPresenter\Facades\AutoPresenter; |
19
|
|
|
|
20
|
|
|
class SendIssueEmailNotificationHandler |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* The mailer instance. |
24
|
|
|
* |
25
|
|
|
* @var \Illuminate\Contracts\Mail\Mailer |
26
|
|
|
*/ |
27
|
|
|
protected $mailer; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* The subscriber instance. |
31
|
|
|
* |
32
|
|
|
* @var \Gitamin\Models\Subscriber |
33
|
|
|
*/ |
34
|
|
|
protected $subscriber; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Create a new send issue email notification handler. |
38
|
|
|
* |
39
|
|
|
* @param \Illuminate\Contracts\Mail\Mailer $mailer |
40
|
|
|
* @param \Gitamin\Models\Subscriber $subscriber |
41
|
|
|
*/ |
42
|
|
|
public function __construct(MailQueue $mailer, Subscriber $subscriber) |
43
|
|
|
{ |
44
|
|
|
$this->mailer = $mailer; |
|
|
|
|
45
|
|
|
$this->subscriber = $subscriber; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Handle the event. |
50
|
|
|
* |
51
|
|
|
* @param \Gitamin\Events\Issue\IssueHasAddedEvent $event |
52
|
|
|
*/ |
53
|
|
|
public function handle(IssueWasAddedEvent $event) |
54
|
|
|
{ |
55
|
|
|
if (! $event->issue->notify) { |
|
|
|
|
56
|
|
|
//return false; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$issue = AutoPresenter::decorate($event->issue); |
60
|
|
|
$project = AutoPresenter::decorate($event->issue->project); |
|
|
|
|
61
|
|
|
|
62
|
|
|
// Only send emails for public issues. |
63
|
|
|
if (1 === 1) { |
64
|
|
|
foreach ($this->subscriber->all() as $subscriber) { |
65
|
|
|
$mail = [ |
66
|
|
|
'email' => $subscriber->email, |
67
|
|
|
'subject' => 'New issue reported.', |
68
|
|
|
'has_project' => ($event->issue->project) ? true : false, |
|
|
|
|
69
|
|
|
'project_name' => $project ? $project->name : null, |
70
|
|
|
'status' => $issue->humanStatus, |
71
|
|
|
'html_content' => $issue->formattedMessage, |
72
|
|
|
'text_content' => $issue->message, |
73
|
|
|
'token' => $subscriber->token, |
74
|
|
|
'unsubscribe_link' => route('subscribe.unsubscribe', ['code' => $subscriber->verify_code]), |
75
|
|
|
]; |
76
|
|
|
error_log(var_export($mail, true), 3, '/tmp/mail.log'); |
77
|
|
|
$this->mailer->queue([ |
78
|
|
|
'html' => 'emails.issues.new-html', |
79
|
|
|
'text' => 'emails.issues.new-text', |
80
|
|
|
], $mail, function (Message $message) use ($mail) { |
81
|
|
|
$message->to($mail['email'])->subject($mail['subject']); |
82
|
|
|
}); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..