ReportMaintenanceCommand is added

This commit is contained in:
James Brooks
2015-08-31 20:16:15 +01:00
parent 60e9a64a3e
commit 1478a25008
5 changed files with 123 additions and 57 deletions

View File

@@ -12,11 +12,12 @@
namespace CachetHQ\Cachet\Http\Controllers\Dashboard;
use AltThree\Validator\ValidationException;
use CachetHQ\Cachet\Events\MaintenanceWasScheduledEvent;
use CachetHQ\Cachet\Commands\Incident\ReportMaintenanceCommand;
use CachetHQ\Cachet\Facades\Setting;
use CachetHQ\Cachet\Models\Incident;
use CachetHQ\Cachet\Models\IncidentTemplate;
use GrahamCampbell\Binput\Facades\Binput;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Redirect;
@@ -26,6 +27,8 @@ use Jenssegers\Date\Date;
class ScheduleController extends Controller
{
use DispatchesJobs;
/**
* Stores the sub-sidebar tree list.
*
@@ -92,24 +95,13 @@ class ScheduleController extends Controller
*/
public function addScheduleAction()
{
$scheduleData = Binput::get('incident');
// Parse the schedule date.
$scheduledAt = Date::createFromFormat('d/m/Y H:i', $scheduleData['scheduled_at'], Setting::get('app_timezone'))
->setTimezone(Config::get('app.timezone'));
if ($scheduledAt->isPast()) {
$messageBag = new MessageBag();
$messageBag->add('scheduled_at', trans('validation.date', ['attribute' => 'scheduled time you supplied']));
return Redirect::route('dashboard.schedule.add')->withErrors($messageBag);
}
$scheduleData['scheduled_at'] = $scheduledAt;
// Bypass the incident.status field.
$scheduleData['status'] = 0;
try {
$incident = Incident::create($scheduleData);
$incident = $this->dispatch(new ReportMaintenanceCommand(
Binput::get('incident.name'),
Binput::get('incident.message'),
Binput::get('incident.notify'),
Binput::get('incident.scheduled_at')
));
} catch (ValidationException $e) {
return Redirect::route('dashboard.schedule.add')
->withInput(Binput::all())
@@ -117,10 +109,6 @@ class ScheduleController extends Controller
->withErrors($e->getMessageBag());
}
if (array_get($scheduleData, 'notify') && subscribers_enabled()) {
event(new MaintenanceWasScheduledEvent($incident));
}
return Redirect::route('dashboard.schedule.add')
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.schedule.add.success')));
}