Merge pull request #950 from cachethq/update-commands

Update commands
This commit is contained in:
James Brooks
2015-10-01 20:14:02 +01:00
32 changed files with 1109 additions and 86 deletions

View File

@@ -61,9 +61,12 @@ class AddComponentCommand
* @var string[]
*/
public $rules = [
'name' => 'required|string',
'status' => 'required|integer',
'link' => 'url',
'name' => 'required|string',
'description' => 'string',
'status' => 'required|integer',
'link' => 'url',
'order' => 'integer',
'group_id' => 'integer',
];
/**

View File

@@ -0,0 +1,104 @@
<?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\Commands\Component;
use CachetHQ\Cachet\Models\Component;
class UpdateComponentCommand
{
/**
* The component to update.
*
* @var \CachetHQ\Cachet\Models\Component
*/
public $component;
/**
* The component name.
*
* @var string
*/
public $name;
/**
* The component description.
*
* @var string
*/
public $description;
/**
* The component status.
*
* @var int
*/
public $status;
/**
* The component link.
*
* @var string
*/
public $link;
/**
* The component order.
*
* @var int
*/
public $order;
/**
* The component group.
*
* @var int
*/
public $group_id;
/**
* The validation rules.
*
* @var string[]
*/
public $rules = [
'name' => 'string',
'description' => 'string',
'status' => 'integer',
'link' => 'url',
'order' => 'integer',
'group_id' => 'integer',
];
/**
* Create a new update component command instance.
*
* @param \CachetHQ\Cachet\Models\Component $component
* @param string $name
* @param string $description
* @param int $status
* @param string $link
* @param int $order
* @param int $group_id
*
* @return void
*/
public function __construct(Component $component, $name, $description, $status, $link, $order, $group_id)
{
$this->component = $component;
$this->name = $name;
$this->description = $description;
$this->status = (int) $status;
$this->link = $link;
$this->order = $order;
$this->group_id = $group_id;
}
}

View File

@@ -0,0 +1,64 @@
<?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\Commands\ComponentGroup;
use CachetHQ\Cachet\Models\ComponentGroup;
class UpdateComponentGroupCommand
{
/**
* The component group.
*
* @var \CachetHQ\Cachet\Models\ComponentGroup
*/
public $group;
/**
* The component group name.
*
* @var string
*/
public $name;
/**
* The component group description.
*
* @var int
*/
public $order;
/**
* The validation rules.
*
* @var string[]
*/
public $rules = [
'name' => 'string',
'order' => 'integer',
];
/**
* Create a add component group command instance.
*
* @param \CachetHQ\Cachet\Models\ComponentGroup $group
* @param string $name
* @param int $order
*
* @return void
*/
public function __construct(ComponentGroup $group, $name, $order)
{
$this->group = $group;
$this->name = $name;
$this->order = (int) $order;
}
}

View File

@@ -62,20 +62,44 @@ class ReportIncidentCommand
*/
public $notify;
/**
* The date at which the incident occurred.
*
* @var string|null
*/
public $incident_date;
/**
* The validation rules.
*
* @var string[]
*/
public $rules = [
'name' => 'required|string',
'status' => 'required|integer',
'message' => 'string',
'visible' => 'boolean',
'component_id' => 'integer',
'component_status' => 'integer',
'notify' => 'boolean',
'incident_date' => 'string',
];
/**
* Create a new report incident command instance.
*
* @param string $name
* @param int $status
* @param string $message
* @param int $visible
* @param int $component_id
* @param int $component_status
* @param bool $notify
* @param string $name
* @param int $status
* @param string $message
* @param int $visible
* @param int $component_id
* @param int $component_status
* @param bool $notify
* @param string|null $incident_date
*
* @return void
*/
public function __construct($name, $status, $message, $visible, $component_id, $component_status, $notify)
public function __construct($name, $status, $message, $visible, $component_id, $component_status, $notify, $incident_date)
{
$this->name = $name;
$this->status = $status;
@@ -84,5 +108,6 @@ class ReportIncidentCommand
$this->component_id = $component_id;
$this->component_status = $component_status;
$this->notify = $notify;
$this->incident_date = $incident_date;
}
}

View File

