Fix command dispatching

This commit is contained in:
James Brooks
2018-06-25 22:25:54 +01:00
parent dd6bbce517
commit 8bb8ee3dc7
30 changed files with 88 additions and 73 deletions

View File

@@ -116,7 +116,7 @@ class CreateIncidentCommandHandler
// Update the component. // Update the component.
if ($component = Component::find($command->component_id)) { if ($component = Component::find($command->component_id)) {
dispatch(new UpdateComponentCommand( execute(new UpdateComponentCommand(
Component::find($command->component_id), Component::find($command->component_id),
null, null,
null, null,

View File

@@ -88,7 +88,7 @@ class UpdateIncidentCommandHandler
// Update the component. // Update the component.
if ($component = Component::find($command->component_id)) { if ($component = Component::find($command->component_id)) {
dispatch(new UpdateComponentCommand( execute(new UpdateComponentCommand(
Component::find($command->component_id), Component::find($command->component_id),
null, null,
null, null,

View File

@@ -63,7 +63,7 @@ class CreateIncidentUpdateCommandHandler
$update = IncidentUpdate::create($data); $update = IncidentUpdate::create($data);
// Update the original incident with the new status. // Update the original incident with the new status.
dispatch(new UpdateIncidentCommand( execute(new UpdateIncidentCommand(
$command->incident, $command->incident,
null, null,
$command->status, $command->status,

View File

@@ -58,7 +58,7 @@ class SubscribeSubscriberCommandHandler
}); });
if ($command->verified) { if ($command->verified) {
dispatch(new VerifySubscriberCommand($subscriber)); execute(new VerifySubscriberCommand($subscriber));
} else { } else {
$subscriber->notify(new VerifySubscriptionNotification()); $subscriber->notify(new VerifySubscriptionNotification());
} }

View File

@@ -42,6 +42,6 @@ class BeaconCommand extends Command
*/ */
public function fire() public function fire()
{ {
dispatch(new SendBeaconJob()); execute(new SendBeaconJob());
} }
} }

View File

@@ -27,7 +27,7 @@ class ApiFilter
* *
* @return \GrahamCampbell\Exceptions\Displayers\DisplayerInterface[] * @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*')) { if ($request->is('api*')) {
foreach ($displayers as $index => $displayer) { foreach ($displayers as $index => $displayer) {

View File

@@ -76,7 +76,7 @@ class ComponentController extends AbstractApiController
public function store() public function store()
{ {
try { try {
$component = dispatch(new CreateComponentCommand( $component = execute(new CreateComponentCommand(
Binput::get('name'), Binput::get('name'),
Binput::get('description'), Binput::get('description'),
Binput::get('status'), Binput::get('status'),
@@ -97,9 +97,9 @@ class ComponentController extends AbstractApiController
Collection::make(preg_split('/ ?, ?/', $tags))->map(function ($tag) { Collection::make(preg_split('/ ?, ?/', $tags))->map(function ($tag) {
return trim($tag); return trim($tag);
})->map(function ($tag) { })->map(function ($tag) {
return dispatch(new CreateTagCommand($tag)); return execute(new CreateTagCommand($tag));
})->each(function ($tag) use ($component) { })->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) public function update(Component $component)
{ {
try { try {
dispatch(new UpdateComponentCommand( execute(new UpdateComponentCommand(
$component, $component,
Binput::get('name'), Binput::get('name'),
Binput::get('description'), Binput::get('description'),
@@ -139,9 +139,9 @@ class ComponentController extends AbstractApiController
Collection::make(preg_split('/ ?, ?/', $tags))->map(function ($tag) { Collection::make(preg_split('/ ?, ?/', $tags))->map(function ($tag) {
return trim($tag); return trim($tag);
})->map(function ($tag) { })->map(function ($tag) {
return dispatch(new CreateTagCommand($tag)); return execute(new CreateTagCommand($tag));
})->each(function ($tag) use ($component) { })->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) public function destroy(Component $component)
{ {
dispatch(new RemoveComponentCommand($component)); execute(new RemoveComponentCommand($component));
return $this->noContent(); return $this->noContent();
} }

View File

@@ -92,7 +92,7 @@ class ComponentGroupController extends AbstractApiController
public function store() public function store()
{ {
try { try {
$group = dispatch(new CreateComponentGroupCommand( $group = execute(new CreateComponentGroupCommand(
Binput::get('name'), Binput::get('name'),
Binput::get('order', 0), Binput::get('order', 0),
Binput::get('collapsed', 0), Binput::get('collapsed', 0),
@@ -115,7 +115,7 @@ class ComponentGroupController extends AbstractApiController
public function update(ComponentGroup $group) public function update(ComponentGroup $group)
{ {
try { try {
$group = dispatch(new UpdateComponentGroupCommand( $group = execute(new UpdateComponentGroupCommand(
$group, $group,
Binput::get('name'), Binput::get('name'),
Binput::get('order'), Binput::get('order'),
@@ -138,7 +138,7 @@ class ComponentGroupController extends AbstractApiController
*/ */
public function destroy(ComponentGroup $group) public function destroy(ComponentGroup $group)
{ {
dispatch(new RemoveComponentGroupCommand($group)); execute(new RemoveComponentGroupCommand($group));
return $this->noContent(); return $this->noContent();
} }

View File

@@ -67,7 +67,7 @@ class IncidentController extends AbstractApiController
public function store() public function store()
{ {
try { try {
$incident = dispatch(new CreateIncidentCommand( $incident = execute(new CreateIncidentCommand(
Binput::get('name'), Binput::get('name'),
Binput::get('status'), Binput::get('status'),
Binput::get('message', null, false, false), Binput::get('message', null, false, false),
@@ -98,7 +98,7 @@ class IncidentController extends AbstractApiController
public function update(Incident $incident) public function update(Incident $incident)
{ {
try { try {
$incident = dispatch(new UpdateIncidentCommand( $incident = execute(new UpdateIncidentCommand(
$incident, $incident,
Binput::get('name'), Binput::get('name'),
Binput::get('status'), Binput::get('status'),
@@ -128,7 +128,7 @@ class IncidentController extends AbstractApiController
*/ */
public function destroy(Incident $incident) public function destroy(Incident $incident)
{ {
dispatch(new RemoveIncidentCommand($incident)); execute(new RemoveIncidentCommand($incident));
return $this->noContent(); return $this->noContent();
} }

View File

@@ -74,7 +74,7 @@ class IncidentUpdateController extends AbstractApiController
public function store(Incident $incident) public function store(Incident $incident)
{ {
try { try {
$update = dispatch(new CreateIncidentUpdateCommand( $update = execute(new CreateIncidentUpdateCommand(
$incident, $incident,
Binput::get('status'), Binput::get('status'),
Binput::get('message'), Binput::get('message'),
@@ -100,7 +100,7 @@ class IncidentUpdateController extends AbstractApiController
public function update(Incident $incident, IncidentUpdate $update) public function update(Incident $incident, IncidentUpdate $update)
{ {
try { try {
$update = dispatch(new UpdateIncidentUpdateCommand( $update = execute(new UpdateIncidentUpdateCommand(
$update, $update,
Binput::get('status'), Binput::get('status'),
Binput::get('message'), Binput::get('message'),
@@ -124,7 +124,7 @@ class IncidentUpdateController extends AbstractApiController
public function destroy(Incident $incident, IncidentUpdate $update) public function destroy(Incident $incident, IncidentUpdate $update)
{ {
try { try {
dispatch(new RemoveIncidentUpdateCommand($update)); execute(new RemoveIncidentUpdateCommand($update));
} catch (QueryException $e) { } catch (QueryException $e) {
throw new BadRequestHttpException(); throw new BadRequestHttpException();
} }

View File

@@ -62,7 +62,7 @@ class MetricController extends AbstractApiController
public function store() public function store()
{ {
try { try {
$metric = dispatch(new CreateMetricCommand( $metric = execute(new CreateMetricCommand(
Binput::get('name'), Binput::get('name'),
Binput::get('suffix'), Binput::get('suffix'),
Binput::get('description'), Binput::get('description'),
@@ -92,7 +92,7 @@ class MetricController extends AbstractApiController
public function update(Metric $metric) public function update(Metric $metric)
{ {
try { try {
$metric = dispatch(new UpdateMetricCommand( $metric = execute(new UpdateMetricCommand(
$metric, $metric,
Binput::get('name'), Binput::get('name'),
Binput::get('suffix'), Binput::get('suffix'),
@@ -122,7 +122,7 @@ class MetricController extends AbstractApiController
*/ */
public function destroy(Metric $metric) public function destroy(Metric $metric)
{ {
dispatch(new RemoveMetricCommand($metric)); execute(new RemoveMetricCommand($metric));
return $this->noContent(); return $this->noContent();
} }

View File

@@ -48,7 +48,7 @@ class MetricPointController extends AbstractApiController
public function store(Metric $metric) public function store(Metric $metric)
{ {
try { try {
$metricPoint = dispatch(new CreateMetricPointCommand( $metricPoint = execute(new CreateMetricPointCommand(
$metric, $metric,
Binput::get('value'), Binput::get('value'),
Binput::get('timestamp') Binput::get('timestamp')
@@ -70,7 +70,7 @@ class MetricPointController extends AbstractApiController
*/ */
public function update(Metric $metric, MetricPoint $metricPoint) public function update(Metric $metric, MetricPoint $metricPoint)
{ {
$metricPoint = dispatch(new UpdateMetricPointCommand( $metricPoint = execute(new UpdateMetricPointCommand(
$metricPoint, $metricPoint,
$metric, $metric,
Binput::get('value'), Binput::get('value'),
@@ -90,7 +90,7 @@ class MetricPointController extends AbstractApiController
*/ */
public function destroy(Metric $metric, MetricPoint $metricPoint) public function destroy(Metric $metric, MetricPoint $metricPoint)
{ {
dispatch(new RemoveMetricPointCommand($metricPoint)); execute(new RemoveMetricPointCommand($metricPoint));
return $this->noContent(); return $this->noContent();
} }

View File

@@ -67,7 +67,7 @@ class ScheduleController extends AbstractApiController
public function store() public function store()
{ {
try { try {
$schedule = dispatch(new CreateScheduleCommand( $schedule = execute(new CreateScheduleCommand(
Binput::get('name'), Binput::get('name'),
Binput::get('message', null, false, false), Binput::get('message', null, false, false),
Binput::get('status'), Binput::get('status'),
@@ -92,7 +92,7 @@ class ScheduleController extends AbstractApiController
public function update(Schedule $schedule) public function update(Schedule $schedule)
{ {
try { try {
$schedule = dispatch(new UpdateScheduleCommand( $schedule = execute(new UpdateScheduleCommand(
$schedule, $schedule,
Binput::get('name'), Binput::get('name'),
Binput::get('message'), Binput::get('message'),
@@ -118,7 +118,7 @@ class ScheduleController extends AbstractApiController
public function destroy(Schedule $schedule) public function destroy(Schedule $schedule)
{ {
try { try {
dispatch(new DeleteScheduleCommand($schedule)); execute(new DeleteScheduleCommand($schedule));
} catch (QueryException $e) { } catch (QueryException $e) {
throw new BadRequestHttpException(); throw new BadRequestHttpException();
} }

View File

@@ -50,7 +50,7 @@ class SubscriberController extends AbstractApiController
$verified = Binput::get('verify', app(Repository::class)->get('setting.skip_subscriber_verification')); $verified = Binput::get('verify', app(Repository::class)->get('setting.skip_subscriber_verification'));
try { 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) { } catch (QueryException $e) {
throw new BadRequestHttpException(); throw new BadRequestHttpException();
} }
@@ -67,7 +67,7 @@ class SubscriberController extends AbstractApiController
*/ */
public function destroy(Subscriber $subscriber) public function destroy(Subscriber $subscriber)
{ {
dispatch(new UnsubscribeSubscriberCommand($subscriber)); execute(new UnsubscribeSubscriberCommand($subscriber));
return $this->noContent(); return $this->noContent();
} }

View File

@@ -30,7 +30,7 @@ class SubscriptionController extends AbstractApiController
*/ */
public function destroy(Subscription $subscription) public function destroy(Subscription $subscription)
{ {
dispatch(new UnsubscribeSubscriptionCommand($subscription)); execute(new UnsubscribeSubscriptionCommand($subscription));
return $this->noContent(); return $this->noContent();
} }

View File

@@ -36,7 +36,7 @@ class ApiController extends AbstractApiController
public function postUpdateComponent(Component $component) public function postUpdateComponent(Component $component)
{ {
try { try {
dispatch(new UpdateComponentCommand( execute(new UpdateComponentCommand(
$component, $component,
$component->name, $component->name,
$component->description, $component->description,
@@ -68,7 +68,7 @@ class ApiController extends AbstractApiController
try { try {
$component = Component::find($componentId); $component = Component::find($componentId);
dispatch(new UpdateComponentCommand( execute(new UpdateComponentCommand(
$component, $component,
$component->name, $component->name,
$component->description, $component->description,
@@ -100,7 +100,7 @@ class ApiController extends AbstractApiController
foreach ($groupData as $order => $groupId) { foreach ($groupData as $order => $groupId) {
$group = ComponentGroup::find($groupId); $group = ComponentGroup::find($groupId);
dispatch(new UpdateComponentGroupCommand( execute(new UpdateComponentGroupCommand(
$group, $group,
$group->name, $group->name,
$order + 1, $order + 1,

View File

@@ -115,7 +115,7 @@ class ComponentController extends Controller
$tags = array_pull($componentData, 'tags'); $tags = array_pull($componentData, 'tags');
try { try {
$component = dispatch(new UpdateComponentCommand( $component = execute(new UpdateComponentCommand(
$component, $component,
$componentData['name'], $componentData['name'],
$componentData['description'], $componentData['description'],
@@ -140,9 +140,9 @@ class ComponentController extends Controller
Collection::make(preg_split('/ ?, ?/', $tags))->map(function ($tag) { Collection::make(preg_split('/ ?, ?/', $tags))->map(function ($tag) {
return trim($tag); return trim($tag);
})->map(function ($tag) { })->map(function ($tag) {
return dispatch(new CreateTagCommand($tag)); return execute(new CreateTagCommand($tag));
})->each(function ($tag) use ($component) { })->each(function ($tag) use ($component) {
dispatch(new ApplyTagCommand($component, $tag)); execute(new ApplyTagCommand($component, $tag));
}); });
return cachet_redirect('dashboard.components.edit', [$component->id]) return cachet_redirect('dashboard.components.edit', [$component->id])
@@ -172,7 +172,7 @@ class ComponentController extends Controller
$tags = array_pull($componentData, 'tags'); $tags = array_pull($componentData, 'tags');
try { try {
$component = dispatch(new CreateComponentCommand( $component = execute(new CreateComponentCommand(
$componentData['name'], $componentData['name'],
$componentData['description'], $componentData['description'],
$componentData['status'], $componentData['status'],
@@ -193,9 +193,9 @@ class ComponentController extends Controller
Collection::make(preg_split('/ ?, ?/', $tags))->map(function ($tag) { Collection::make(preg_split('/ ?, ?/', $tags))->map(function ($tag) {
return trim($tag); return trim($tag);
})->map(function ($tag) { })->map(function ($tag) {
return dispatch(new CreateTagCommand($tag)); return execute(new CreateTagCommand($tag));
})->each(function ($tag) use ($component) { })->each(function ($tag) use ($component) {
dispatch(new ApplyTagCommand($component, $tag)); execute(new ApplyTagCommand($component, $tag));
}); });
return cachet_redirect('dashboard.components') return cachet_redirect('dashboard.components')
@@ -211,7 +211,7 @@ class ComponentController extends Controller
*/ */
public function deleteComponentAction(Component $component) public function deleteComponentAction(Component $component)
{ {
dispatch(new RemoveComponentCommand($component)); execute(new RemoveComponentCommand($component));
return cachet_redirect('dashboard.components') return cachet_redirect('dashboard.components')
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.components.delete.success'))); ->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.components.delete.success')));

View File

@@ -87,7 +87,7 @@ class ComponentGroupController extends Controller
*/ */
public function deleteComponentGroupAction(ComponentGroup $group) public function deleteComponentGroupAction(ComponentGroup $group)
{ {
dispatch(new RemoveComponentGroupCommand($group)); execute(new RemoveComponentGroupCommand($group));
return cachet_redirect('dashboard.components.groups') return cachet_redirect('dashboard.components.groups')
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.components.delete.success'))); ->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.components.delete.success')));
@@ -126,7 +126,7 @@ class ComponentGroupController extends Controller
public function postAddComponentGroup() public function postAddComponentGroup()
{ {
try { try {
$group = dispatch(new CreateComponentGroupCommand( $group = execute(new CreateComponentGroupCommand(
Binput::get('name'), Binput::get('name'),
Binput::get('order', 0), Binput::get('order', 0),
Binput::get('collapsed'), Binput::get('collapsed'),
@@ -153,7 +153,7 @@ class ComponentGroupController extends Controller
public function updateComponentGroupAction(ComponentGroup $group) public function updateComponentGroupAction(ComponentGroup $group)
{ {
try { try {
$group = dispatch(new UpdateComponentGroupCommand( $group = execute(new UpdateComponentGroupCommand(
$group, $group,
Binput::get('name'), Binput::get('name'),
$group->order, $group->order,

View File

@@ -101,7 +101,7 @@ class DashboardController extends Controller
$welcomeUser = !Auth::user()->welcomed; $welcomeUser = !Auth::user()->welcomed;
if ($welcomeUser) { if ($welcomeUser) {
dispatch(new WelcomeUserCommand(Auth::user())); execute(new WelcomeUserCommand(Auth::user()));
} }
$entries = null; $entries = null;

View File

@@ -117,7 +117,7 @@ class IncidentController extends Controller
public function createIncidentAction() public function createIncidentAction()
{ {
try { try {
$incident = dispatch(new CreateIncidentCommand( $incident = execute(new CreateIncidentCommand(
Binput::get('name'), Binput::get('name'),
Binput::get('status'), Binput::get('status'),
Binput::get('message', null, false, false), Binput::get('message', null, false, false),
@@ -213,7 +213,7 @@ class IncidentController extends Controller
*/ */
public function deleteIncidentAction(Incident $incident) public function deleteIncidentAction(Incident $incident)
{ {
dispatch(new RemoveIncidentCommand($incident)); execute(new RemoveIncidentCommand($incident));
return cachet_redirect('dashboard.incidents') return cachet_redirect('dashboard.incidents')
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.incidents.delete.success'))); ->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) public function editIncidentAction(Incident $incident)
{ {
try { try {
$incident = dispatch(new UpdateIncidentCommand( $incident = execute(new UpdateIncidentCommand(
$incident, $incident,
Binput::get('name'), Binput::get('name'),
Binput::get('status'), Binput::get('status'),

View File

@@ -101,7 +101,7 @@ class IncidentUpdateController extends Controller
public function createIncidentUpdateAction(Incident $incident) public function createIncidentUpdateAction(Incident $incident)
{ {
try { try {
$incidentUpdate = dispatch(new CreateIncidentUpdateCommand( $incidentUpdate = execute(new CreateIncidentUpdateCommand(
$incident, $incident,
Binput::get('status'), Binput::get('status'),
Binput::get('message'), Binput::get('message'),
@@ -151,7 +151,7 @@ class IncidentUpdateController extends Controller
public function editIncidentUpdateAction(Incident $incident, IncidentUpdate $incidentUpdate) public function editIncidentUpdateAction(Incident $incident, IncidentUpdate $incidentUpdate)
{ {
try { try {
$incidentUpdate = dispatch(new UpdateIncidentUpdateCommand( $incidentUpdate = execute(new UpdateIncidentUpdateCommand(
$incidentUpdate, $incidentUpdate,
Binput::get('status'), Binput::get('status'),
Binput::get('message'), Binput::get('message'),

View File

@@ -71,7 +71,7 @@ class MetricController extends Controller
$metricData = Binput::get('metric'); $metricData = Binput::get('metric');
try { try {
dispatch(new CreateMetricCommand( execute(new CreateMetricCommand(
$metricData['name'], $metricData['name'],
$metricData['suffix'], $metricData['suffix'],
$metricData['description'], $metricData['description'],
@@ -115,7 +115,7 @@ class MetricController extends Controller
*/ */
public function deleteMetricAction(Metric $metric) public function deleteMetricAction(Metric $metric)
{ {
dispatch(new RemoveMetricCommand($metric)); execute(new RemoveMetricCommand($metric));
return cachet_redirect('dashboard.metrics') return cachet_redirect('dashboard.metrics')
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.metrics.delete.success'))); ->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) public function editMetricAction(Metric $metric)
{ {
try { try {
dispatch(new UpdateMetricCommand( execute(new UpdateMetricCommand(
$metric, $metric,
Binput::get('name', null, false), Binput::get('name', null, false),
Binput::get('suffix', null, false), Binput::get('suffix', null, false),

View File

@@ -81,7 +81,7 @@ class ScheduleController extends Controller
public function addScheduleAction() public function addScheduleAction()
{ {
try { try {
dispatch(new CreateScheduleCommand( execute(new CreateScheduleCommand(
Binput::get('name'), Binput::get('name'),
Binput::get('message', null, false, false), Binput::get('message', null, false, false),
Binput::get('status', Schedule::UPCOMING), Binput::get('status', Schedule::UPCOMING),
@@ -127,7 +127,7 @@ class ScheduleController extends Controller
public function editScheduleAction(Schedule $schedule) public function editScheduleAction(Schedule $schedule)
{ {
try { try {
$schedule = dispatch(new UpdateScheduleCommand( $schedule = execute(new UpdateScheduleCommand(
$schedule, $schedule,
Binput::get('name', null), Binput::get('name', null),
Binput::get('message', null), Binput::get('message', null),
@@ -156,7 +156,7 @@ class ScheduleController extends Controller
*/ */
public function deleteScheduleAction(Schedule $schedule) public function deleteScheduleAction(Schedule $schedule)
{ {
dispatch(new DeleteScheduleCommand($schedule)); execute(new DeleteScheduleCommand($schedule));
return cachet_redirect('dashboard.schedule') return cachet_redirect('dashboard.schedule')
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.schedule.delete.success'))); ->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.schedule.delete.success')));

View File

@@ -319,7 +319,7 @@ class SettingsController extends Controller
{ {
$config = Binput::get('config'); $config = Binput::get('config');
dispatch(new UpdateConfigCommand($config)); execute(new UpdateConfigCommand($config));
return cachet_redirect('dashboard.settings.mail') return cachet_redirect('dashboard.settings.mail')
->withInput(Binput::all()) ->withInput(Binput::all())

View File

@@ -58,7 +58,7 @@ class SubscriberController extends Controller
$subscribers = preg_split("/\r\n|\n|\r/", Binput::get('email')); $subscribers = preg_split("/\r\n|\n|\r/", Binput::get('email'));
foreach ($subscribers as $subscriber) { foreach ($subscribers as $subscriber) {
dispatch(new SubscribeSubscriberCommand($subscriber, $verified)); execute(new SubscribeSubscriberCommand($subscriber, $verified));
} }
} catch (ValidationException $e) { } catch (ValidationException $e) {
return cachet_redirect('dashboard.subscribers.create') return cachet_redirect('dashboard.subscribers.create')
@@ -82,7 +82,7 @@ class SubscriberController extends Controller
*/ */
public function deleteSubscriberAction(Subscriber $subscriber) public function deleteSubscriberAction(Subscriber $subscriber)
{ {
dispatch(new UnsubscribeSubscriberCommand($subscriber)); execute(new UnsubscribeSubscriberCommand($subscriber));
return cachet_redirect('dashboard.subscribers'); return cachet_redirect('dashboard.subscribers');
} }

View File

@@ -80,7 +80,7 @@ class TeamController extends Controller
public function postAddUser() public function postAddUser()
{ {
try { try {
dispatch(new CreateUserCommand( execute(new CreateUserCommand(
Binput::get('username'), Binput::get('username'),
Binput::get('password'), Binput::get('password'),
Binput::get('email'), Binput::get('email'),
@@ -129,7 +129,7 @@ class TeamController extends Controller
public function postInviteUser() public function postInviteUser()
{ {
try { try {
dispatch(new InviteUserCommand( execute(new InviteUserCommand(
array_unique(array_filter((array) Binput::get('emails'))) array_unique(array_filter((array) Binput::get('emails')))
)); ));
} catch (ValidationException $e) { } catch (ValidationException $e) {
@@ -152,7 +152,7 @@ class TeamController extends Controller
*/ */
public function deleteUser(User $user) public function deleteUser(User $user)
{ {
dispatch(new RemoveUserCommand($user)); execute(new RemoveUserCommand($user));
return cachet_redirect('dashboard.team') return cachet_redirect('dashboard.team')
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.team.delete.success'))); ->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.team.delete.success')));

View File

@@ -258,7 +258,7 @@ class SetupController extends Controller
$envData = array_pull($postData, 'env'); $envData = array_pull($postData, 'env');
// Write the env to the .env file. // Write the env to the .env file.
dispatch(new UpdateConfigCommand($envData)); execute(new UpdateConfigCommand($envData));
if (Request::ajax()) { if (Request::ajax()) {
return Response::json(['status' => 1]); return Response::json(['status' => 1]);

View File

@@ -69,7 +69,7 @@ class SignupController extends Controller
} }
try { try {
dispatch(new SignupUserCommand( execute(new SignupUserCommand(
Binput::get('username'), Binput::get('username'),
Binput::get('password'), Binput::get('password'),
Binput::get('email'), Binput::get('email'),
@@ -82,7 +82,7 @@ class SignupController extends Controller
->withErrors($e->getMessageBag()); ->withErrors($e->getMessageBag());
} }
dispatch(new ClaimInviteCommand($invite)); execute(new ClaimInviteCommand($invite));
return cachet_redirect('status-page') return cachet_redirect('status-page')
->withSuccess(sprintf('<strong>%s</strong> %s', trans('dashboard.notifications.awesome'), trans('cachet.signup.success'))); ->withSuccess(sprintf('<strong>%s</strong> %s', trans('dashboard.notifications.awesome'), trans('cachet.signup.success')));

View File

@@ -80,7 +80,7 @@ class SubscribeController extends Controller
$verified = app(Repository::class)->get('setting.skip_subscriber_verification'); $verified = app(Repository::class)->get('setting.skip_subscriber_verification');
try { try {
$subscription = dispatch(new SubscribeSubscriberCommand($email, $verified)); $subscription = execute(new SubscribeSubscriberCommand($email, $verified));
} catch (ValidationException $e) { } catch (ValidationException $e) {
return cachet_redirect('status-page') return cachet_redirect('status-page')
->withInput(Binput::all()) ->withInput(Binput::all())
@@ -116,7 +116,7 @@ class SubscribeController extends Controller
} }
if (!$subscriber->is_verified) { if (!$subscriber->is_verified) {
dispatch(new VerifySubscriberCommand($subscriber)); execute(new VerifySubscriberCommand($subscriber));
} }
return cachet_redirect('status-page') return cachet_redirect('status-page')
@@ -144,9 +144,9 @@ class SubscribeController extends Controller
} }
if ($subscription) { if ($subscription) {
dispatch(new UnsubscribeSubscriptionCommand(Subscription::forSubscriber($subscriber->id)->firstOrFail())); execute(new UnsubscribeSubscriptionCommand(Subscription::forSubscriber($subscriber->id)->firstOrFail()));
} else { } else {
dispatch(new UnsubscribeSubscriberCommand($subscriber)); execute(new UnsubscribeSubscriberCommand($subscriber));
} }
return cachet_redirect('status-page') return cachet_redirect('status-page')
@@ -204,7 +204,7 @@ class SubscribeController extends Controller
} }
try { try {
dispatch(new UpdateSubscriberSubscriptionCommand($subscriber, Binput::get('subscriptions'))); execute(new UpdateSubscriberSubscriptionCommand($subscriber, Binput::get('subscriptions')));
} catch (ValidationException $e) { } catch (ValidationException $e) {
return cachet_redirect('subscribe.manage', $subscriber->verify_code) return cachet_redirect('subscribe.manage', $subscriber->verify_code)
->withInput(Binput::all()) ->withInput(Binput::all())

View File

@@ -10,6 +10,7 @@
*/ */
use CachetHQ\Cachet\Settings\Repository; use CachetHQ\Cachet\Settings\Repository;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Request; use Illuminate\Support\Facades\Request;
use Jenssegers\Date\Date; use Jenssegers\Date\Date;
@@ -159,3 +160,17 @@ if (!function_exists('cachet_redirect')) {
return app('redirect')->to($url, $status, $headers); 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);
}
}