2014-12-20 18:53:52 +00:00
|
|
|
<?php
|
|
|
|
|
2015-04-19 08:52:39 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Cachet.
|
|
|
|
*
|
2015-07-06 17:37:01 +01:00
|
|
|
* (c) Alt Three Services Limited
|
2015-04-19 08:52:39 +01:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2015-03-20 18:30:45 -06:00
|
|
|
namespace CachetHQ\Cachet\Http\Controllers\Admin;
|
2015-01-01 15:45:04 +00:00
|
|
|
|
2015-05-24 16:33:03 -05:00
|
|
|
use CachetHQ\Cachet\Events\IncidentHasReportedEvent;
|
2015-05-19 17:40:04 +01:00
|
|
|
use CachetHQ\Cachet\Facades\Setting;
|
2015-03-21 02:21:20 -06:00
|
|
|
use CachetHQ\Cachet\Http\Controllers\AbstractController;
|
2015-01-06 11:43:32 +00:00
|
|
|
use CachetHQ\Cachet\Models\Component;
|
2015-03-26 15:07:16 -06:00
|
|
|
use CachetHQ\Cachet\Models\ComponentGroup;
|
2015-01-02 00:18:19 +00:00
|
|
|
use CachetHQ\Cachet\Models\Incident;
|
|
|
|
use CachetHQ\Cachet\Models\IncidentTemplate;
|
2015-01-02 12:05:50 +00:00
|
|
|
use GrahamCampbell\Binput\Facades\Binput;
|
2015-05-19 17:40:04 +01:00
|
|
|
use Illuminate\Support\Facades\Config;
|
2015-01-01 15:45:04 +00:00
|
|
|
use Illuminate\Support\Facades\Redirect;
|
|
|
|
use Illuminate\Support\Facades\View;
|
2015-05-19 17:40:04 +01:00
|
|
|
use Jenssegers\Date\Date;
|
2015-01-01 15:45:04 +00:00
|
|
|
|
2015-03-21 02:21:20 -06:00
|
|
|
class IncidentController extends AbstractController
|
2014-12-20 21:20:17 +00:00
|
|
|
{
|
2015-02-28 20:18:30 +00:00
|
|
|
/**
|
|
|
|
* Stores the sub-sidebar tree list.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $subMenu = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new DashIncidentController instance.
|
|
|
|
*
|
|
|
|
* @return \CachetHQ\Cachet\Http\Controllers\DashScheduleController
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->subMenu = [
|
|
|
|
'incidents' => [
|
|
|
|
'title' => trans('dashboard.incidents.incidents'),
|
|
|
|
'url' => route('dashboard.incidents'),
|
|
|
|
'icon' => 'ion-android-checkmark-circle',
|
|
|
|
'active' => true,
|
|
|
|
],
|
2015-06-16 09:07:49 +01:00
|
|
|
'schedule' => [
|
2015-02-28 20:18:30 +00:00
|
|
|
'title' => trans('dashboard.schedule.schedule'),
|
|
|
|
'url' => route('dashboard.schedule'),
|
|
|
|
'icon' => 'ion-android-calendar',
|
|
|
|
'active' => false,
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
2015-07-02 16:37:38 +01:00
|
|
|
View::share('sub_menu', $this->subMenu);
|
|
|
|
View::share('sub_title', trans('dashboard.incidents.title'));
|
2015-02-28 20:18:30 +00:00
|
|
|
}
|
|
|
|
|
2014-12-20 21:20:17 +00:00
|
|
|
/**
|
|
|
|
* Shows the incidents view.
|
2014-12-29 23:07:46 +00:00
|
|
|
*
|
2014-12-20 21:20:17 +00:00
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function showIncidents()
|
|
|
|
{
|
2015-02-28 20:18:30 +00:00
|
|
|
$incidents = Incident::notScheduled()->orderBy('created_at', 'desc')->get();
|
2014-12-20 21:20:17 +00:00
|
|
|
|
2015-01-01 10:39:22 +00:00
|
|
|
return View::make('dashboard.incidents.index')->with([
|
2015-07-02 16:40:38 +01:00
|
|
|
'page_title' => trans('dashboard.incidents.incidents').' - '.trans('dashboard.dashboard'),
|
2015-07-02 16:46:14 +01:00
|
|
|
'incidents' => $incidents,
|
2014-12-20 21:20:17 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows the add incident view.
|
2014-12-29 23:07:46 +00:00
|
|
|
*
|
2014-12-20 21:20:17 +00:00
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function showAddIncident()
|
|
|
|
{
|
2015-03-26 15:07:16 -06:00
|
|
|
$componentsInGroups = ComponentGroup::with('components')->get();
|
|
|
|
$componentsOutGroups = Component::where('group_id', 0)->get();
|
|
|
|
|
2015-01-01 10:39:22 +00:00
|
|
|
return View::make('dashboard.incidents.add')->with([
|
2015-07-02 16:46:14 +01:00
|
|
|
'page_title' => trans('dashboard.incidents.add.title').' - '.trans('dashboard.dashboard'),
|
2015-03-26 15:07:16 -06:00
|
|
|
'componentsInGroups' => $componentsInGroups,
|
|
|
|
'componentsOutGroups' => $componentsOutGroups,
|
|
|
|
'incidentTemplates' => IncidentTemplate::all(),
|
2015-01-08 08:58:09 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows the incident templates.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function showTemplates()
|
|
|
|
{
|
|
|
|
return View::make('dashboard.incidents.templates.index')->with([
|
2015-07-02 16:46:14 +01:00
|
|
|
'page_title' => trans('dashboard.incidents.templates.title').' - '.trans('dashboard.dashboard'),
|
2015-01-08 08:58:09 +00:00
|
|
|
'incidentTemplates' => IncidentTemplate::all(),
|
2014-12-20 21:20:17 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2015-01-09 20:21:29 -06:00
|
|
|
/**
|
|
|
|
* Creates a new incident.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function createIncidentAction()
|
|
|
|
{
|
2015-01-06 11:43:32 +00:00
|
|
|
$incidentData = Binput::get('incident');
|
|
|
|
$componentStatus = array_pull($incidentData, 'component_status');
|
2015-03-06 08:34:47 +00:00
|
|
|
|
2015-05-20 08:18:48 +01:00
|
|
|
if (array_has($incidentData, 'created_at') && $incidentData['created_at']) {
|
2015-05-19 17:40:04 +01:00
|
|
|
$incidentDate = Date::createFromFormat('d/m/Y H:i', $incidentData['created_at'], Setting::get('app_timezone'))->setTimezone(Config::get('app.timezone'));
|
|
|
|
$incidentData['created_at'] = $incidentDate;
|
|
|
|
$incidentData['updated_at'] = $incidentDate;
|
2015-05-20 08:18:48 +01:00
|
|
|
} else {
|
|
|
|
unset($incidentData['created_at']);
|
2015-05-19 17:40:04 +01:00
|
|
|
}
|
|
|
|
|
2015-01-06 11:43:32 +00:00
|
|
|
$incident = Incident::create($incidentData);
|
2015-01-09 20:21:29 -06:00
|
|
|
|
2015-04-19 08:52:39 +01:00
|
|
|
if (!$incident->isValid()) {
|
2015-01-09 20:21:29 -06:00
|
|
|
return Redirect::back()->withInput(Binput::all())
|
2015-01-14 16:05:51 +00:00
|
|
|
->with('title', sprintf(
|
2015-06-15 20:30:35 +01:00
|
|
|
'%s %s',
|
2015-01-14 16:05:51 +00:00
|
|
|
trans('dashboard.notifications.whoops'),
|
|
|
|
trans('dashboard.incidents.add.failure')
|
|
|
|
))
|
2015-01-09 20:21:29 -06:00
|
|
|
->with('errors', $incident->getErrors());
|
|
|
|
}
|
|
|
|
|
2015-01-06 11:43:32 +00:00
|
|
|
// Update the component.
|
2015-01-23 17:38:52 +00:00
|
|
|
if (isset($incidentData['component_id']) && (int) $incidentData['component_id'] > 0) {
|
2015-01-06 11:43:32 +00:00
|
|
|
Component::find($incidentData['component_id'])->update([
|
|
|
|
'status' => $componentStatus,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2015-01-14 16:05:51 +00:00
|
|
|
$successMsg = sprintf(
|
2015-06-15 20:30:35 +01:00
|
|
|
'%s %s',
|
2015-01-14 16:05:51 +00:00
|
|
|
trans('dashboard.notifications.awesome'),
|
|
|
|
trans('dashboard.incidents.add.success')
|
|
|
|
);
|
|
|
|
|
2015-06-18 16:24:10 +01:00
|
|
|
$isEnabled = (bool) Setting::get('enable_subscribers', false);
|
|
|
|
$mailAddress = env('MAIL_ADDRESS', false);
|
|
|
|
$mailFrom = env('MAIL_NAME', false);
|
|
|
|
$subscribersEnabled = $isEnabled && $mailAddress && $mailFrom;
|
|
|
|
|
|
|
|
if (array_get($incidentData, 'notify') && $subscribersEnabled) {
|
2015-05-24 16:33:03 -05:00
|
|
|
event(new IncidentHasReportedEvent($incident));
|
|
|
|
}
|
|
|
|
|
2015-01-14 16:05:51 +00:00
|
|
|
return Redirect::back()->with('success', $successMsg);
|
2015-01-09 20:21:29 -06:00
|
|
|
}
|
|
|
|
|
2014-12-20 21:20:17 +00:00
|
|
|
/**
|
|
|
|
* Shows the add incident template view.
|
2014-12-29 23:07:46 +00:00
|
|
|
*
|
2014-12-20 21:20:17 +00:00
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function showAddIncidentTemplate()
|
|
|
|
{
|
2015-01-05 11:12:34 +00:00
|
|
|
return View::make('dashboard.incidents.templates.add')->with([
|
2015-07-02 16:40:38 +01:00
|
|
|
'page_title' => trans('dashboard.incidents.templates.add.title').' - '.trans('dashboard.dashboard'),
|
2014-12-20 21:20:17 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2015-01-08 08:58:09 +00:00
|
|
|
/**
|
|
|
|
* 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.incidents.templates.edit')->with([
|
2015-07-02 16:40:38 +01:00
|
|
|
'page_title' => trans('dashboard.incidents.templates.edit.title').' - '.trans('dashboard.dashboard'),
|
2015-07-02 16:46:14 +01:00
|
|
|
'template' => $template,
|
2015-01-08 08:58:09 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes an incident template.
|
|
|
|
*
|
|
|
|
* @param \CachetHQ\Cachet\Models\IncidentTemplate $template
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function deleteTemplateAction(IncidentTemplate $template)
|
|
|
|
{
|
|
|
|
$template->delete();
|
|
|
|
|
|
|
|
return Redirect::back();
|
|
|
|
}
|
|
|
|
|
2014-12-20 21:20:17 +00:00
|
|
|
/**
|
|
|
|
* Creates a new incident template.
|
2014-12-29 23:07:46 +00:00
|
|
|
*
|
2014-12-20 21:20:17 +00:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function createIncidentTemplateAction()
|
|
|
|
{
|
2015-01-02 12:05:50 +00:00
|
|
|
$_template = Binput::get('template');
|
2014-12-20 21:20:17 +00:00
|
|
|
$template = IncidentTemplate::create($_template);
|
|
|
|
|
2015-04-19 08:52:39 +01:00
|
|
|
if (!$template->isValid()) {
|
2015-01-09 20:21:29 -06:00
|
|
|
return Redirect::back()->withInput(Binput::all())
|
2015-01-14 16:05:51 +00:00
|
|
|
->with('title', sprintf(
|
2015-06-15 20:30:35 +01:00
|
|
|
'%s %s',
|
2015-08-03 21:06:56 +01:00
|
|
|
trans('dashboard.notifications.whoops'),
|
2015-01-14 16:05:51 +00:00
|
|
|
trans('dashboard.incidents.templates.add.failure')
|
|
|
|
))
|
2015-01-09 20:21:29 -06:00
|
|
|
->with('errors', $template->getErrors());
|
|
|
|
}
|
2014-12-20 21:20:17 +00:00
|
|
|
|
2015-01-14 16:05:51 +00:00
|
|
|
$successMsg = sprintf(
|
2015-06-15 20:30:35 +01:00
|
|
|
'%s %s',
|
2015-01-14 16:05:51 +00:00
|
|
|
trans('dashboard.notifications.awesome'),
|
|
|
|
trans('dashboard.incidents.templates.add.success')
|
|
|
|
);
|
|
|
|
|
|
|
|
return Redirect::back()->with('success', $successMsg);
|
2014-12-20 21:20:17 +00:00
|
|
|
}
|
2014-12-22 12:55:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes a given incident.
|
2014-12-29 23:07:46 +00:00
|
|
|
*
|
2015-01-02 00:18:19 +00:00
|
|
|
* @param \CachetHQ\Cachet\Models\Incident $incident
|
2014-12-29 23:07:46 +00:00
|
|
|
*
|
2014-12-22 12:55:26 +00:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function deleteIncidentAction(Incident $incident)
|
|
|
|
{
|
|
|
|
$incident->delete();
|
|
|
|
|
|
|
|
return Redirect::back();
|
|
|
|
}
|
2015-01-02 20:35:02 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows the edit incident view.
|
|
|
|
*
|
|
|
|
* @param \CachetHQ\Cachet\Models\Incident $incident
|
|
|
|
*
|
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function showEditIncidentAction(Incident $incident)
|
|
|
|
{
|
2015-03-26 15:07:16 -06:00
|
|
|
$componentsInGroups = ComponentGroup::with('components')->get();
|
|
|
|
$componentsOutGroups = Component::where('group_id', 0)->get();
|
|
|
|
|
2015-01-02 20:35:02 +01:00
|
|
|
return View::make('dashboard.incidents.edit')->with([
|
2015-07-02 16:46:14 +01:00
|
|
|
'page_title' => trans('dashboard.incidents.edit.title').' - '.trans('dashboard.dashboard'),
|
2015-03-26 15:07:16 -06:00
|
|
|
'incident' => $incident,
|
|
|
|
'componentsInGroups' => $componentsInGroups,
|
|
|
|
'componentsOutGroups' => $componentsOutGroups,
|
2015-01-02 20:35:02 +01:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Edit an incident.
|
|
|
|
*
|
|
|
|
* @param \CachetHQ\Cachet\Models\Incident $incident
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function editIncidentAction(Incident $incident)
|
|
|
|
{
|
2015-03-06 08:34:47 +00:00
|
|
|
$incidentData = Binput::get('incident');
|
2015-05-19 17:40:04 +01:00
|
|
|
|
2015-05-20 08:18:48 +01:00
|
|
|
if (array_has($incidentData, 'created_at') && $incidentData['created_at']) {
|
2015-05-19 17:40:04 +01:00
|
|
|
$incidentDate = Date::createFromFormat('d/m/Y H:i', $incidentData['created_at'], Setting::get('app_timezone'))->setTimezone(Config::get('app.timezone'));
|
|
|
|
$incidentData['created_at'] = $incidentDate;
|
|
|
|
$incidentData['updated_at'] = $incidentDate;
|
2015-05-20 08:18:48 +01:00
|
|
|
} else {
|
|
|
|
unset($incidentData['created_at']);
|
2015-05-19 17:40:04 +01:00
|
|
|
}
|
|
|
|
|
2015-03-06 08:34:47 +00:00
|
|
|
$incident->update($incidentData);
|
2015-01-02 20:35:02 +01:00
|
|
|
|
2015-04-19 08:52:39 +01:00
|
|
|
if (!$incident->isValid()) {
|
2015-01-09 20:21:29 -06:00
|
|
|
return Redirect::back()->withInput(Binput::all())
|
2015-01-14 16:05:51 +00:00
|
|
|
->with('title', sprintf(
|
2015-06-15 20:30:35 +01:00
|
|
|
'%s %s',
|
2015-08-03 21:06:56 +01:00
|
|
|
trans('dashboard.notifications.whoops'),
|
2015-01-14 16:05:51 +00:00
|
|
|
trans('dashboard.incidents.templates.edit.failure')
|
|
|
|
))
|
2015-01-09 20:21:29 -06:00
|
|
|
->with('errors', $incident->getErrors());
|
|
|
|
}
|
|
|
|
|
2015-06-15 16:27:42 +01:00
|
|
|
$componentStatus = array_pull($incidentData, 'component_status');
|
|
|
|
if ($incident->component) {
|
|
|
|
$incident->component->update([
|
|
|
|
'status' => $componentStatus,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2015-01-14 16:05:51 +00:00
|
|
|
$successMsg = sprintf(
|
2015-06-15 20:30:35 +01:00
|
|
|
'%s %s',
|
2015-01-14 16:05:51 +00:00
|
|
|
trans('dashboard.notifications.awesome'),
|
|
|
|
trans('dashboard.incidents.edit.success')
|
|
|
|
);
|
|
|
|
|
|
|
|
return Redirect::to('dashboard/incidents')->with('success', $successMsg);
|
2015-01-02 20:35:02 +01:00
|
|
|
}
|
2015-01-08 08:58:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Edit an incident template.
|
|
|
|
*
|
|
|
|
* @param \CachetHQ\Cachet\Models\IncidentTemplate $template
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function editTemplateAction(IncidentTemplate $template)
|
|
|
|
{
|
|
|
|
$template->update(Binput::get('template'));
|
|
|
|
|
|
|
|
return Redirect::back()->with('updatedTemplate', $template);
|
|
|
|
}
|
2014-12-20 18:53:52 +00:00
|
|
|
}
|