@@ -41,6 +41,18 @@ class ReportMaintenanceCommand
*/
public $timestamp;
/**
* The validation rules.
*
* @var string[]
*/
public $rules = [
'name' => 'required|string',
'message' => 'string',
'notify' => 'boolean',
'timestamp' => 'string',
];
/**
* Create a new report maintenance command instance.
*

View File

@@ -0,0 +1,123 @@
<?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\Commands\Incident;
use CachetHQ\Cachet\Models\Incident;
class UpdateIncidentCommand
{
/**
* The incident to update.
*
* @var \CachetHQ\Cachet\Models\Incident
*/
public $incident;
/**
* The incident name.
*
* @var string
*/
public $name;
/**
* The incident status.
*
* @var int
*/
public $status;
/**
* The incident message.
*
* @var string
*/
public $message;
/**
* The incident visibility.
*
* @var int
*/
public $visible;
/**
* The incident component.
*
* @var int
*/
public $component_id;
/**
* The component status.
*
* @var int
*/
public $component_status;
/**
* Whether to notify about the incident or not.
*
* @var bool
*/
public $notify;
/**
* The date that the incident occurred on.
*
* @var string
*/
public $incident_date;
/**
* The validation rules.
*
* @var string[]
*/
public $rules = [
'name' => 'string',
'status' => 'integer',
'message' => 'string',
'visible' => 'boolean',
'component_id' => 'integer',
'component_status' => 'integer',
'notify' => 'boolean',
];
/**
* Create a new update incident command instance.
*
* @param \CachetHQ\Cachet\Models\Incident $name
* @param string $name
* @param int $status
* @param string $message
* @param int $visible
* @param int $component_id
* @param int $component_status
* @param bool $notify
* @param string|null $incident_date
*
* @return void
*/
public function __construct(Incident $incident, $name, $status, $message, $visible, $component_id, $component_status, $notify, $incident_date = null)
{
$this->incident = $incident;
$this->name = $name;
$this->status = $status;
$this->message = $message;
$this->visible = $visible;
$this->component_id = $component_id;
$this->component_status = $component_status;
$this->notify = $notify;
$this->incident_date = $incident_date;
}
}

View File

@@ -68,11 +68,14 @@ class AddMetricCommand
* @var string[]
*/
public $rules = [
'name' => 'required',
'suffix' => 'required',
'name' => 'required|string',
'suffix' => 'required|string',
'description' => 'string',
'display_chart' => 'boolean',
'default_value' => 'numeric',
'places' => 'numeric|min:0|max:4',
'default_value' => 'integer',
'calc_type' => 'integer',
'display_chart' => 'integer',
'places' => 'integer|between:0,4',
];
/**

View File

@@ -34,21 +34,31 @@ class AddMetricPointCommand
*
* @var string
*/
public $createdAt;
public $created_at;
/**
* The validation rules.
*
* @var string[]
*/
public $rules = [
'value' => 'integer',
'created_at' => 'string',
];
/**
* Create a new add metric point command instance.
*
* @param \CachetHQ\Cachet\Models\Metric $metric
* @param int $value
* @param string $createdAt
* @param string $created_at
*
* @return void
*/
public function __construct(Metric $metric, $value, $createdAt)
public function __construct(Metric $metric, $value, $created_at)
{
$this->metric = $metric;
$this->value = $value;
$this->createdAt = $createdAt;
$this->created_at = $created_at;
}
}

View File

