Files
cachet-docker/app/Handlers/Events/Incident/SendMaintenanceEmailNotificationHandler.php
2015-08-31 20:16:36 +01:00

96 lines
2.9 KiB
PHP

<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Handlers\Events\Incident;
use CachetHQ\Cachet\Events\MaintenanceWasScheduledEvent;
use CachetHQ\Cachet\Models\Subscriber;
use Illuminate\Contracts\Mail\MailQueue;
use Illuminate\Mail\Message;
use McCool\LaravelAutoPresenter\PresenterDecorator;
class SendMaintenanceEmailNotificationHandler
{
/**
* The mailer instance.
*
* @var \Illuminate\Contracts\Mail\MailQueue
*/
protected $mailer;
/**
* The subscriber instance.
*
* @var \CachetHQ\Cachet\Models\Subscriber
*/
protected $subscriber;
/**
* The presenter instance.
*
* @var \McCool\LaravelAutoPresenter\PresenterDecorator
*/
protected $presenter;
/**
* Create a new send maintenance email notification handler.
*
* @param \Illuminate\Contracts\Mail\Mailer $mailer
* @param \CachetHQ\Cachet\Models\Subscriber $subscriber
* @param \McCool\LaravelAutoPresenter\PresenterDecorator $presenter
*
* @return void
*/
public function __construct(MailQueue $mailer, Subscriber $subscriber, PresenterDecorator $presenter)
{
$this->mailer = $mailer;
$this->subscriber = $subscriber;
$this->presenter = $presenter;
}
/**
* Handle the event.
*
<<<<<<< cc10f8f42347c5fdfe7e464bedd3a388059ebc4b
* @param \CachetHQ\Cachet\Events\MaintenanceHasScheduledEvent $event
*
* @return void
=======
* @param \CachetHQ\Cachet\Events\MaintenanceWasScheduledEvent $event
>>>>>>> Rename incident events and fixes
*/
public function handle(MaintenanceWasScheduledEvent $event)
{
$data = $this->presenter->decorate($event->incident);
foreach ($this->subscriber->all() as $subscriber) {
$mail = [
'email' => $subscriber->email,
'subject' => 'Scheduled maintenance.',
'status' => $data->humanStatus,
'html_content' => $data->formattedMessage,
'text_content' => $data->message,
'scheduled_at' => $data->scheduled_at_formatted,
'token' => $subscriber->token,
'unsubscribe_link' => route('subscribe.unsubscribe', ['code' => $subscriber->verify_code]),
'app_url' => env('APP_URL'),
];
$this->mailer->queue([
'html' => 'emails.incidents.maintenance-html',
'text' => 'emails.incidents.maintenance-text',
], $mail, function (Message $message) use ($mail) {
$message->to($mail['email'])->subject($mail['subject']);
});
}
}
}