Merge branch '2.4' of github.com:CachetHQ/Cachet into feature/2895-custom-meta-descriptions-per-incident

This commit is contained in:
Nico Stapelbroek
2018-07-02 11:20:47 +02:00
399 changed files with 10754 additions and 5607 deletions
@@ -14,11 +14,13 @@ namespace CachetHQ\Cachet\Http\Controllers\Api;
use CachetHQ\Cachet\Bus\Commands\Component\CreateComponentCommand;
use CachetHQ\Cachet\Bus\Commands\Component\RemoveComponentCommand;
use CachetHQ\Cachet\Bus\Commands\Component\UpdateComponentCommand;
use CachetHQ\Cachet\Bus\Commands\Tag\ApplyTagCommand;
use CachetHQ\Cachet\Bus\Commands\Tag\CreateTagCommand;
use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\Tag;
use GrahamCampbell\Binput\Facades\Binput;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Database\QueryException;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Request;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
@@ -37,6 +39,10 @@ class ComponentController extends AbstractApiController
$components = Component::enabled();
}
if ($tags = Binput::get('tags')) {
$components->withAnyTags($tags);
}
$components->search(Binput::except(['sort', 'order', 'per_page']));
if ($sortBy = Binput::get('sort')) {
@@ -70,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'),
@@ -85,17 +91,16 @@ class ComponentController extends AbstractApiController
}
if (Binput::has('tags')) {
$component->tags()->delete();
// The component was added successfully, so now let's deal with the tags.
$tags = preg_split('/ ?, ?/', Binput::get('tags'));
// For every tag, do we need to create it?
$componentTags = array_map(function ($taggable) use ($component) {
return Tag::firstOrCreate([
'name' => $taggable,
])->id;
}, $tags);
$component->tags()->sync($componentTags);
Collection::make(preg_split('/ ?, ?/', $tags))->map(function ($tag) {
return trim($tag);
})->map(function ($tag) {
return execute(new CreateTagCommand($tag));
})->each(function ($tag) use ($component) {
execute(new ApplyTagCommand($component, $tag));
});
}
return $this->item($component);
@@ -111,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'),
@@ -119,7 +124,7 @@ class ComponentController extends AbstractApiController
Binput::get('link'),
Binput::get('order'),
Binput::get('group_id'),
(bool) Binput::get('enabled', true),
(bool) Binput::get('enabled'),
Binput::get('meta', null),
(bool) Binput::get('silent', false)
));
@@ -128,14 +133,16 @@ class ComponentController extends AbstractApiController
}
if (Binput::has('tags')) {
$tags = preg_split('/ ?, ?/', Binput::get('tags'));
$component->tags()->delete();
// For every tag, do we need to create it?
$componentTags = array_map(function ($taggable) use ($component) {
return Tag::firstOrCreate(['name' => $taggable])->id;
}, $tags);
$component->tags()->sync($componentTags);
// The component was added successfully, so now let's deal with the tags.
Collection::make(preg_split('/ ?, ?/', $tags))->map(function ($tag) {
return trim($tag);
})->map(function ($tag) {
return execute(new CreateTagCommand($tag));
})->each(function ($tag) use ($component) {
execute(new ApplyTagCommand($component, $tag));
});
}
return $this->item($component);
@@ -150,7 +157,7 @@ class ComponentController extends AbstractApiController
*/
public function destroy(Component $component)
{
dispatch(new RemoveComponentCommand($component));
execute(new RemoveComponentCommand($component));
return $this->noContent();
}
@@ -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();
}
@@ -17,7 +17,7 @@ use CachetHQ\Cachet\Integrations\Contracts\System;
/**
* This is the general api controller.
*
* @author James Brooks <james@bluebaytravel.co.uk>
* @author James Brooks <james@alt-three.com>
*/
class GeneralController extends AbstractApiController
{
@@ -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();
}
@@ -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();
}
@@ -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();
}
@@ -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')
@@ -64,13 +64,13 @@ class MetricPointController extends AbstractApiController
* Updates a metric point.
*
* @param \CachetHQ\Cachet\Models\Metric $metric
* @param \CachetHQ\Cachet\Models\MetircPoint $metricPoint
* @param \CachetHQ\Cachet\Models\MetricPoint $metricPoint
*
* @return \Illuminate\Http\JsonResponse
*/
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();
}
@@ -34,7 +34,7 @@ class ScheduleController extends AbstractApiController
*/
public function index()
{
$schedule = Schedule::whereRaw('1 = 1');
$schedule = Schedule::query();
if ($sortBy = Binput::get('sort')) {
$direction = Binput::has('order') && Binput::get('order') == 'desc';
@@ -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();
}
@@ -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();
}
@@ -30,7 +30,7 @@ class SubscriptionController extends AbstractApiController
*/
public function destroy(Subscription $subscription)
{
dispatch(new UnsubscribeSubscriptionCommand($subscription));
execute(new UnsubscribeSubscriptionCommand($subscription));
return $this->noContent();
}
@@ -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,
@@ -15,16 +15,20 @@ use AltThree\Validator\ValidationException;
use CachetHQ\Cachet\Bus\Commands\Component\CreateComponentCommand;
use CachetHQ\Cachet\Bus\Commands\Component\RemoveComponentCommand;
use CachetHQ\Cachet\Bus\Commands\Component\UpdateComponentCommand;
use CachetHQ\Cachet\Bus\Commands\ComponentGroup\CreateComponentGroupCommand;
use CachetHQ\Cachet\Bus\Commands\ComponentGroup\RemoveComponentGroupCommand;
use CachetHQ\Cachet\Bus\Commands\ComponentGroup\UpdateComponentGroupCommand;
use CachetHQ\Cachet\Bus\Commands\Tag\ApplyTagCommand;
use CachetHQ\Cachet\Bus\Commands\Tag\CreateTagCommand;
use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\ComponentGroup;
use CachetHQ\Cachet\Models\Tag;
use GrahamCampbell\Binput\Facades\Binput;
use Illuminate\Routing\Controller;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\View;
/**
* This is the component controller class.
*
* @author James Brooks <james@alt-three.com>
*/
class ComponentController extends Controller
{
/**
@@ -57,8 +61,8 @@ class ComponentController extends Controller
];
View::share([
'sub_menu' => $this->subMenu,
'sub_title' => trans_choice('dashboard.components.components', 2),
'subMenu' => $this->subMenu,
'subTitle' => trans_choice('dashboard.components.components', 2),
]);
}
@@ -79,21 +83,6 @@ class ComponentController extends Controller
->withSubMenu($this->subMenu);
}
/**
* Shows the component groups view.
*
* @return \Illuminate\View\View
*/
public function showComponentGroups()
{
$this->subMenu['groups']['active'] = true;
return View::make('dashboard.components.groups.index')
->withPageTitle(trans_choice('dashboard.components.groups.groups', 2).' - '.trans('dashboard.dashboard'))
->withGroups(ComponentGroup::orderBy('order')->get())
->withSubMenu($this->subMenu);
}
/**
* Shows the edit component view.
*
@@ -126,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'],
@@ -145,15 +134,16 @@ class ComponentController extends Controller
->withErrors($e->getMessageBag());
}
$component->tags()->delete();
// The component was added successfully, so now let's deal with the tags.
$tags = preg_split('/ ?, ?/', $tags);
// For every tag, do we need to create it?
$componentTags = array_map(function ($taggable) {
return Tag::firstOrCreate(['name' => $taggable])->id;
}, $tags);
$component->tags()->sync($componentTags);
Collection::make(preg_split('/ ?, ?/', $tags))->map(function ($tag) {
return trim($tag);
})->map(function ($tag) {
return execute(new CreateTagCommand($tag));
})->each(function ($tag) use ($component) {
execute(new ApplyTagCommand($component, $tag));
});
return cachet_redirect('dashboard.components.edit', [$component->id])
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.components.edit.success')));
@@ -182,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'],
@@ -200,14 +190,13 @@ class ComponentController extends Controller
}
// The component was added successfully, so now let's deal with the tags.
$tags = preg_split('/ ?, ?/', $tags);
// For every tag, do we need to create it?
$componentTags = array_map(function ($taggable) {
return Tag::firstOrCreate(['name' => $taggable])->id;
}, $tags);
$component->tags()->sync($componentTags);
Collection::make(preg_split('/ ?, ?/', $tags))->map(function ($tag) {
return trim($tag);
})->map(function ($tag) {
return execute(new CreateTagCommand($tag));
})->each(function ($tag) use ($component) {
execute(new ApplyTagCommand($component, $tag));
});
return cachet_redirect('dashboard.components')
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.components.add.success')));
@@ -222,102 +211,9 @@ 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')));
}
/**
* Deletes a given component group.
*
* @param \CachetHQ\Cachet\Models\ComponentGroup $group
*
* @return \Illuminate\Http\RedirectResponse
*/
public function deleteComponentGroupAction(ComponentGroup $group)
{
dispatch(new RemoveComponentGroupCommand($group));
return cachet_redirect('dashboard.components.groups')
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.components.delete.success')));
}
/**
* Shows the add component group view.
*
* @return \Illuminate\View\View
*/
public function showAddComponentGroup()
{
return View::make('dashboard.components.groups.add')
->withPageTitle(trans('dashboard.components.groups.add.title').' - '.trans('dashboard.dashboard'));
}
/**
* Shows the edit component group view.
*
* @param \CachetHQ\Cachet\Models\ComponentGroup $group
*
* @return \Illuminate\View\View
*/
public function showEditComponentGroup(ComponentGroup $group)
{
return View::make('dashboard.components.groups.edit')
->withPageTitle(trans('dashboard.components.groups.edit.title').' - '.trans('dashboard.dashboard'))
->withGroup($group);
}
/**
* Creates a new component.
*
* @return \Illuminate\Http\RedirectResponse
*/
public function postAddComponentGroup()
{
try {
$group = dispatch(new CreateComponentGroupCommand(
Binput::get('name'),
Binput::get('order', 0),
Binput::get('collapsed'),
Binput::get('visible')
));
} catch (ValidationException $e) {
return cachet_redirect('dashboard.components.groups.create')
->withInput(Binput::all())
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.components.groups.add.failure')))
->withErrors($e->getMessageBag());
}
return cachet_redirect('dashboard.components.groups')
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.components.groups.add.success')));
}
/**
* Updates a component group.
*
* @param \CachetHQ\Cachet\Models\ComponentGroup $group
*
* @return \Illuminate\Http\RedirectResponse
*/
public function updateComponentGroupAction(ComponentGroup $group)
{
try {
$group = dispatch(new UpdateComponentGroupCommand(
$group,
Binput::get('name'),
$group->order,
Binput::get('collapsed'),
Binput::get('visible')
));
} catch (ValidationException $e) {
return cachet_redirect('dashboard.components.groups.edit', [$group->id])
->withInput(Binput::all())
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.components.groups.edit.failure')))
->withErrors($e->getMessageBag());
}
return cachet_redirect('dashboard.components.groups.edit', [$group->id])
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.components.groups.edit.success')));
}
}
@@ -0,0 +1,173 @@
<?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\Http\Controllers\Dashboard;
use AltThree\Validator\ValidationException;
use CachetHQ\Cachet\Bus\Commands\ComponentGroup\CreateComponentGroupCommand;
use CachetHQ\Cachet\Bus\Commands\ComponentGroup\RemoveComponentGroupCommand;
use CachetHQ\Cachet\Bus\Commands\ComponentGroup\UpdateComponentGroupCommand;
use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\ComponentGroup;
use GrahamCampbell\Binput\Facades\Binput;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\View;
/**
* This is the component group controller class.
*
* @author James Brooks <james@bluebaytravel.co.uk>
*/
class ComponentGroupController extends Controller
{
/**
* Array of sub-menu items.
*
* @var array
*/
protected $subMenu = [];
/**
* Creates a new component controller instance.
*
* @return void
*/
public function __construct()
{
$this->subMenu = [
'components' => [
'title' => trans('dashboard.components.components'),
'url' => cachet_route('dashboard.components'),
'icon' => 'ion-ios-browsers',
'active' => false,
],
'groups' => [
'title' => trans_choice('dashboard.components.groups.groups', 2),
'url' => cachet_route('dashboard.components.groups'),
'icon' => 'ion-folder',
'active' => false,
],
];
View::share([
'sub_menu' => $this->subMenu,
'subTitle' => trans_choice('dashboard.components.components', 2),
]);
}
/**
* Shows the component groups view.
*
* @return \Illuminate\View\View
*/
public function showComponentGroups()
{
$this->subMenu['groups']['active'] = true;
return View::make('dashboard.components.groups.index')
->withPageTitle(trans_choice('dashboard.components.groups.groups', 2).' - '.trans('dashboard.dashboard'))
->withGroups(ComponentGroup::orderBy('order')->get())
->withSubMenu($this->subMenu);
}
/**
* Deletes a given component group.
*
* @param \CachetHQ\Cachet\Models\ComponentGroup $group
*
* @return \Illuminate\Http\RedirectResponse
*/
public function deleteComponentGroupAction(ComponentGroup $group)
{
execute(new RemoveComponentGroupCommand($group));
return cachet_redirect('dashboard.components.groups')
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.components.delete.success')));
}
/**
* Shows the add component group view.
*
* @return \Illuminate\View\View
*/
public function showAddComponentGroup()
{
return View::make('dashboard.components.groups.add')
->withPageTitle(trans('dashboard.components.groups.add.title').' - '.trans('dashboard.dashboard'));
}
/**
* Shows the edit component group view.
*
* @param \CachetHQ\Cachet\Models\ComponentGroup $group
*
* @return \Illuminate\View\View
*/
public function showEditComponentGroup(ComponentGroup $group)
{
return View::make('dashboard.components.groups.edit')
->withPageTitle(trans('dashboard.components.groups.edit.title').' - '.trans('dashboard.dashboard'))
->withGroup($group);
}
/**
* Creates a new component.
*
* @return \Illuminate\Http\RedirectResponse
*/
public function postAddComponentGroup()
{
try {
$group = execute(new CreateComponentGroupCommand(
Binput::get('name'),
Binput::get('order', 0),
Binput::get('collapsed'),
Binput::get('visible')
));
} catch (ValidationException $e) {
return cachet_redirect('dashboard.components.groups.create')
->withInput(Binput::all())
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.components.groups.add.failure')))
->withErrors($e->getMessageBag());
}
return cachet_redirect('dashboard.components.groups')
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.components.groups.add.success')));
}
/**
* Updates a component group.
*
* @param \CachetHQ\Cachet\Models\ComponentGroup $group
*
* @return \Illuminate\Http\RedirectResponse
*/
public function updateComponentGroupAction(ComponentGroup $group)
{
try {
$group = execute(new UpdateComponentGroupCommand(
$group,
Binput::get('name'),
$group->order,
Binput::get('collapsed'),
Binput::get('visible')
));
} catch (ValidationException $e) {
return cachet_redirect('dashboard.components.groups.edit', [$group->id])
->withInput(Binput::all())
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.components.groups.edit.failure')))
->withErrors($e->getMessageBag());
}
return cachet_redirect('dashboard.components.groups.edit', [$group->id])
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.components.groups.edit.success')));
}
}
@@ -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;
@@ -15,14 +15,11 @@ use AltThree\Validator\ValidationException;
use CachetHQ\Cachet\Bus\Commands\Incident\CreateIncidentCommand;
use CachetHQ\Cachet\Bus\Commands\Incident\RemoveIncidentCommand;
use CachetHQ\Cachet\Bus\Commands\Incident\UpdateIncidentCommand;
use CachetHQ\Cachet\Bus\Commands\IncidentUpdate\CreateIncidentUpdateCommand;
use CachetHQ\Cachet\Bus\Commands\IncidentUpdate\UpdateIncidentUpdateCommand;
use CachetHQ\Cachet\Integrations\Contracts\System;
use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\ComponentGroup;
use CachetHQ\Cachet\Models\Incident;
use CachetHQ\Cachet\Models\IncidentTemplate;
use CachetHQ\Cachet\Models\IncidentUpdate;
use GrahamCampbell\Binput\Facades\Binput;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Routing\Controller;
@@ -68,7 +65,7 @@ class IncidentController extends Controller
$this->auth = $auth;
$this->system = $system;
View::share('sub_title', trans('dashboard.incidents.title'));
View::share('subTitle', trans('dashboard.incidents.title'));
}
/**
@@ -120,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),
@@ -217,7 +214,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')));
@@ -250,7 +247,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'),
@@ -300,107 +297,4 @@ class IncidentController extends Controller
return cachet_redirect('dashboard.templates.edit', ['id' => $template->id])
->withUpdatedTemplate($template);
}
/**
* Shows the incident update form.
*
* @param \CachetHQ\Cachet\Models\Incident $incident
*
* @return \Illuminate\View\View
*/
public function showIncidentUpdates(Incident $incident)
{
return View::make('dashboard.incidents.updates.index')->withIncident($incident);
}
/**
* Shows the incident update form.
*
* @param \CachetHQ\Cachet\Models\Incident $incident
*
* @return \Illuminate\View\View
*/
public function showCreateIncidentUpdateAction(Incident $incident)
{
return View::make('dashboard.incidents.updates.add')
->withIncident($incident)
->withNotificationsEnabled($this->system->canNotifySubscribers());
}
/**
* Creates a new incident update.
*
* @param \CachetHQ\Cachet\Models\Incident $incident
*
* @return \Illuminate\Http\RedirectResponse
*/
public function createIncidentUpdateAction(Incident $incident)
{
try {
$incidentUpdate = dispatch(new CreateIncidentUpdateCommand(
$incident,
Binput::get('status'),
Binput::get('message'),
Binput::get('component_id'),
Binput::get('component_status'),
$this->auth->user()
));
} catch (ValidationException $e) {
return cachet_redirect('dashboard.incidents.updates.create', ['id' => $incident->id])
->withInput(Binput::all())
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.incidents.updates.add.failure')))
->withErrors($e->getMessageBag());
}
if ($incident->component) {
$incident->component->update(['status' => Binput::get('component_status')]);
}
return cachet_redirect('dashboard.incidents')
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.incidents.updates.success')));
}
/**
* Shows the edit incident view.
*
* @param \CachetHQ\Cachet\Models\Incident $incident
* @param \CachetHQ\Cachet\Models\IncidentUpdate $incidentUpdate
*
* @return \Illuminate\View\View
*/
public function showEditIncidentUpdateAction(Incident $incident, IncidentUpdate $incidentUpdate)
{
return View::make('dashboard.incidents.updates.edit')
->withIncident($incident)
->withUpdate($incidentUpdate)
->withNotificationsEnabled($this->system->canNotifySubscribers());
}
/**
* Edit an incident update.
*
* @param \CachetHQ\Cachet\Models\Incident $incident
* @param \CachetHQ\Cachet\Models\IncidentUpdate $incidentUpdate
*
* @return \Illuminate\Http\RedirectResponse
*/
public function editIncidentUpdateAction(Incident $incident, IncidentUpdate $incidentUpdate)
{
try {
$incidentUpdate = dispatch(new UpdateIncidentUpdateCommand(
$incidentUpdate,
Binput::get('status'),
Binput::get('message'),
$this->auth->user()
));
} catch (ValidationException $e) {
return cachet_redirect('dashboard.incidents.updates.edit', ['incident' => $incident->id, 'incident_update' => $incidentUpdate->id])
->withInput(Binput::all())
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.incidents.updates.edit.failure')))
->withErrors($e->getMessageBag());
}
return cachet_redirect('dashboard.incidents.updates', ['incident' => $incident->id])
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.incidents.updates.edit.success')));
}
}
@@ -0,0 +1,161 @@
<?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\Http\Controllers\Dashboard;
use AltThree\Validator\ValidationException;
use CachetHQ\Cachet\Integrations\Contracts\System;
use CachetHQ\Cachet\Models\Incident;
use CachetHQ\Cachet\Models\IncidentTemplate;
use GrahamCampbell\Binput\Facades\Binput;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\View;
/**
* This is the incident template controller.
*
* @author James Brooks <james@alt-three.com>
*/
class IncidentTemplateController extends Controller
{
/**
* Stores the sub-sidebar tree list.
*
* @var array
*/
protected $subMenu = [];
/**
* The guard instance.
*
* @var \Illuminate\Contracts\Auth\Guard
*/
protected $auth;
/**
* The system instance.
*
* @var \CachetHQ\Cachet\Integrations\Contracts\System
*/
protected $system;
/**
* Creates a new incident controller instance.
*
* @param \Illuminate\Contracts\Auth\Guard $auth
*
* @return void
*/
public function __construct(Guard $auth, System $system)
{
$this->auth = $auth;
$this->system = $system;
View::share('sub_title', trans('dashboard.incidents.title'));
}
/**
* Shows the incident templates.
*
* @return \Illuminate\View\View
*/
public function showTemplates()
{
return View::make('dashboard.templates.index')
->withPageTitle(trans('dashboard.incidents.templates.title').' - '.trans('dashboard.dashboard'))
->withIncidentTemplates(IncidentTemplate::all());
}
/**
* Shows the add incident template view.
*
* @return \Illuminate\View\View
*/
public function showAddIncidentTemplate()
{
return View::make('dashboard.templates.add')
->withPageTitle(trans('dashboard.incidents.templates.add.title').' - '.trans('dashboard.dashboard'));
}
/**
* Shows the edit incident template view.
*
* @param \CachetHQ\Cachet\Models\IncidentTemplate $template
*
* @return \Illuminate\View\View
*/
public function showEditTemplateAction(IncidentTemplate $template)
{
return View::make('dashboard.templates.edit')
->withPageTitle(trans('dashboard.incidents.templates.edit.title').' - '.trans('dashboard.dashboard'))
->withTemplate($template);
}
/**
* Deletes an incident template.
*
* @param \CachetHQ\Cachet\Models\IncidentTemplate $template
*
* @return \Illuminate\Http\RedirectResponse
*/
public function deleteTemplateAction(IncidentTemplate $template)
{
$template->delete();
return cachet_redirect('dashboard.templates')
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.incidents.templates.delete.success')));
}
/**
* Creates a new incident template.
*
* @return \Illuminate\Http\RedirectResponse
*/
public function createIncidentTemplateAction()
{
try {
IncidentTemplate::create([
'name' => Binput::get('name'),
'template' => Binput::get('template', null, false, false),
]);
} catch (ValidationException $e) {
return cachet_redirect('dashboard.templates.create')
->withInput(Binput::all())
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.incidents.templates.add.failure')))
->withErrors($e->getMessageBag());
}
return cachet_redirect('dashboard.templates')
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.incidents.templates.add.success')));
}
/**
* Edit an incident template.
*
* @param \CachetHQ\Cachet\Models\IncidentTemplate $template
*
* @return \Illuminate\Http\RedirectResponse
*/
public function editTemplateAction(IncidentTemplate $template)
{
try {
$template->update(Binput::get('template'));
} catch (ValidationException $e) {
return cachet_redirect('dashboard.templates.edit', ['id' => $template->id])
->withUpdatedTemplate($template)
->withTemplateErrors($e->getMessageBag()->getErrors());
}
return cachet_redirect('dashboard.templates.edit', ['id' => $template->id])
->withUpdatedTemplate($template);
}
}
@@ -0,0 +1,170 @@
<?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\Http\Controllers\Dashboard;
use AltThree\Validator\ValidationException;
use CachetHQ\Cachet\Bus\Commands\IncidentUpdate\CreateIncidentUpdateCommand;
use CachetHQ\Cachet\Bus\Commands\IncidentUpdate\UpdateIncidentUpdateCommand;
use CachetHQ\Cachet\Integrations\Contracts\System;
use CachetHQ\Cachet\Models\Incident;
use CachetHQ\Cachet\Models\IncidentUpdate;
use GrahamCampbell\Binput\Facades\Binput;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\View;
/**
* This is the incident update controller.
*
* @author James Brooks <james@alt-three.com>
*/
class IncidentUpdateController extends Controller
{
/**
* Stores the sub-sidebar tree list.
*
* @var array
*/
protected $subMenu = [];
/**
* The guard instance.
*
* @var \Illuminate\Contracts\Auth\Guard
*/
protected $auth;
/**
* The system instance.
*
* @var \CachetHQ\Cachet\Integrations\Contracts\System
*/
protected $system;
/**
* Creates a new incident controller instance.
*
* @param \Illuminate\Contracts\Auth\Guard $auth
*
* @return void
*/
public function __construct(Guard $auth, System $system)
{
$this->auth = $auth;
$this->system = $system;
View::share('sub_title', trans('dashboard.incidents.title'));
}
/**
* Shows the incident update form.
*
* @param \CachetHQ\Cachet\Models\Incident $incident
*
* @return \Illuminate\View\View
*/
public function showIncidentUpdates(Incident $incident)
{
return View::make('dashboard.incidents.updates.index')->withIncident($incident);
}
/**
* Shows the incident update form.
*
* @param \CachetHQ\Cachet\Models\Incident $incident
*
* @return \Illuminate\View\View
*/
public function showCreateIncidentUpdateAction(Incident $incident)
{
return View::make('dashboard.incidents.updates.add')
->withIncident($incident)
->withNotificationsEnabled($this->system->canNotifySubscribers());
}
/**
* Creates a new incident update.
*
* @param \CachetHQ\Cachet\Models\Incident $incident
*
* @return \Illuminate\Http\RedirectResponse
*/
public function createIncidentUpdateAction(Incident $incident)
{
try {
$incidentUpdate = execute(new CreateIncidentUpdateCommand(
$incident,
Binput::get('status'),
Binput::get('message'),
Binput::get('component_id'),
Binput::get('component_status'),
$this->auth->user()
));
} catch (ValidationException $e) {
return cachet_redirect('dashboard.incidents.updates.create', ['id' => $incident->id])
->withInput(Binput::all())
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.incidents.updates.add.failure')))
->withErrors($e->getMessageBag());
}
if ($incident->component) {
$incident->component->update(['status' => Binput::get('component_status')]);
}
return cachet_redirect('dashboard.incidents')
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.incidents.updates.success')));
}
/**
* Shows the edit incident view.
*
* @param \CachetHQ\Cachet\Models\Incident $incident
* @param \CachetHQ\Cachet\Models\IncidentUpdate $incidentUpdate
*
* @return \Illuminate\View\View
*/
public function showEditIncidentUpdateAction(Incident $incident, IncidentUpdate $incidentUpdate)
{
return View::make('dashboard.incidents.updates.edit')
->withIncident($incident)
->withUpdate($incidentUpdate)
->withNotificationsEnabled($this->system->canNotifySubscribers());
}
/**
* Edit an incident update.
*
* @param \CachetHQ\Cachet\Models\Incident $incident
* @param \CachetHQ\Cachet\Models\IncidentUpdate $incidentUpdate
*
* @return \Illuminate\Http\RedirectResponse
*/
public function editIncidentUpdateAction(Incident $incident, IncidentUpdate $incidentUpdate)
{
try {
$incidentUpdate = execute(new UpdateIncidentUpdateCommand(
$incidentUpdate,
Binput::get('status'),
Binput::get('message'),
$this->auth->user()
));
} catch (ValidationException $e) {
return cachet_redirect('dashboard.incidents.updates.edit', ['incident' => $incident->id, 'incident_update' => $incidentUpdate->id])
->withInput(Binput::all())
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.incidents.updates.edit.failure')))
->withErrors($e->getMessageBag());
}
return cachet_redirect('dashboard.incidents.updates', ['incident' => $incident->id])
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.incidents.updates.edit.success')));
}
}
@@ -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),
@@ -42,7 +42,7 @@ class ScheduleController extends Controller
*/
public function __construct()
{
View::share('sub_title', trans('dashboard.schedule.title'));
View::share('subTitle', trans('dashboard.schedule.title'));
}
/**
@@ -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')));
@@ -18,11 +18,12 @@ use CachetHQ\Cachet\Notifications\System\SystemTestNotification;
use CachetHQ\Cachet\Settings\Repository;
use Exception;
use GrahamCampbell\Binput\Facades\Binput;
use Illuminate\Log\Writer;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Lang;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\View;
@@ -115,8 +116,8 @@ class SettingsController extends Controller
];
View::share([
'sub_title' => trans('dashboard.settings.settings'),
'sub_menu' => $this->subMenu,
'subTitle' => trans('dashboard.settings.settings'),
'subMenu' => $this->subMenu,
]);
}
@@ -269,7 +270,7 @@ class SettingsController extends Controller
{
$this->subMenu['log']['active'] = true;
$log = app(Writer::class)->getMonolog();
$log = Log::getLogger();
$logContents = '';
@@ -318,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())
@@ -356,6 +357,14 @@ class SettingsController extends Controller
}
}
if (isset($parameters['stylesheet'])) {
if ($stylesheet = Binput::get('stylesheet', null, false, false)) {
$setting->set('stylesheet', $stylesheet);
} else {
$setting->delete('stylesheet');
}
}
if (Binput::hasFile('app_banner')) {
$this->handleUpdateBanner($setting);
}
@@ -366,6 +375,7 @@ class SettingsController extends Controller
'remove_banner',
'header',
'footer',
'stylesheet',
];
try {
@@ -384,6 +394,10 @@ class SettingsController extends Controller
Lang::setLocale(Binput::get('app_locale'));
}
if (Binput::has('always_authenticate')) {
Artisan::call('route:clear');
}
return Redirect::back()->withSuccess(trans('dashboard.settings.edit.success'));
}
@@ -397,6 +411,7 @@ class SettingsController extends Controller
protected function handleUpdateBanner(Repository $setting)
{
$file = Binput::file('app_banner');
$redirectUrl = $this->subMenu['theme']['url'];
// Image Validation.
// Image size in bytes.
@@ -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');
}
@@ -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')));
+8 -2
View File
@@ -17,6 +17,7 @@ use GrahamCampbell\Markdown\Facades\Markdown;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Str;
use McCool\LaravelAutoPresenter\Facades\AutoPresenter;
/**
* This is the feed controller.
@@ -106,12 +107,17 @@ class FeedController extends Controller
*/
private function feedAddItem(Incident $incident, $isRss)
{
$incident = AutoPresenter::decorate($incident);
$this->feed->add(
$incident->name,
Config::get('setting.app_name'),
Str::canonicalize(cachet_route('incident', [$incident->id])),
$isRss ? $incident->occurred_at->toRssString() : $incident->occurred_at->toAtomString(),
$isRss ? $incident->message : Markdown::convertToHtml($incident->message)
$isRss ? $incident->getWrappedObject()->occurred_at->toRssString() : $incident->getWrappedObject()->occurred_at->toAtomString(),
$isRss ? $incident->message : Markdown::convertToHtml($incident->message),
null,
[],
$isRss ? $incident->human_status : null
);
}
}
+1 -1
View File
@@ -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]);
+2 -2
View File
@@ -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('<strong>%s</strong> %s', trans('dashboard.notifications.awesome'), trans('cachet.signup.success')));
+25 -43
View File
@@ -19,7 +19,6 @@ use CachetHQ\Cachet\Models\Metric;
use CachetHQ\Cachet\Models\Schedule;
use CachetHQ\Cachet\Repositories\Metric\MetricRepository;
use CachetHQ\Cachet\Services\Dates\DateFactory;
use Exception;
use GrahamCampbell\Binput\Facades\Binput;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Auth;
@@ -45,32 +44,34 @@ class StatusPageController extends AbstractApiController
*/
public function showIndex()
{
$only_disrupted_days = Config::get('setting.only_disrupted_days');
$onlyDisruptedDays = Config::get('setting.only_disrupted_days');
$appIncidentDays = (int) Config::get('setting.app_incident_days', 1);
// Used for the database query
$startDate = Date::now();
$endDate = Date::now();
$startDate = Date::createFromFormat('Y-m-d', Binput::get('start_date', Date::now()->toDateString()));
$endDate = $startDate->copy()->subDays($appIncidentDays);
$canPageForward = false;
$canPageBackward = false;
$previousDate = null;
$nextDate = null;
if ($only_disrupted_days) {
if ($onlyDisruptedDays) {
// In this case, start_date GET parameter means the page
$page = Binput::get('start_date', 0);
if (!is_numeric($page)) {
$page = 0;
}
$page = (int) $page;
$page = (int) Binput::get('start_date', 0);
$allIncidentDays = Incident::where('visible', '>=', (int) !Auth::check())
->select('occurred_at')->distinct()->orderBy('occurred_at', 'desc')->get()->map(function (Incident $incident) {
return app(DateFactory::class)->make($incident->occurred_at)->toDateString();
})->unique()->values();
->select('occurred_at')
->whereBetween('occurred_at', [
$endDate->format('Y-m-d').' 00:00:00',
$startDate->format('Y-m-d').' 23:59:59',
])
->distinct()
->orderBy('occurred_at', 'desc')
->get()
->map(function (Incident $incident) {
return app(DateFactory::class)->make($incident->occurred_at)->toDateString();
})->unique()
->values();
$numIncidentDays = count($allIncidentDays);
$numPages = round($numIncidentDays / $appIncidentDays);
@@ -78,8 +79,8 @@ class StatusPageController extends AbstractApiController
$selectedDays = $allIncidentDays->slice($page * $appIncidentDays, $appIncidentDays)->all();
if (count($selectedDays) > 0) {
$startDate = Date::createFromFormat('Y-m-d', array_values(array_slice($selectedDays, -1))[0]);
$endDate = Date::createFromFormat('Y-m-d', array_values($selectedDays)[0]);
$startDate = Date::createFromFormat('Y-m-d', array_values($selectedDays)[0]);
$endDate = Date::createFromFormat('Y-m-d', array_values(array_slice($selectedDays, -1))[0]);
}
$canPageForward = $page > 0;
@@ -87,41 +88,22 @@ class StatusPageController extends AbstractApiController
$previousDate = $page + 1;
$nextDate = $page - 1;
} else {
$today = Date::now();
$date = Date::now();
// Check if we have another starting date
if (Binput::has('start_date')) {
try {
// If date provided is valid
$oldDate = Date::createFromFormat('Y-m-d', Binput::get('start_date'));
// If trying to get a future date fallback to today
if ($today->gt($oldDate)) {
$date = $oldDate;
}
} catch (Exception $e) {
// Fallback to today
}
}
$startDate = $date->copy()->subDays($appIncidentDays);
$endDate = $date->copy();
$canPageForward = (bool) $today->gt($date);
$canPageForward = (bool) $startDate->lt($date->sub('1 day'));
$canPageBackward = Incident::where('occurred_at', '<', $date->format('Y-m-d'))->count() > 0;
$previousDate = $date->copy()->subDays($appIncidentDays)->toDateString();
$nextDate = $date->copy()->addDays($appIncidentDays)->toDateString();
$previousDate = $startDate->copy()->subDays($appIncidentDays)->toDateString();
$nextDate = $startDate->copy()->addDays($appIncidentDays)->toDateString();
}
$allIncidents = Incident::where('visible', '>=', (int) !Auth::check())->whereBetween('occurred_at', [
$startDate->format('Y-m-d').' 00:00:00',
$endDate->format('Y-m-d').' 23:59:59',
$endDate->format('Y-m-d').' 00:00:00',
$startDate->format('Y-m-d').' 23:59:59',
])->orderBy('occurred_at', 'desc')->get()->groupBy(function (Incident $incident) {
return app(DateFactory::class)->make($incident->occurred_at)->toDateString();
});
if (!$only_disrupted_days) {
if (!$onlyDisruptedDays) {
$incidentDays = array_pad([], $appIncidentDays, null);
// Add in days that have no incidents
+5 -5
View File
@@ -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())