@@ -0,0 +1,115 @@
<?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\Commands\Metric;
use CachetHQ\Cachet\Models\Metric;
class UpdateMetricCommand
{
/**
* The metric.
*
* @var \CachetHQ\Cachet\Models\Metric
*/
public $metric;
/**
* The metric name.
*
* @var string
*/
public $name;
/**
* The metric suffix.
*
* @var string
*/
public $suffix;
/**
* The metric description.
*
* @var string
*/
public $description;
/**
* The metric default value.
*
* @var float
*/
public $default_value;
/**
* The metric calculation type.
*
* @var int
*/
public $calc_type;
/**
* The metric display chart.
*
* @var int
*/
public $display_chart;
/**
* The metric decimal places.
*
* @var int
*/
public $places;
/**
* The validation rules.
*
* @var string[]
*/
public $rules = [
'name' => 'string',
'suffix' => 'string',
'description' => 'string',
'display_chart' => 'boolean',
'default_value' => 'numeric',
'calc_type' => 'integer|in:0,1',
'display_chart' => 'integer',
'places' => 'numeric|min:0|max:4',
];
/**
* Create a new update metric command instance.
*
* @param \CachetHQ\Cachet\Models\Metric $metric
* @param string $name
* @param string $suffix
* @param string $description
* @param float $default_value
* @param int $calc_type
* @param int $display_chart
* @param int $places
*
* @return void
*/
public function __construct(Metric $metric, $name, $suffix, $description, $default_value, $calc_type, $display_chart, $places)
{
$this->metric = $metric;
$this->name = $name;
$this->suffix = $suffix;
$this->description = $description;
$this->default_value = $default_value;
$this->calc_type = $calc_type;
$this->display_chart = $display_chart;
$this->places = $places;
}
}

View File

@@ -0,0 +1,74 @@
<?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\Commands\Metric;
use CachetHQ\Cachet\Models\Metric;
use CachetHQ\Cachet\Models\MetricPoint;
class UpdateMetricPointCommand
{
/**
* The metric point.
*
* @var \CachetHQ\Cachet\Models\MetricPoint
*/
public $point;
/**
* The metric.
*
* @var \CachetHQ\Cachet\Models\Metric
*/
public $metric;
/**
* The metric point value.
*
* @var int
*/
public $value;
/**
* The metric point created at.
*
* @var string
*/
public $created_at;
/**
* The validation rules.
*
* @var string[]
*/
public $rules = [
'value' => 'integer',
'created_at' => 'string',
];
/**
* Create a new update metric point command instance.
*
* @param \CachetHQ\Cachet\Models\MetricPoint $point
* @param \CachetHQ\Cachet\Models\Metric $metric
* @param int $value
* @param string $created_at
*
* @return void
*/
public function __construct(MetricPoint $point, Metric $metric, $value, $created_at)
{
$this->point = $point;
$this->metric = $metric;
$this->value = $value;
$this->created_at = $created_at;
}
}

View File

@@ -0,0 +1,34 @@
<?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\Events\Component;
use CachetHQ\Cachet\Models\Component;
class ComponentWasUpdatedEvent
{
/**
* The component that was updated.
*
* @var \CachetHQ\Cachet\Models\Component
*/
public $component;
/**
* Create a new component was updated event instance.
*
* @return void
*/
public function __construct(Component $component)
{
$this->component = $component;
}
}

View File

@@ -0,0 +1,34 @@
<?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\Events\ComponentGroup;
use CachetHQ\Cachet\Models\ComponentGroup;
class ComponentGroupWasUpdatedEvent
{
/**
* The component group that was updated.
*
* @var \CachetHQ\Cachet\Models\ComponentGroup
*/
public $group;
/**
* Create a new component group was updated event instance.
*
* @return void
*/
public function __construct(ComponentGroup $group)
{
$this->group = $group;
}
}

View File

@@ -0,0 +1,34 @@
<?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\Events\Incident;
use CachetHQ\Cachet\Models\Incident;
class IncidentWasUpdatedEvent
{
/**
* The incident that has been updated.
*
* @var \CachetHQ\Cachet\Models\Incident
*/
public $incident;
/**
* Create a new incident has updated event instance.
*
* @return void
*/
public function __construct(Incident $incident)
{
$this->incident = $incident;
}
}

View File

@@ -0,0 +1,34 @@
<?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\Events\Metric;
use CachetHQ\Cachet\Models\MetricPoint;
class MetricPointWasUpdatedEvent
{
/**
* The metric point that was updated.
*
* @var \CachetHQ\Cachet\Models\MetricPoint
*/
public $point;
/**
* Create a new metric point was updated event instance.
*
* @return void
*/
public function __construct(MetricPoint $point)
{
$this->point = $point;
}
}

View File

