From 8bb8ee3dc781159db093664f91c57eb2a146dd02 Mon Sep 17 00:00:00 2001 From: James Brooks Date: Mon, 25 Jun 2018 22:25:54 +0100 Subject: [PATCH] Fix command dispatching --- .../Incident/CreateIncidentCommandHandler.php | 2 +- .../Incident/UpdateIncidentCommandHandler.php | 2 +- .../CreateIncidentUpdateCommandHandler.php | 2 +- .../SubscribeSubscriberCommandHandler.php | 2 +- app/Console/Commands/BeaconCommand.php | 2 +- app/Foundation/Exceptions/Filters/ApiFilter.php | 2 +- app/Http/Controllers/Api/ComponentController.php | 14 +++++++------- .../Controllers/Api/ComponentGroupController.php | 6 +++--- app/Http/Controllers/Api/IncidentController.php | 6 +++--- .../Controllers/Api/IncidentUpdateController.php | 6 +++--- app/Http/Controllers/Api/MetricController.php | 6 +++--- .../Controllers/Api/MetricPointController.php | 6 +++--- app/Http/Controllers/Api/ScheduleController.php | 6 +++--- app/Http/Controllers/Api/SubscriberController.php | 4 ++-- .../Controllers/Api/SubscriptionController.php | 2 +- app/Http/Controllers/Dashboard/ApiController.php | 6 +++--- .../Controllers/Dashboard/ComponentController.php | 14 +++++++------- .../Dashboard/ComponentGroupController.php | 6 +++--- .../Controllers/Dashboard/DashboardController.php | 2 +- .../Controllers/Dashboard/IncidentController.php | 6 +++--- .../Dashboard/IncidentUpdateController.php | 4 ++-- .../Controllers/Dashboard/MetricController.php | 6 +++--- .../Controllers/Dashboard/ScheduleController.php | 6 +++--- .../Controllers/Dashboard/SettingsController.php | 2 +- .../Dashboard/SubscriberController.php | 4 ++-- app/Http/Controllers/Dashboard/TeamController.php | 6 +++--- app/Http/Controllers/SetupController.php | 2 +- app/Http/Controllers/SignupController.php | 4 ++-- app/Http/Controllers/SubscribeController.php | 10 +++++----- app/helpers.php | 15 +++++++++++++++ 30 files changed, 88 insertions(+), 73 deletions(-) diff --git a/app/Bus/Handlers/Commands/Incident/CreateIncidentCommandHandler.php b/app/Bus/Handlers/Commands/Incident/CreateIncidentCommandHandler.php index 0e14a298..fae44d84 100644 --- a/app/Bus/Handlers/Commands/Incident/CreateIncidentCommandHandler.php +++ b/app/Bus/Handlers/Commands/Incident/CreateIncidentCommandHandler.php @@ -116,7 +116,7 @@ class CreateIncidentCommandHandler // Update the component. if ($component = Component::find($command->component_id)) { - dispatch(new UpdateComponentCommand( + execute(new UpdateComponentCommand( Component::find($command->component_id), null, null, diff --git a/app/Bus/Handlers/Commands/Incident/UpdateIncidentCommandHandler.php b/app/Bus/Handlers/Commands/Incident/UpdateIncidentCommandHandler.php index 00bf9f8d..7b6af453 100644 --- a/app/Bus/Handlers/Commands/Incident/UpdateIncidentCommandHandler.php +++ b/app/Bus/Handlers/Commands/Incident/UpdateIncidentCommandHandler.php @@ -88,7 +88,7 @@ class UpdateIncidentCommandHandler // Update the component. if ($component = Component::find($command->component_id)) { - dispatch(new UpdateComponentCommand( + execute(new UpdateComponentCommand( Component::find($command->component_id), null, null, diff --git a/app/Bus/Handlers/Commands/IncidentUpdate/CreateIncidentUpdateCommandHandler.php b/app/Bus/Handlers/Commands/IncidentUpdate/CreateIncidentUpdateCommandHandler.php index 09fe9d9b..20dd2c84 100644 --- a/app/Bus/Handlers/Commands/IncidentUpdate/CreateIncidentUpdateCommandHandler.php +++ b/app/Bus/Handlers/Commands/IncidentUpdate/CreateIncidentUpdateCommandHandler.php @@ -63,7 +63,7 @@ class CreateIncidentUpdateCommandHandler $update = IncidentUpdate::create($data); // Update the original incident with the new status. - dispatch(new UpdateIncidentCommand( + execute(new UpdateIncidentCommand( $command->incident, null, $command->status, diff --git a/app/Bus/Handlers/Commands/Subscriber/SubscribeSubscriberCommandHandler.php b/app/Bus/Handlers/Commands/Subscriber/SubscribeSubscriberCommandHandler.php index 6a9839c7..1dde43da 100644 --- a/app/Bus/Handlers/Commands/Subscriber/SubscribeSubscriberCommandHandler.php +++ b/app/Bus/Handlers/Commands/Subscriber/SubscribeSubscriberCommandHandler.php @@ -58,7 +58,7 @@ class SubscribeSubscriberCommandHandler }); if ($command->verified) { - dispatch(new VerifySubscriberCommand($subscriber)); + execute(new VerifySubscriberCommand($subscriber)); } else { $subscriber->notify(new VerifySubscriptionNotification()); } diff --git a/app/Console/Commands/BeaconCommand.php b/app/Console/Commands/BeaconCommand.php index 5045f642..c3a446a0 100644 --- a/app/Console/Commands/BeaconCommand.php +++ b/app/Console/Commands/BeaconCommand.php @@ -42,6 +42,6 @@ class BeaconCommand extends Command */ public function fire() { - dispatch(new SendBeaconJob()); + execute(new SendBeaconJob()); } } diff --git a/app/Foundation/Exceptions/Filters/ApiFilter.php b/app/Foundation/Exceptions/Filters/ApiFilter.php index e824de2a..a8a8105d 100644 --- a/app/Foundation/Exceptions/Filters/ApiFilter.php +++ b/app/Foundation/Exceptions/Filters/ApiFilter.php @@ -27,7 +27,7 @@ class ApiFilter * * @return \GrahamCampbell\Exceptions\Displayers\DisplayerInterface[] */ - public function filter(array $displayers, Request $request, Exception $original, Exception $transformed, $code) + public function filter(array $displayers, Request $request, Exception $original, Exception $transformed, int $code) { if ($request->is('api*')) { foreach ($displayers as $index => $displayer) { diff --git a/app/Http/Controllers/Api/ComponentController.php b/app/Http/Controllers/Api/ComponentController.php index 9b37cba5..7d1b800e 100644 --- a/app/Http/Controllers/Api/ComponentController.php +++ b/app/Http/Controllers/Api/ComponentController.php @@ -76,7 +76,7 @@ class ComponentController extends AbstractApiController public function store() { try { - $component = dispatch(new CreateComponentCommand( + $component = execute(new CreateComponentCommand( Binput::get('name'), Binput::get('description'), Binput::get('status'), @@ -97,9 +97,9 @@ class ComponentController extends AbstractApiController Collection::make(preg_split('/ ?, ?/', $tags))->map(function ($tag) { return trim($tag); })->map(function ($tag) { - return dispatch(new CreateTagCommand($tag)); + return execute(new CreateTagCommand($tag)); })->each(function ($tag) use ($component) { - dispatch(new ApplyTagCommand($component, $tag)); + execute(new ApplyTagCommand($component, $tag)); }); } @@ -116,7 +116,7 @@ class ComponentController extends AbstractApiController public function update(Component $component) { try { - dispatch(new UpdateComponentCommand( + execute(new UpdateComponentCommand( $component, Binput::get('name'), Binput::get('description'), @@ -139,9 +139,9 @@ class ComponentController extends AbstractApiController Collection::make(preg_split('/ ?, ?/', $tags))->map(function ($tag) { return trim($tag); })->map(function ($tag) { - return dispatch(new CreateTagCommand($tag)); + return execute(new CreateTagCommand($tag)); })->each(function ($tag) use ($component) { - dispatch(new ApplyTagCommand($component, $tag)); + execute(new ApplyTagCommand($component, $tag)); }); } @@ -157,7 +157,7 @@ class ComponentController extends AbstractApiController */ public function destroy(Component $component) { - dispatch(new RemoveComponentCommand($component)); + execute(new RemoveComponentCommand($component)); return $this->noContent(); } diff --git a/app/Http/Controllers/Api/ComponentGroupController.php b/app/Http/Controllers/Api/ComponentGroupController.php index 7e7c65a7..957106e1 100644 --- a/app/Http/Controllers/Api/ComponentGroupController.php +++ b/app/Http/Controllers/Api/ComponentGroupController.php @@ -92,7 +92,7 @@ class ComponentGroupController extends AbstractApiController public function store() { try { - $group = dispatch(new CreateComponentGroupCommand( + $group = execute(new CreateComponentGroupCommand( Binput::get('name'), Binput::get('order', 0), Binput::get('collapsed', 0), @@ -115,7 +115,7 @@ class ComponentGroupController extends AbstractApiController public function update(ComponentGroup $group) { try { - $group = dispatch(new UpdateComponentGroupCommand( + $group = execute(new UpdateComponentGroupCommand( $group, Binput::get('name'), Binput::get('order'), @@ -138,7 +138,7 @@ class ComponentGroupController extends AbstractApiController */ public function destroy(ComponentGroup $group) { - dispatch(new RemoveComponentGroupCommand($group)); + execute(new RemoveComponentGroupCommand($group)); return $this->noContent(); } diff --git a/app/Http/Controllers/Api/IncidentController.php b/app/Http/Controllers/Api/IncidentController.php index 718be542..b301202c 100644 --- a/app/Http/Controllers/Api/IncidentController.php +++ b/app/Http/Controllers/Api/IncidentController.php @@ -67,7 +67,7 @@ class IncidentController extends AbstractApiController public function store() { try { - $incident = dispatch(new CreateIncidentCommand( + $incident = execute(new CreateIncidentCommand( Binput::get('name'), Binput::get('status'), Binput::get('message', null, false, false), @@ -98,7 +98,7 @@ class IncidentController extends AbstractApiController public function update(Incident $incident) { try { - $incident = dispatch(new UpdateIncidentCommand( + $incident = execute(new UpdateIncidentCommand( $incident, Binput::get('name'), Binput::get('status'), @@ -128,7 +128,7 @@ class IncidentController extends AbstractApiController */ public function destroy(Incident $incident) { - dispatch(new RemoveIncidentCommand($incident)); + execute(new RemoveIncidentCommand($incident)); return $this->noContent(); } diff --git a/app/Http/Controllers/Api/IncidentUpdateController.php b/app/Http/Controllers/Api/IncidentUpdateController.php index 2b9ec3c4..0c239a6a 100644 --- a/app/Http/Controllers/Api/IncidentUpdateController.php +++ b/app/Http/Controllers/Api/IncidentUpdateController.php @@ -74,7 +74,7 @@ class IncidentUpdateController extends AbstractApiController public function store(Incident $incident) { try { - $update = dispatch(new CreateIncidentUpdateCommand( + $update = execute(new CreateIncidentUpdateCommand( $incident, Binput::get('status'), Binput::get('message'), @@ -100,7 +100,7 @@ class IncidentUpdateController extends AbstractApiController public function update(Incident $incident, IncidentUpdate $update) { try { - $update = dispatch(new UpdateIncidentUpdateCommand( + $update = execute(new UpdateIncidentUpdateCommand( $update, Binput::get('status'), Binput::get('message'), @@ -124,7 +124,7 @@ class IncidentUpdateController extends AbstractApiController public function destroy(Incident $incident, IncidentUpdate $update) { try { - dispatch(new RemoveIncidentUpdateCommand($update)); + execute(new RemoveIncidentUpdateCommand($update)); } catch (QueryException $e) { throw new BadRequestHttpException(); } diff --git a/app/Http/Controllers/Api/MetricController.php b/app/Http/Controllers/Api/MetricController.php index fd7dbe07..4ef2e1e4 100644 --- a/app/Http/Controllers/Api/MetricController.php +++ b/app/Http/Controllers/Api/MetricController.php @@ -62,7 +62,7 @@ class MetricController extends AbstractApiController public function store() { try { - $metric = dispatch(new CreateMetricCommand( + $metric = execute(new CreateMetricCommand( Binput::get('name'), Binput::get('suffix'), Binput::get('description'), @@ -92,7 +92,7 @@ class MetricController extends AbstractApiController public function update(Metric $metric) { try { - $metric = dispatch(new UpdateMetricCommand( + $metric = execute(new UpdateMetricCommand( $metric, Binput::get('name'), Binput::get('suffix'), @@ -122,7 +122,7 @@ class MetricController extends AbstractApiController */ public function destroy(Metric $metric) { - dispatch(new RemoveMetricCommand($metric)); + execute(new RemoveMetricCommand($metric)); return $this->noContent(); } diff --git a/app/Http/Controllers/Api/MetricPointController.php b/app/Http/Controllers/Api/MetricPointController.php index bc551052..8afb5c59 100644 --- a/app/Http/Controllers/Api/MetricPointController.php +++ b/app/Http/Controllers/Api/MetricPointController.php @@ -48,7 +48,7 @@ class MetricPointController extends AbstractApiController public function store(Metric $metric) { try { - $metricPoint = dispatch(new CreateMetricPointCommand( + $metricPoint = execute(new CreateMetricPointCommand( $metric, Binput::get('value'), Binput::get('timestamp') @@ -70,7 +70,7 @@ class MetricPointController extends AbstractApiController */ public function update(Metric $metric, MetricPoint $metricPoint) { - $metricPoint = dispatch(new UpdateMetricPointCommand( + $metricPoint = execute(new UpdateMetricPointCommand( $metricPoint, $metric, Binput::get('value'), @@ -90,7 +90,7 @@ class MetricPointController extends AbstractApiController */ public function destroy(Metric $metric, MetricPoint $metricPoint) { - dispatch(new RemoveMetricPointCommand($metricPoint)); + execute(new RemoveMetricPointCommand($metricPoint)); return $this->noContent(); } diff --git a/app/Http/Controllers/Api/ScheduleController.php b/app/Http/Controllers/Api/ScheduleController.php index 09f64248..d12eabc7 100644 --- a/app/Http/Controllers/Api/ScheduleController.php +++ b/app/Http/Controllers/Api/ScheduleController.php @@ -67,7 +67,7 @@ class ScheduleController extends AbstractApiController public function store() { try { - $schedule = dispatch(new CreateScheduleCommand( + $schedule = execute(new CreateScheduleCommand( Binput::get('name'), Binput::get('message', null, false, false), Binput::get('status'), @@ -92,7 +92,7 @@ class ScheduleController extends AbstractApiController public function update(Schedule $schedule) { try { - $schedule = dispatch(new UpdateScheduleCommand( + $schedule = execute(new UpdateScheduleCommand( $schedule, Binput::get('name'), Binput::get('message'), @@ -118,7 +118,7 @@ class ScheduleController extends AbstractApiController public function destroy(Schedule $schedule) { try { - dispatch(new DeleteScheduleCommand($schedule)); + execute(new DeleteScheduleCommand($schedule)); } catch (QueryException $e) { throw new BadRequestHttpException(); } diff --git a/app/Http/Controllers/Api/SubscriberController.php b/app/Http/Controllers/Api/SubscriberController.php index 5a8b1178..621aa06d 100644 --- a/app/Http/Controllers/Api/SubscriberController.php +++ b/app/Http/Controllers/Api/SubscriberController.php @@ -50,7 +50,7 @@ class SubscriberController extends AbstractApiController $verified = Binput::get('verify', app(Repository::class)->get('setting.skip_subscriber_verification')); try { - $subscriber = dispatch(new SubscribeSubscriberCommand(Binput::get('email'), $verified, Binput::get('components', null))); + $subscriber = execute(new SubscribeSubscriberCommand(Binput::get('email'), $verified, Binput::get('components', null))); } catch (QueryException $e) { throw new BadRequestHttpException(); } @@ -67,7 +67,7 @@ class SubscriberController extends AbstractApiController */ public function destroy(Subscriber $subscriber) { - dispatch(new UnsubscribeSubscriberCommand($subscriber)); + execute(new UnsubscribeSubscriberCommand($subscriber)); return $this->noContent(); } diff --git a/app/Http/Controllers/Api/SubscriptionController.php b/app/Http/Controllers/Api/SubscriptionController.php index a7372d08..173a5e0f 100644 --- a/app/Http/Controllers/Api/SubscriptionController.php +++ b/app/Http/Controllers/Api/SubscriptionController.php @@ -30,7 +30,7 @@ class SubscriptionController extends AbstractApiController */ public function destroy(Subscription $subscription) { - dispatch(new UnsubscribeSubscriptionCommand($subscription)); + execute(new UnsubscribeSubscriptionCommand($subscription)); return $this->noContent(); } diff --git a/app/Http/Controllers/Dashboard/ApiController.php b/app/Http/Controllers/Dashboard/ApiController.php index 9cc80c4e..7c92b2c8 100644 --- a/app/Http/Controllers/Dashboard/ApiController.php +++ b/app/Http/Controllers/Dashboard/ApiController.php @@ -36,7 +36,7 @@ class ApiController extends AbstractApiController public function postUpdateComponent(Component $component) { try { - dispatch(new UpdateComponentCommand( + execute(new UpdateComponentCommand( $component, $component->name, $component->description, @@ -68,7 +68,7 @@ class ApiController extends AbstractApiController try { $component = Component::find($componentId); - dispatch(new UpdateComponentCommand( + execute(new UpdateComponentCommand( $component, $component->name, $component->description, @@ -100,7 +100,7 @@ class ApiController extends AbstractApiController foreach ($groupData as $order => $groupId) { $group = ComponentGroup::find($groupId); - dispatch(new UpdateComponentGroupCommand( + execute(new UpdateComponentGroupCommand( $group, $group->name, $order + 1, diff --git a/app/Http/Controllers/Dashboard/ComponentController.php b/app/Http/Controllers/Dashboard/ComponentController.php index e1ecd5eb..2745cf4b 100644 --- a/app/Http/Controllers/Dashboard/ComponentController.php +++ b/app/Http/Controllers/Dashboard/ComponentController.php @@ -115,7 +115,7 @@ class ComponentController extends Controller $tags = array_pull($componentData, 'tags'); try { - $component = dispatch(new UpdateComponentCommand( + $component = execute(new UpdateComponentCommand( $component, $componentData['name'], $componentData['description'], @@ -140,9 +140,9 @@ class ComponentController extends Controller Collection::make(preg_split('/ ?, ?/', $tags))->map(function ($tag) { return trim($tag); })->map(function ($tag) { - return dispatch(new CreateTagCommand($tag)); + return execute(new CreateTagCommand($tag)); })->each(function ($tag) use ($component) { - dispatch(new ApplyTagCommand($component, $tag)); + execute(new ApplyTagCommand($component, $tag)); }); return cachet_redirect('dashboard.components.edit', [$component->id]) @@ -172,7 +172,7 @@ class ComponentController extends Controller $tags = array_pull($componentData, 'tags'); try { - $component = dispatch(new CreateComponentCommand( + $component = execute(new CreateComponentCommand( $componentData['name'], $componentData['description'], $componentData['status'], @@ -193,9 +193,9 @@ class ComponentController extends Controller Collection::make(preg_split('/ ?, ?/', $tags))->map(function ($tag) { return trim($tag); })->map(function ($tag) { - return dispatch(new CreateTagCommand($tag)); + return execute(new CreateTagCommand($tag)); })->each(function ($tag) use ($component) { - dispatch(new ApplyTagCommand($component, $tag)); + execute(new ApplyTagCommand($component, $tag)); }); return cachet_redirect('dashboard.components') @@ -211,7 +211,7 @@ class ComponentController extends Controller */ public function deleteComponentAction(Component $component) { - dispatch(new RemoveComponentCommand($component)); + execute(new RemoveComponentCommand($component)); return cachet_redirect('dashboard.components') ->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.components.delete.success'))); diff --git a/app/Http/Controllers/Dashboard/ComponentGroupController.php b/app/Http/Controllers/Dashboard/ComponentGroupController.php index fcf333db..8ef79503 100644 --- a/app/Http/Controllers/Dashboard/ComponentGroupController.php +++ b/app/Http/Controllers/Dashboard/ComponentGroupController.php @@ -87,7 +87,7 @@ class ComponentGroupController extends Controller */ public function deleteComponentGroupAction(ComponentGroup $group) { - dispatch(new RemoveComponentGroupCommand($group)); + execute(new RemoveComponentGroupCommand($group)); return cachet_redirect('dashboard.components.groups') ->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.components.delete.success'))); @@ -126,7 +126,7 @@ class ComponentGroupController extends Controller public function postAddComponentGroup() { try { - $group = dispatch(new CreateComponentGroupCommand( + $group = execute(new CreateComponentGroupCommand( Binput::get('name'), Binput::get('order', 0), Binput::get('collapsed'), @@ -153,7 +153,7 @@ class ComponentGroupController extends Controller public function updateComponentGroupAction(ComponentGroup $group) { try { - $group = dispatch(new UpdateComponentGroupCommand( + $group = execute(new UpdateComponentGroupCommand( $group, Binput::get('name'), $group->order, diff --git a/app/Http/Controllers/Dashboard/DashboardController.php b/app/Http/Controllers/Dashboard/DashboardController.php index 835ec22f..0c1c55e7 100644 --- a/app/Http/Controllers/Dashboard/DashboardController.php +++ b/app/Http/Controllers/Dashboard/DashboardController.php @@ -101,7 +101,7 @@ class DashboardController extends Controller $welcomeUser = !Auth::user()->welcomed; if ($welcomeUser) { - dispatch(new WelcomeUserCommand(Auth::user())); + execute(new WelcomeUserCommand(Auth::user())); } $entries = null; diff --git a/app/Http/Controllers/Dashboard/IncidentController.php b/app/Http/Controllers/Dashboard/IncidentController.php index 21aa0811..a64b361c 100644 --- a/app/Http/Controllers/Dashboard/IncidentController.php +++ b/app/Http/Controllers/Dashboard/IncidentController.php @@ -117,7 +117,7 @@ class IncidentController extends Controller public function createIncidentAction() { try { - $incident = dispatch(new CreateIncidentCommand( + $incident = execute(new CreateIncidentCommand( Binput::get('name'), Binput::get('status'), Binput::get('message', null, false, false), @@ -213,7 +213,7 @@ class IncidentController extends Controller */ public function deleteIncidentAction(Incident $incident) { - dispatch(new RemoveIncidentCommand($incident)); + execute(new RemoveIncidentCommand($incident)); return cachet_redirect('dashboard.incidents') ->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.incidents.delete.success'))); @@ -246,7 +246,7 @@ class IncidentController extends Controller public function editIncidentAction(Incident $incident) { try { - $incident = dispatch(new UpdateIncidentCommand( + $incident = execute(new UpdateIncidentCommand( $incident, Binput::get('name'), Binput::get('status'), diff --git a/app/Http/Controllers/Dashboard/IncidentUpdateController.php b/app/Http/Controllers/Dashboard/IncidentUpdateController.php index 043c2b7c..69a084eb 100644 --- a/app/Http/Controllers/Dashboard/IncidentUpdateController.php +++ b/app/Http/Controllers/Dashboard/IncidentUpdateController.php @@ -101,7 +101,7 @@ class IncidentUpdateController extends Controller public function createIncidentUpdateAction(Incident $incident) { try { - $incidentUpdate = dispatch(new CreateIncidentUpdateCommand( + $incidentUpdate = execute(new CreateIncidentUpdateCommand( $incident, Binput::get('status'), Binput::get('message'), @@ -151,7 +151,7 @@ class IncidentUpdateController extends Controller public function editIncidentUpdateAction(Incident $incident, IncidentUpdate $incidentUpdate) { try { - $incidentUpdate = dispatch(new UpdateIncidentUpdateCommand( + $incidentUpdate = execute(new UpdateIncidentUpdateCommand( $incidentUpdate, Binput::get('status'), Binput::get('message'), diff --git a/app/Http/Controllers/Dashboard/MetricController.php b/app/Http/Controllers/Dashboard/MetricController.php index 94f8379d..56a4f6e9 100644 --- a/app/Http/Controllers/Dashboard/MetricController.php +++ b/app/Http/Controllers/Dashboard/MetricController.php @@ -71,7 +71,7 @@ class MetricController extends Controller $metricData = Binput::get('metric'); try { - dispatch(new CreateMetricCommand( + execute(new CreateMetricCommand( $metricData['name'], $metricData['suffix'], $metricData['description'], @@ -115,7 +115,7 @@ class MetricController extends Controller */ public function deleteMetricAction(Metric $metric) { - dispatch(new RemoveMetricCommand($metric)); + execute(new RemoveMetricCommand($metric)); return cachet_redirect('dashboard.metrics') ->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.metrics.delete.success'))); @@ -146,7 +146,7 @@ class MetricController extends Controller public function editMetricAction(Metric $metric) { try { - dispatch(new UpdateMetricCommand( + execute(new UpdateMetricCommand( $metric, Binput::get('name', null, false), Binput::get('suffix', null, false), diff --git a/app/Http/Controllers/Dashboard/ScheduleController.php b/app/Http/Controllers/Dashboard/ScheduleController.php index 6a549fc0..ceb369bc 100644 --- a/app/Http/Controllers/Dashboard/ScheduleController.php +++ b/app/Http/Controllers/Dashboard/ScheduleController.php @@ -81,7 +81,7 @@ class ScheduleController extends Controller public function addScheduleAction() { try { - dispatch(new CreateScheduleCommand( + execute(new CreateScheduleCommand( Binput::get('name'), Binput::get('message', null, false, false), Binput::get('status', Schedule::UPCOMING), @@ -127,7 +127,7 @@ class ScheduleController extends Controller public function editScheduleAction(Schedule $schedule) { try { - $schedule = dispatch(new UpdateScheduleCommand( + $schedule = execute(new UpdateScheduleCommand( $schedule, Binput::get('name', null), Binput::get('message', null), @@ -156,7 +156,7 @@ class ScheduleController extends Controller */ public function deleteScheduleAction(Schedule $schedule) { - dispatch(new DeleteScheduleCommand($schedule)); + execute(new DeleteScheduleCommand($schedule)); return cachet_redirect('dashboard.schedule') ->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.schedule.delete.success'))); diff --git a/app/Http/Controllers/Dashboard/SettingsController.php b/app/Http/Controllers/Dashboard/SettingsController.php index 80399fa3..f128e227 100644 --- a/app/Http/Controllers/Dashboard/SettingsController.php +++ b/app/Http/Controllers/Dashboard/SettingsController.php @@ -319,7 +319,7 @@ class SettingsController extends Controller { $config = Binput::get('config'); - dispatch(new UpdateConfigCommand($config)); + execute(new UpdateConfigCommand($config)); return cachet_redirect('dashboard.settings.mail') ->withInput(Binput::all()) diff --git a/app/Http/Controllers/Dashboard/SubscriberController.php b/app/Http/Controllers/Dashboard/SubscriberController.php index e9749996..48305540 100644 --- a/app/Http/Controllers/Dashboard/SubscriberController.php +++ b/app/Http/Controllers/Dashboard/SubscriberController.php @@ -58,7 +58,7 @@ class SubscriberController extends Controller $subscribers = preg_split("/\r\n|\n|\r/", Binput::get('email')); foreach ($subscribers as $subscriber) { - dispatch(new SubscribeSubscriberCommand($subscriber, $verified)); + execute(new SubscribeSubscriberCommand($subscriber, $verified)); } } catch (ValidationException $e) { return cachet_redirect('dashboard.subscribers.create') @@ -82,7 +82,7 @@ class SubscriberController extends Controller */ public function deleteSubscriberAction(Subscriber $subscriber) { - dispatch(new UnsubscribeSubscriberCommand($subscriber)); + execute(new UnsubscribeSubscriberCommand($subscriber)); return cachet_redirect('dashboard.subscribers'); } diff --git a/app/Http/Controllers/Dashboard/TeamController.php b/app/Http/Controllers/Dashboard/TeamController.php index 6e0d112b..b7621619 100644 --- a/app/Http/Controllers/Dashboard/TeamController.php +++ b/app/Http/Controllers/Dashboard/TeamController.php @@ -80,7 +80,7 @@ class TeamController extends Controller public function postAddUser() { try { - dispatch(new CreateUserCommand( + execute(new CreateUserCommand( Binput::get('username'), Binput::get('password'), Binput::get('email'), @@ -129,7 +129,7 @@ class TeamController extends Controller public function postInviteUser() { try { - dispatch(new InviteUserCommand( + execute(new InviteUserCommand( array_unique(array_filter((array) Binput::get('emails'))) )); } catch (ValidationException $e) { @@ -152,7 +152,7 @@ class TeamController extends Controller */ public function deleteUser(User $user) { - dispatch(new RemoveUserCommand($user)); + execute(new RemoveUserCommand($user)); return cachet_redirect('dashboard.team') ->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.team.delete.success'))); diff --git a/app/Http/Controllers/SetupController.php b/app/Http/Controllers/SetupController.php index 5c603cbf..0edf88fe 100644 --- a/app/Http/Controllers/SetupController.php +++ b/app/Http/Controllers/SetupController.php @@ -258,7 +258,7 @@ class SetupController extends Controller $envData = array_pull($postData, 'env'); // Write the env to the .env file. - dispatch(new UpdateConfigCommand($envData)); + execute(new UpdateConfigCommand($envData)); if (Request::ajax()) { return Response::json(['status' => 1]); diff --git a/app/Http/Controllers/SignupController.php b/app/Http/Controllers/SignupController.php index a506c59f..6c7db152 100644 --- a/app/Http/Controllers/SignupController.php +++ b/app/Http/Controllers/SignupController.php @@ -69,7 +69,7 @@ class SignupController extends Controller } try { - dispatch(new SignupUserCommand( + execute(new SignupUserCommand( Binput::get('username'), Binput::get('password'), Binput::get('email'), @@ -82,7 +82,7 @@ class SignupController extends Controller ->withErrors($e->getMessageBag()); } - dispatch(new ClaimInviteCommand($invite)); + execute(new ClaimInviteCommand($invite)); return cachet_redirect('status-page') ->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('cachet.signup.success'))); diff --git a/app/Http/Controllers/SubscribeController.php b/app/Http/Controllers/SubscribeController.php index 7ae2cc16..8fa89587 100644 --- a/app/Http/Controllers/SubscribeController.php +++ b/app/Http/Controllers/SubscribeController.php @@ -80,7 +80,7 @@ class SubscribeController extends Controller $verified = app(Repository::class)->get('setting.skip_subscriber_verification'); try { - $subscription = dispatch(new SubscribeSubscriberCommand($email, $verified)); + $subscription = execute(new SubscribeSubscriberCommand($email, $verified)); } catch (ValidationException $e) { return cachet_redirect('status-page') ->withInput(Binput::all()) @@ -116,7 +116,7 @@ class SubscribeController extends Controller } if (!$subscriber->is_verified) { - dispatch(new VerifySubscriberCommand($subscriber)); + execute(new VerifySubscriberCommand($subscriber)); } return cachet_redirect('status-page') @@ -144,9 +144,9 @@ class SubscribeController extends Controller } if ($subscription) { - dispatch(new UnsubscribeSubscriptionCommand(Subscription::forSubscriber($subscriber->id)->firstOrFail())); + execute(new UnsubscribeSubscriptionCommand(Subscription::forSubscriber($subscriber->id)->firstOrFail())); } else { - dispatch(new UnsubscribeSubscriberCommand($subscriber)); + execute(new UnsubscribeSubscriberCommand($subscriber)); } return cachet_redirect('status-page') @@ -204,7 +204,7 @@ class SubscribeController extends Controller } try { - dispatch(new UpdateSubscriberSubscriptionCommand($subscriber, Binput::get('subscriptions'))); + execute(new UpdateSubscriberSubscriptionCommand($subscriber, Binput::get('subscriptions'))); } catch (ValidationException $e) { return cachet_redirect('subscribe.manage', $subscriber->verify_code) ->withInput(Binput::all()) diff --git a/app/helpers.php b/app/helpers.php index c3bb1aae..ce7b89a2 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -10,6 +10,7 @@ */ use CachetHQ\Cachet\Settings\Repository; +use Illuminate\Contracts\Bus\Dispatcher; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Request; use Jenssegers\Date\Date; @@ -159,3 +160,17 @@ if (!function_exists('cachet_redirect')) { return app('redirect')->to($url, $status, $headers); } } + +if (!function_exists('execute')) { + /** + * Send the given command to the dispatcher for execution. + * + * @param object $command + * + * @return void + */ + function execute($command) + { + app(Dispatcher::class)->execute($command); + } +}