From 64ff4d73c24e40e7495d2e5e66f9983028d33a2e Mon Sep 17 00:00:00 2001 From: Joseph Cohen Date: Sat, 15 Aug 2015 22:15:06 -0500 Subject: [PATCH] Rename incident events and fixes --- ...Event.php => IncidentWasReportedEvent.php} | 2 +- ...t.php => MaintenanceWasScheduledEvent.php} | 2 +- app/Events/SubscriberHasVerifiedEvent.php | 34 ++++++++++ .../SendIncidentEmailNotificationHandler.php | 2 +- ...endMaintenanceEmailNotificationHandler.php | 8 ++- ...SendSubscriberVerificationEmailHandler.php | 62 +++++++++++++++++++ .../Controllers/Api/IncidentController.php | 4 +- .../Controllers/Api/SubscriberController.php | 2 +- .../Dashboard/IncidentController.php | 4 +- .../Dashboard/ScheduleController.php | 4 +- .../Dashboard/SubscriberController.php | 6 +- app/Providers/EventServiceProvider.php | 4 +- tests/Api/SubscriberTest.php | 2 +- 13 files changed, 116 insertions(+), 20 deletions(-) rename app/Events/Incident/{IncidentHasReportedEvent.php => IncidentWasReportedEvent.php} (95%) rename app/Events/Incident/{MaintenanceHasScheduledEvent.php => MaintenanceWasScheduledEvent.php} (94%) create mode 100644 app/Events/SubscriberHasVerifiedEvent.php create mode 100644 app/Handlers/Events/SendSubscriberVerificationEmailHandler.php diff --git a/app/Events/Incident/IncidentHasReportedEvent.php b/app/Events/Incident/IncidentWasReportedEvent.php similarity index 95% rename from app/Events/Incident/IncidentHasReportedEvent.php rename to app/Events/Incident/IncidentWasReportedEvent.php index 81f13990..82e4fa6a 100644 --- a/app/Events/Incident/IncidentHasReportedEvent.php +++ b/app/Events/Incident/IncidentWasReportedEvent.php @@ -13,7 +13,7 @@ namespace CachetHQ\Cachet\Events; use CachetHQ\Cachet\Models\Incident; -class IncidentHasReportedEvent +class IncidentWasReportedEvent { /** * The incident that has been reported. diff --git a/app/Events/Incident/MaintenanceHasScheduledEvent.php b/app/Events/Incident/MaintenanceWasScheduledEvent.php similarity index 94% rename from app/Events/Incident/MaintenanceHasScheduledEvent.php rename to app/Events/Incident/MaintenanceWasScheduledEvent.php index 4aea3173..b7b7f079 100644 --- a/app/Events/Incident/MaintenanceHasScheduledEvent.php +++ b/app/Events/Incident/MaintenanceWasScheduledEvent.php @@ -13,7 +13,7 @@ namespace CachetHQ\Cachet\Events; use CachetHQ\Cachet\Models\Incident; -class MaintenanceHasScheduledEvent +class MaintenanceWasScheduledEvent { /** * The incident that has been reported. diff --git a/app/Events/SubscriberHasVerifiedEvent.php b/app/Events/SubscriberHasVerifiedEvent.php new file mode 100644 index 00000000..e095ddb9 --- /dev/null +++ b/app/Events/SubscriberHasVerifiedEvent.php @@ -0,0 +1,34 @@ +subscriber = $subscriber; + } +} diff --git a/app/Handlers/Events/Incident/SendIncidentEmailNotificationHandler.php b/app/Handlers/Events/Incident/SendIncidentEmailNotificationHandler.php index 9c44ee74..4914f0cc 100644 --- a/app/Handlers/Events/Incident/SendIncidentEmailNotificationHandler.php +++ b/app/Handlers/Events/Incident/SendIncidentEmailNotificationHandler.php @@ -63,7 +63,7 @@ class SendIncidentEmailNotificationHandler * * @return void */ - public function handle(IncidentHasReportedEvent $event) + public function handle(IncidentWasReportedEvent $event) { $incident = $this->presenter->decorate($event->incident); $component = $this->presenter->decorate($event->incident->component); diff --git a/app/Handlers/Events/Incident/SendMaintenanceEmailNotificationHandler.php b/app/Handlers/Events/Incident/SendMaintenanceEmailNotificationHandler.php index b1195c34..5b03d6f7 100644 --- a/app/Handlers/Events/Incident/SendMaintenanceEmailNotificationHandler.php +++ b/app/Handlers/Events/Incident/SendMaintenanceEmailNotificationHandler.php @@ -11,7 +11,7 @@ namespace CachetHQ\Cachet\Handlers\Events\Incident; -use CachetHQ\Cachet\Events\MaintenanceHasScheduledEvent; +use CachetHQ\Cachet\Events\MaintenanceWasScheduledEvent; use CachetHQ\Cachet\Models\Subscriber; use Illuminate\Contracts\Mail\MailQueue; use Illuminate\Mail\Message; @@ -59,11 +59,15 @@ class SendMaintenanceEmailNotificationHandler /** * 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(MaintenanceHasScheduledEvent $event) + public function handle(MaintenanceWasScheduledEvent $event) { $data = $this->presenter->decorate($event->incident); diff --git a/app/Handlers/Events/SendSubscriberVerificationEmailHandler.php b/app/Handlers/Events/SendSubscriberVerificationEmailHandler.php new file mode 100644 index 00000000..1de26a31 --- /dev/null +++ b/app/Handlers/Events/SendSubscriberVerificationEmailHandler.php @@ -0,0 +1,62 @@ +mailer = $mailer; + } + + /** + * Handle the event. + * + * @param \CachetHQ\Cachet\Events\CustomerHasSubscribedEvent $event + * + * @return void + */ + public function handle(SubscriberHasSubscribedEvent $event) + { + $mail = [ + 'email' => $event->subscriber->email, + 'subject' => 'Confirm your subscription.', + 'link' => route('subscribe.verify', ['code' => $event->subscriber->verify_code]), + 'app_url' => env('APP_URL'), + ]; + + $this->mailer->queue([ + 'html' => 'emails.subscribers.verify-html', + 'text' => 'emails.subscribers.verify-text', + ], $mail, function (Message $message) use ($mail) { + $message->to($mail['email'])->subject($mail['subject']); + }); + } +} diff --git a/app/Http/Controllers/Api/IncidentController.php b/app/Http/Controllers/Api/IncidentController.php index 16d5d3c9..97c95e69 100644 --- a/app/Http/Controllers/Api/IncidentController.php +++ b/app/Http/Controllers/Api/IncidentController.php @@ -11,7 +11,7 @@ namespace CachetHQ\Cachet\Http\Controllers\Api; -use CachetHQ\Cachet\Events\Incident\IncidentHasReportedEvent; +use CachetHQ\Cachet\Events\Incident\IncidentWasReportedEvent; use CachetHQ\Cachet\Models\Incident; use Exception; use GrahamCampbell\Binput\Facades\Binput; @@ -80,7 +80,7 @@ class IncidentController extends AbstractApiController } if (array_get($incidentData, 'notify') && subscribers_enabled()) { - event(new IncidentHasReportedEvent($incident)); + event(new IncidentWasReportedEvent($incident)); } return $this->item($incident); diff --git a/app/Http/Controllers/Api/SubscriberController.php b/app/Http/Controllers/Api/SubscriberController.php index eca4e985..0f5d75ab 100644 --- a/app/Http/Controllers/Api/SubscriberController.php +++ b/app/Http/Controllers/Api/SubscriberController.php @@ -46,7 +46,7 @@ class SubscriberController extends AbstractApiController public function postSubscribers() { try { - $subscriber = $this->dispatch(new SubscribeSubscriberCommand(Binput::get('email'), Binput::get('verified', false))); + $subscriber = $this->dispatch(new SubscribeSubscriberCommand(Binput::get('email'), Binput::get('verify', false))); } catch (Exception $e) { throw new BadRequestHttpException(); } diff --git a/app/Http/Controllers/Dashboard/IncidentController.php b/app/Http/Controllers/Dashboard/IncidentController.php index e89f69c7..51024510 100644 --- a/app/Http/Controllers/Dashboard/IncidentController.php +++ b/app/Http/Controllers/Dashboard/IncidentController.php @@ -12,7 +12,7 @@ namespace CachetHQ\Cachet\Http\Controllers\Dashboard; use AltThree\Validator\ValidationException; -use CachetHQ\Cachet\Events\Incident\IncidentHasReportedEvent; +use CachetHQ\Cachet\Events\Incident\IncidentWasReportedEvent; use CachetHQ\Cachet\Facades\Setting; use CachetHQ\Cachet\Models\Component; use CachetHQ\Cachet\Models\ComponentGroup; @@ -133,7 +133,7 @@ class IncidentController extends Controller } if (array_get($incidentData, 'notify') && subscribers_enabled()) { - event(new IncidentHasReportedEvent($incident)); + event(new IncidentWasReportedEvent($incident)); } return Redirect::route('dashboard.incidents.add') diff --git a/app/Http/Controllers/Dashboard/ScheduleController.php b/app/Http/Controllers/Dashboard/ScheduleController.php index 9cdc8e9c..caafec10 100644 --- a/app/Http/Controllers/Dashboard/ScheduleController.php +++ b/app/Http/Controllers/Dashboard/ScheduleController.php @@ -12,7 +12,7 @@ namespace CachetHQ\Cachet\Http\Controllers\Dashboard; use AltThree\Validator\ValidationException; -use CachetHQ\Cachet\Events\MaintenanceHasScheduledEvent; +use CachetHQ\Cachet\Events\MaintenanceWasScheduledEvent; use CachetHQ\Cachet\Facades\Setting; use CachetHQ\Cachet\Models\Incident; use CachetHQ\Cachet\Models\IncidentTemplate; @@ -118,7 +118,7 @@ class ScheduleController extends Controller } if (array_get($scheduleData, 'notify') && subscribers_enabled()) { - event(new MaintenanceHasScheduledEvent($incident)); + event(new MaintenanceWasScheduledEvent($incident)); } return Redirect::route('dashboard.schedule.add') diff --git a/app/Http/Controllers/Dashboard/SubscriberController.php b/app/Http/Controllers/Dashboard/SubscriberController.php index 50a8bb15..22798a41 100644 --- a/app/Http/Controllers/Dashboard/SubscriberController.php +++ b/app/Http/Controllers/Dashboard/SubscriberController.php @@ -57,10 +57,8 @@ class SubscriberController extends Controller */ public function createSubscriberAction() { - $email = Binput::get('email'); - try { - $this->dispatch(new SubscribeSubscriberCommand($email)); + $this->dispatch(new SubscribeSubscriberCommand(Binput::get('email'))); } catch (ValidationException $e) { return Redirect::route('dashboard.subscribers.add') ->withInput(Binput::all()) @@ -68,8 +66,6 @@ class SubscriberController extends Controller ->withErrors($e->getMessageBag()); } - event(new CustomerHasSubscribedEvent($subscriber)); - return Redirect::route('dashboard.subscribers.add') ->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.subscribers.add.success'))); } diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index aef6d1e6..7646ad66 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -24,10 +24,10 @@ class EventServiceProvider extends ServiceProvider 'CachetHQ\Cachet\Events\Subscriber\SubscriberHasSubscribedEvent' => [ 'CachetHQ\Cachet\Handlers\Events\SendSubscriberVerificationEmailHandler', ], - 'CachetHQ\Cachet\Events\Incident\IncidentHasReportedEvent' => [ + 'CachetHQ\Cachet\Events\Incident\IncidentWasReportedEvent' => [ 'CachetHQ\Cachet\Handlers\Events\Incident\SendIncidentEmailNotificationHandler', ], - 'CachetHQ\Cachet\Events\Incident\MaintenanceHasScheduledEvent' => [ + 'CachetHQ\Cachet\Events\Incident\MaintenanceWasScheduledEvent' => [ 'CachetHQ\Cachet\Handlers\Events\Incident\SendMaintenanceEmailNotificationHandler', ], ]; diff --git a/tests/Api/SubscriberTest.php b/tests/Api/SubscriberTest.php index d5ebc04e..403430f1 100644 --- a/tests/Api/SubscriberTest.php +++ b/tests/Api/SubscriberTest.php @@ -40,7 +40,7 @@ class SubscriberTest extends AbstractTestCase { $this->beUser(); - $this->expectsEvents('CachetHQ\Cachet\Events\SubscriberHasSubscribedEvent'); + $this->expectsEvents('CachetHQ\Cachet\Events\Subscriber\SubscriberHasSubscribedEvent'); $this->post('/api/v1/subscribers', [ 'email' => 'james@cachethq.io',