@@ -0,0 +1,34 @@
<?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\Events\Metric;
use CachetHQ\Cachet\Models\Metric;
class MetricWasUpdatedEvent
{
/**
* The metric that was updated.
*
* @var \CachetHQ\Cachet\Models\MetricPoint
*/
public $metric;
/**
* Create a new metric was updated event instance.
*
* @return void
*/
public function __construct(Metric $metric)
{
$this->metric = $metric;
}
}

View File

@@ -0,0 +1,55 @@
<?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\Handlers\Commands\Component;
use CachetHQ\Cachet\Commands\Component\UpdateComponentCommand;
use CachetHQ\Cachet\Events\Component\ComponentWasUpdatedEvent;
use CachetHQ\Cachet\Models\Component;
class UpdateComponentCommandHandler
{
/**
* Handle the update component command.
*
* @param \CachetHQ\Cachet\Commands\Component\UpdateComponentCommand $command
*
* @return \CachetHQ\Cachet\Models\Component
*/
public function handle(UpdateComponentCommand $command)
{
$component = $command->component;
$component->update($this->filterComponentData($command));
event(new ComponentWasUpdatedEvent($component));
return $component;
}
/**
* Filter the command data.
*
* @param \CachetHQ\Cachet\Commands\Component\UpdateComponentCommand $command
*
* @return array
*/
protected function filterComponentData($command)
{
return array_filter([
'name' => $command->name,
'description' => $command->description,
'link' => $command->link,
'status' => $command->status,
'order' => $command->order,
'group_id' => $command->group_id,
]);
}
}

View File

@@ -0,0 +1,38 @@
<?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\Handlers\Commands\ComponentGroup;
use CachetHQ\Cachet\Commands\ComponentGroup\UpdateComponentGroupCommand;
use CachetHQ\Cachet\Events\ComponentGroup\ComponentGroupWasUpdatedEvent;
class UpdateComponentGroupCommandHandler
{
/**
* Handle the update component group command.
*
* @param \CachetHQ\Cachet\Commands\ComponentGroup\UpdateComponentGroupCommand $command
*
* @return \CachetHQ\Cachet\Models\ComponentGroup
*/
public function handle(UpdateComponentGroupCommand $command)
{
$group = $command->group;
$group->update([
'name' => $command->name,
'order' => $command->order,
]);
event(new ComponentGroupWasUpdatedEvent($group));
return $group;
}
}

View File

@@ -13,8 +13,11 @@ namespace CachetHQ\Cachet\Handlers\Commands\Incident;
use CachetHQ\Cachet\Commands\Incident\ReportIncidentCommand;
use CachetHQ\Cachet\Events\Incident\IncidentWasReportedEvent;
use CachetHQ\Cachet\Facades\Setting;
use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\Incident;
use Illuminate\Support\Facades\Config;
use Jenssegers\Date\Date;
class ReportIncidentCommandHandler
{
@@ -35,6 +38,16 @@ class ReportIncidentCommandHandler
'component' => $command->component_id,
]);
// The incident occurred at a different time.
if ($command->incident_date) {
$incidentDate = Date::createFromFormat('d/m/Y H:i', $command->incident_date, Setting::get('app_timezone'))->setTimezone(Config::get('app.timezone'));
$incident->update([
'created_at' => $incidentDate,
'updated_at' => $incidentDate,
]);
}
// Update the component.
if ($command->component_id) {
Component::find($command->component_id)->update([

View File

@@ -0,0 +1,80 @@
<?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\Handlers\Commands\Incident;
use CachetHQ\Cachet\Commands\Incident\UpdateIncidentCommand;
use CachetHQ\Cachet\Events\Incident\IncidentWasUpdatedEvent;
use CachetHQ\Cachet\Facades\Setting;
use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\Incident;
use Illuminate\Support\Facades\Config;
use Jenssegers\Date\Date;
class UpdateIncidentCommandHandler
{
/**
* Handle the update incident command.
*
* @param \CachetHQ\Cachet\Commands\Incident\UpdateIncidentCommand $command
*
* @return \CachetHQ\Cachet\Models\Incident
*/
public function handle(UpdateIncidentCommand $command)
{
$incident = $command->incident;
$incident->update($this->filterIncidentData($command));
// The incident occurred at a different time.
if ($command->incident_date) {
$incidentDate = Date::createFromFormat('d/m/Y H:i', $command->incident_date, Setting::get('app_timezone'))->setTimezone(Config::get('app.timezone'));
$incident->update([
'created_at' => $incidentDate,
'updated_at' => $incidentDate,
]);
}
// Update the component.
if ($command->component_id) {
Component::find($command->component_id)->update([
'status' => $command->component_status,
]);
}
// Notify subscribers.
if ($command->notify) {
event(new IncidentWasUpdatedEvent($incident));
}
return $incident;
}
/**
* Filter the command data.
*
* @param \CachetHQ\Cachet\Commands\Incident\UpdateIncidentCommand $command
*
* @return array
*/
protected function filterIncidentData($command)
{
return array_filter([
'name' => $command->name,
'status' => $command->status,
'message' => $command->message,
'visible' => $command->visible,
'component_id' => $command->component_id,
'component_status' => $command->component_status,
'notify' => $command->notify,
]);
}
}

View File

@@ -28,7 +28,7 @@ class AddMetricPointCommandHandler
public function handle(AddMetricPointCommand $command)
{
$metric = $command->metric;
$createdAt = $command->createdAt;
$createdAt = $command->created_at;
$data = [
'metric_id' => $metric->id,

View File

@@ -0,0 +1,57 @@
<?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\Handlers\Commands\Metric;
use CachetHQ\Cachet\Commands\Metric\UpdateMetricCommand;
use CachetHQ\Cachet\Events\Metric\MetricWasUpdatedEvent;
use CachetHQ\Cachet\Models\Metric;
class UpdateMetricCommandHandler
{
/**
* Handle the update metric command.
*
* @param \CachetHQ\Cachet\Commands\Metric\UpdateMetricCommand $command
*
* @return \CachetHQ\Cachet\Models\Metric
*/
public function handle(UpdateMetricCommand $command)
{
$metric = $command->metric;
$metric->update($this->filterMetricData($command));
event(new MetricWasUpdatedEvent($metric));
return $metric;
}
/**
* Filter the command data.
*
* @param \CachetHQ\Cachet\Commands\Metric\UpdateMetricCommand $command
*
* @return array
*/
protected function filterMetricData($command)
{
return array_filter([
'name' => $command->name,
'suffix' => $command->suffix,
'description' => $command->description,
'default_value' => $command->default_value,
'calc_type' => $command->calc_type,
'display_chart' => $command->display_chart,
'places' => $command->places,
]);
}
}

View File

@@ -0,0 +1,48 @@
<?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\Handlers\Commands\Metric;
use CachetHQ\Cachet\Commands\Metric\UpdateMetricPointCommand;
use CachetHQ\Cachet\Events\Metric\MetricPointWasUpdatedEvent;
use Carbon\Carbon;
class UpdateMetricPointCommandHandler
{
/**
* Handle the update metric point command.
*
* @param \CachetHQ\Cachet\Commands\Metric\UpdateMetricPointCommand $command
*
* @return \CachetHQ\Cachet\Models\MetricPoint
*/
public function handle(UpdateMetricPointCommand $command)
{
$point = $command->point;
$metric = $command->metric;
$createdAt = $command->created_at;
$data = [
'metric_id' => $metric->id,
'value' => $command->value,
];
if ($createdAt) {
$data['created_at'] = Carbon::createFromFormat('U', $createdAt)->format('Y-m-d H:i:s');
}
$point->update($data);
event(new MetricPointWasUpdatedEvent($point));
return $point;
}
}

View File

@@ -13,6 +13,7 @@ namespace CachetHQ\Cachet\Http\Controllers\Api;
use CachetHQ\Cachet\Commands\Component\AddComponentCommand;
use CachetHQ\Cachet\Commands\Component\RemoveComponentCommand;
use CachetHQ\Cachet\Commands\Component\UpdateComponentCommand;
use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\Tag;
use Exception;
@@ -101,7 +102,15 @@ class ComponentController extends AbstractApiController
public function putComponent(Component $component)
{
try {
$component->update(Binput::except('tags'));
$this->dispatch(new UpdateComponentCommand(
$component,
Binput::get('name'),
Binput::get('description'),
Binput::get('status'),
Binput::get('link'),
Binput::get('order'),
Binput::get('group_id')
));
} catch (Exception $e) {
throw new BadRequestHttpException();
}

View File

@@ -13,6 +13,7 @@ namespace CachetHQ\Cachet\Http\Controllers\Api;
use CachetHQ\Cachet\Commands\ComponentGroup\AddComponentGroupCommand;
use CachetHQ\Cachet\Commands\ComponentGroup\RemoveComponentGroupCommand;
use CachetHQ\Cachet\Commands\ComponentGroup\UpdateComponentGroupCommand;
use CachetHQ\Cachet\Models\ComponentGroup;
use Exception;
use GrahamCampbell\Binput\Facades\Binput;
@@ -81,7 +82,11 @@ class ComponentGroupController extends AbstractApiController
$groupData = array_filter(Binput::only(['name', 'order']));
try {
$group->update($groupData);
$group = $this->dispatch(new UpdateComponentGroupCommand(
$group,
Binput::get('name'),
Binput::get('order', 0)
));
} catch (Exception $e) {
throw new BadRequestHttpException();
}

View File

@@ -13,6 +13,7 @@ namespace CachetHQ\Cachet\Http\Controllers\Api;
use CachetHQ\Cachet\Commands\Incident\RemoveIncidentCommand;
use CachetHQ\Cachet\Commands\Incident\ReportIncidentCommand;
use CachetHQ\Cachet\Commands\Incident\UpdateIncidentCommand;
use CachetHQ\Cachet\Models\Incident;
use Exception;
use GrahamCampbell\Binput\Facades\Binput;
@@ -71,7 +72,8 @@ class IncidentController extends AbstractApiController
Binput::get('visible', true),
Binput::get('component_id'),
Binput::get('component_status'),
Binput::get('notify', true)
Binput::get('notify', true),
Binput::get('created_at')
));
} catch (Exception $e) {
throw new BadRequestHttpException();
@@ -89,17 +91,18 @@ class IncidentController extends AbstractApiController
*/
public function putIncident(Incident $incident)
{
$incidentData = array_filter(Binput::only([
'name',
'message',
'status',
'component_id',
'notify',
'visible',
]));
try {
$incident->update($incidentData);
$incident = $this->dispatch(new UpdateIncidentCommand(
$incident,
Binput::get('name'),
Binput::get('status'),
Binput::get('message'),
Binput::get('visible', true),
Binput::get('component_id'),
Binput::get('component_status'),
Binput::get('notify', true),
Binput::get('created_at')
));
} catch (Exception $e) {
throw new BadRequestHttpException();
}

View File

@@ -13,6 +13,7 @@ namespace CachetHQ\Cachet\Http\Controllers\Api;
use CachetHQ\Cachet\Commands\Metric\AddMetricCommand;
use CachetHQ\Cachet\Commands\Metric\RemoveMetricCommand;
use CachetHQ\Cachet\Commands\Metric\UpdateMetricCommand;
use CachetHQ\Cachet\Models\Metric;
use Exception;
use GrahamCampbell\Binput\Facades\Binput;
@@ -96,7 +97,16 @@ class MetricController extends AbstractApiController
public function putMetric(Metric $metric)
{
try {
$metric->update(Binput::all());
$metric = $this->dispatch(new UpdateMetricCommand(
$metric,
Binput::get('name'),
Binput::get('suffix'),
Binput::get('description'),
Binput::get('default_value'),
Binput::get('calc_type', 0),
Binput::get('display_chart'),
Binput::get('places')
));
} catch (Exception $e) {
throw new BadRequestHttpException();
}

View File

@@ -13,9 +13,9 @@ namespace CachetHQ\Cachet\Http\Controllers\Api;
use CachetHQ\Cachet\Commands\Metric\AddMetricPointCommand;
use CachetHQ\Cachet\Commands\Metric\RemoveMetricPointCommand;
use CachetHQ\Cachet\Commands\Metric\UpdateMetricPointCommand;
use CachetHQ\Cachet\Models\Metric;
use CachetHQ\Cachet\Models\MetricPoint;
use Carbon\Carbon;
use Exception;
use GrahamCampbell\Binput\Facades\Binput;
use Illuminate\Foundation\Bus\DispatchesJobs;
@@ -48,7 +48,11 @@ class MetricPointController extends AbstractApiController
public function postMetricPoints(Metric $metric)
{
try {
$metricPoint = $this->dispatch(new AddMetricPointCommand($metric, Binput::get('value'), Binput::get('timestamp')));
$metricPoint = $this->dispatch(new AddMetricPointCommand(
$metric,
Binput::get('value'),
Binput::get('timestamp'))
);
} catch (Exception $e) {
throw new BadRequestHttpException();
}
@@ -66,15 +70,12 @@ class MetricPointController extends AbstractApiController
*/
public function putMetricPoint(Metric $metric, MetricPoint $metricPoint)
{
$metricPointData = Binput::all();
$metricPointData['metric_id'] = $metric->id;
if ($timestamp = array_pull($metricPointData, 'timestamp')) {
$pointTimestamp = Carbon::createFromFormat('U', $timestamp);
$metricPointData['created_at'] = $pointTimestamp->format('Y-m-d H:i:s');
}
$metricPoint->update($metricPointData);
$metricPoint = $this->dispatch(new UpdateMetricPointCommand(
$metricPoint,
$metric,
Binput::get('value'),
Binput::get('timestamp')
));
return $this->item($metricPoint);
}

View File

@@ -16,6 +16,7 @@ use CachetHQ\Cachet\Commands\Component\AddComponentCommand;
use CachetHQ\Cachet\Commands\Component\RemoveComponentCommand;
use CachetHQ\Cachet\Commands\ComponentGroup\AddComponentGroupCommand;
use CachetHQ\Cachet\Commands\ComponentGroup\RemoveComponentGroupCommand;
use CachetHQ\Cachet\Commands\ComponentGroup\UpdateComponentGroupCommand;
use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\ComponentGroup;
use CachetHQ\Cachet\Models\Tag;
@@ -114,11 +115,12 @@ class ComponentController extends Controller
*/
public function updateComponentAction(Component $component)
{
$_component = Binput::get('component');
$tags = array_pull($_component, 'tags');
$componentData = Binput::get('component');
$tags = array_pull($componentData, 'tags');
try {
$component->update($_component);
$componentData['component'] = $component;
$component = $this->dispatchFromArray(AddComponentCommand::class, $componentData);
} catch (ValidationException $e) {
return Redirect::route('dashboard.components.edit', ['id' => $component->id])
->withInput(Binput::all())
@@ -159,12 +161,11 @@ class ComponentController extends Controller
*/
public function createComponentAction()
{
$_component = Binput::get('component');
// We deal with tags separately.
$tags = array_pull($_component, 'tags');
$componentData = Binput::get('component');
$tags = array_pull($componentData, 'tags');
try {
$component = $this->dispatchFromArray(AddComponentCommand::class, Binput::get('component'));
$component = $this->dispatchFromArray(AddComponentCommand::class, $componentData);
} catch (ValidationException $e) {
return Redirect::route('dashboard.components.add')
->withInput(Binput::all())
@@ -271,18 +272,20 @@ class ComponentController extends Controller
*/
public function updateComponentGroupAction(ComponentGroup $group)
{
$groupData = Binput::get('group');
try {
$group->update($groupData);
$group = $this->dispatch(new UpdateComponentGroupCommand(
$group,
Binput::get('name'),
Binput::get('order', 0)
));
} catch (ValidationException $e) {
return Redirect::route('dashboard.components.group.edit', ['id' => $group->id])
return Redirect::route('dashboard.components.groups.edit', ['id' => $group->id])
->withInput(Binput::all())
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.components.groups.edit.failure')))
->withErrors($e->getMessageBag());
}
return Redirect::route('dashboard.components.group.edit', ['id' => $group->id])
return Redirect::route('dashboard.components.groups.edit', ['id' => $group->id])
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.components.groups.edit.success')));
}
}

View File

@@ -14,7 +14,7 @@ namespace CachetHQ\Cachet\Http\Controllers\Dashboard;
use AltThree\Validator\ValidationException;
use CachetHQ\Cachet\Commands\Incident\RemoveIncidentCommand;
use CachetHQ\Cachet\Commands\Incident\ReportIncidentCommand;
use CachetHQ\Cachet\Facades\Setting;
use CachetHQ\Cachet\Commands\Incident\UpdateIncidentCommand;
use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\ComponentGroup;
use CachetHQ\Cachet\Models\Incident;
@@ -22,10 +22,8 @@ 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;
use Illuminate\Support\Facades\View;
use Jenssegers\Date\Date;
class IncidentController extends Controller
{
@@ -111,10 +109,6 @@ class IncidentController extends Controller
*/
public function createIncidentAction()
{
if ($createdAt = Binput::get('created_at')) {
$incidentDate = Date::createFromFormat('d/m/Y H:i', $createdAt, Setting::get('app_timezone'))->setTimezone(Config::get('app.timezone'));
}
try {
$incident = $this->dispatch(new ReportIncidentCommand(
Binput::get('name'),
@@ -123,15 +117,9 @@ class IncidentController extends Controller
Binput::get('visible', true),
Binput::get('component_id'),
Binput::get('component_status'),
Binput::get('notify', true)
Binput::get('notify', true),
Binput::get('created_at')
));
if (isset($incidentDate)) {
$incident->update([
'created_at' => $incidentDate,
'updated_at' => $incidentDate,
]);
}
} catch (ValidationException $e) {
return Redirect::route('dashboard.incidents.add')
->withInput(Binput::all())
@@ -241,18 +229,18 @@ class IncidentController extends Controller
*/
public function editIncidentAction(Incident $incident)
{
$incidentData = Binput::get('incident');
if (array_has($incidentData, 'created_at') && $incidentData['created_at']) {
$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;
} else {
unset($incidentData['created_at']);
}
try {
$incident->update($incidentData);
$incident = $this->dispatch(new UpdateIncidentCommand(
$incident,
Binput::get('name'),
Binput::get('status'),
Binput::get('message'),
Binput::get('visible', true),
Binput::get('component_id'),
Binput::get('component_status'),
Binput::get('notify', true),
Binput::get('created_at')
));
} catch (ValidationException $e) {
return Redirect::route('dashboard.incidents.edit', ['id' => $incident->id])
->withInput(Binput::all())

View File

@@ -14,6 +14,7 @@ namespace CachetHQ\Cachet\Http\Controllers\Dashboard;
use AltThree\Validator\ValidationException;
use CachetHQ\Cachet\Commands\Metric\AddMetricCommand;
use CachetHQ\Cachet\Commands\Metric\RemoveMetricCommand;
use CachetHQ\Cachet\Commands\Metric\UpdateMetricCommand;
use CachetHQ\Cachet\Models\Metric;
use CachetHQ\Cachet\Models\MetricPoint;
use GrahamCampbell\Binput\Facades\Binput;
@@ -132,7 +133,16 @@ class MetricController extends Controller
public function editMetricAction(Metric $metric)
{
try {
$metric->update(Binput::get('metric', null, false));
$this->dispatch(new UpdateMetricCommand(
$metric,
Binput::get('metric.name', null, false),
Binput::get('metric.suffix', null, false),
Binput::get('metric.description', null, false),
Binput::get('metric.default_value', null, false),
Binput::get('metric.calc_type', null, false),
Binput::get('metric.display_chart', null, false),
Binput::get('metric.places', null, false)
));
} catch (ValidationException $e) {
return Redirect::route('dashboard.metrics.edit', ['id' => $metric->id])
->withInput(Binput::all())

View File

@@ -30,7 +30,7 @@ class FeedRoutes
// Prevent access until the app is setup.
$router->group([
'middleware' => 'app.hasSetting',
'setting' => 'app_name'
'setting' => 'app_name',
], function ($router) {
$router->get('/atom/{component_group?}', [
'as' => 'feed.atom',

View File

@@ -19,7 +19,7 @@
<fieldset>
<div class="form-group">
<label for="incident-name">{{ trans('forms.components.groups.name') }}</label>
<input type="text" class="form-control" name="group[name]" id="group-name" value="{{ $group->name }}" required>
<input type="text" class="form-control" name="name" id="group-name" value="{{ $group->name }}" required>
</div>
</fieldset>