From 3f8471d8da3edaf5158436551dac3a3fc193b749 Mon Sep 17 00:00:00 2001 From: Joseph Cohen Date: Thu, 24 Sep 2015 23:07:39 -0500 Subject: [PATCH] Fixes and validation rules --- .../Component/AddComponentCommand.php | 9 +++++--- .../Component/UpdateComponentCommand.php | 11 ++++++---- .../Incident/ReportIncidentCommand.php | 15 +++++++++++++ .../Incident/ReportMaintenanceCommand.php | 12 +++++++++++ .../Incident/UpdateIncidentCommand.php | 21 +++++++++++++++++-- app/Commands/Metric/AddMetricCommand.php | 9 +++++--- app/Commands/Metric/AddMetricPointCommand.php | 18 ++++++++++++---- app/Commands/Metric/UpdateMetricCommand.php | 3 +++ .../Metric/UpdateMetricPointCommand.php | 18 ++++++++++++---- .../Incident/UpdateIncidentCommandHandler.php | 7 +++++++ .../UpdateMetricPointCommandHandler.php | 2 +- .../Dashboard/IncidentController.php | 12 ++++------- 12 files changed, 108 insertions(+), 29 deletions(-) diff --git a/app/Commands/Component/AddComponentCommand.php b/app/Commands/Component/AddComponentCommand.php index 4952bf570..4f43e61ee 100644 --- a/app/Commands/Component/AddComponentCommand.php +++ b/app/Commands/Component/AddComponentCommand.php @@ -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', ]; /** diff --git a/app/Commands/Component/UpdateComponentCommand.php b/app/Commands/Component/UpdateComponentCommand.php index b50d0a5f9..d34ee4d9f 100644 --- a/app/Commands/Component/UpdateComponentCommand.php +++ b/app/Commands/Component/UpdateComponentCommand.php @@ -16,7 +16,7 @@ use CachetHQ\Cachet\Models\Component; class UpdateComponentCommand { /** - * The component. + * The component to update. * * @var \CachetHQ\Cachet\Models\Component */ @@ -70,9 +70,12 @@ class UpdateComponentCommand * @var string[] */ public $rules = [ - 'name' => 'string', - 'status' => 'integer', - 'link' => 'url', + 'name' => 'string', + 'description' => 'string', + 'status' => 'integer', + 'link' => 'url', + 'order' => 'integer', + 'group_id' => 'integer', ]; /** diff --git a/app/Commands/Incident/ReportIncidentCommand.php b/app/Commands/Incident/ReportIncidentCommand.php index 073e183a8..25486c75c 100644 --- a/app/Commands/Incident/ReportIncidentCommand.php +++ b/app/Commands/Incident/ReportIncidentCommand.php @@ -62,6 +62,21 @@ class ReportIncidentCommand */ public $notify; + /** + * 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', + ]; + /** * Create a new report incident command instance. * diff --git a/app/Commands/Incident/ReportMaintenanceCommand.php b/app/Commands/Incident/ReportMaintenanceCommand.php index 82105055e..2f0a64050 100644 --- a/app/Commands/Incident/ReportMaintenanceCommand.php +++ b/app/Commands/Incident/ReportMaintenanceCommand.php @@ -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. * diff --git a/app/Commands/Incident/UpdateIncidentCommand.php b/app/Commands/Incident/UpdateIncidentCommand.php index bf6b56f38..d271bca20 100644 --- a/app/Commands/Incident/UpdateIncidentCommand.php +++ b/app/Commands/Incident/UpdateIncidentCommand.php @@ -16,7 +16,7 @@ use CachetHQ\Cachet\Models\Incident; class UpdateIncidentCommand { /** - * The incident. + * The incident to update. * * @var \CachetHQ\Cachet\Models\Incident */ @@ -71,6 +71,21 @@ class UpdateIncidentCommand */ public $notify; + /** + * 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. * @@ -82,10 +97,11 @@ class UpdateIncidentCommand * @param int $component_id * @param int $component_status * @param bool $notify + * @param string|null $incidentDate * * @return void */ - public function __construct(Incident $incident, $name, $status, $message, $visible, $component_id, $component_status, $notify) + public function __construct(Incident $incident, $name, $status, $message, $visible, $component_id, $component_status, $notify, $incident_date = null) { $this->incident = $incident; $this->name = $name; @@ -95,5 +111,6 @@ class UpdateIncidentCommand $this->component_id = $component_id; $this->component_status = $component_status; $this->notify = $notify; + $this->incident_date = $incident_date; } } diff --git a/app/Commands/Metric/AddMetricCommand.php b/app/Commands/Metric/AddMetricCommand.php index b65072cec..f946f6284 100644 --- a/app/Commands/Metric/AddMetricCommand.php +++ b/app/Commands/Metric/AddMetricCommand.php @@ -68,13 +68,16 @@ class AddMetricCommand * @var string[] */ public $rules = [ - 'name' => 'required', - 'suffix' => 'required', + 'name' => 'required|string', + 'suffix' => 'required|string', + 'description' => 'string', 'display_chart' => 'boolean', 'default_value' => 'numeric', + 'calc_type' => 'integer', + 'display_chart' => 'integer', 'places' => 'numeric|min:0|max:4', ]; - + /** * Create a new add metric command instance. * diff --git a/app/Commands/Metric/AddMetricPointCommand.php b/app/Commands/Metric/AddMetricPointCommand.php index e0b676b81..9ecdad1a1 100644 --- a/app/Commands/Metric/AddMetricPointCommand.php +++ b/app/Commands/Metric/AddMetricPointCommand.php @@ -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; } } diff --git a/app/Commands/Metric/UpdateMetricCommand.php b/app/Commands/Metric/UpdateMetricCommand.php index b6284f890..3c4674fe0 100644 --- a/app/Commands/Metric/UpdateMetricCommand.php +++ b/app/Commands/Metric/UpdateMetricCommand.php @@ -79,8 +79,11 @@ class UpdateMetricCommand public $rules = [ 'name' => 'string', 'suffix' => 'string', + 'description' => 'string', 'display_chart' => 'boolean', 'default_value' => 'numeric', + 'calc_type' => 'integer', + 'display_chart' => 'integer', 'places' => 'numeric|min:0|max:4', ]; diff --git a/app/Commands/Metric/UpdateMetricPointCommand.php b/app/Commands/Metric/UpdateMetricPointCommand.php index 7d3cdb9f0..420a41e4a 100644 --- a/app/Commands/Metric/UpdateMetricPointCommand.php +++ b/app/Commands/Metric/UpdateMetricPointCommand.php @@ -42,7 +42,17 @@ class UpdateMetricPointCommand * * @var string */ - public $createdAt; + public $created_at; + + /** + * The validation rules. + * + * @var string[] + */ + public $rules = [ + 'value' => 'integer', + 'created_at' => 'string', + ]; /** * Create a new update metric point command instance. @@ -50,15 +60,15 @@ class UpdateMetricPointCommand * @param \CachetHQ\Cachet\Models\MetricPoint $point * @param \CachetHQ\Cachet\Models\Metric $metric * @param int $value - * @param string $createdAt + * @param string $created_at * * @return void */ - public function __construct(MetricPoint $point, Metric $metric, $value, $createdAt) + public function __construct(MetricPoint $point, Metric $metric, $value, $created_at) { $this->point = $point; $this->metric = $metric; $this->value = $value; - $this->createdAt = $createdAt; + $this->created_at = $created_at; } } diff --git a/app/Handlers/Commands/Incident/UpdateIncidentCommandHandler.php b/app/Handlers/Commands/Incident/UpdateIncidentCommandHandler.php index 03802fd70..bbaf7ac23 100644 --- a/app/Handlers/Commands/Incident/UpdateIncidentCommandHandler.php +++ b/app/Handlers/Commands/Incident/UpdateIncidentCommandHandler.php @@ -30,6 +30,13 @@ class UpdateIncidentCommandHandler $incident = $command->incident; $incident->update($this->filterIncidentData($command)); + if ($incidentDate = $command->incident_date) { + $incident->update([ + 'created_at' => $incidentDate, + 'updated_at' => $incidentDate, + ]); + } + // Update the component. if ($command->component_id) { Component::find($command->component_id)->update([ diff --git a/app/Handlers/Commands/Metric/UpdateMetricPointCommandHandler.php b/app/Handlers/Commands/Metric/UpdateMetricPointCommandHandler.php index 794eebebd..823d254ed 100644 --- a/app/Handlers/Commands/Metric/UpdateMetricPointCommandHandler.php +++ b/app/Handlers/Commands/Metric/UpdateMetricPointCommandHandler.php @@ -28,7 +28,7 @@ class UpdateMetricPointCommandHandler { $point = $command->point; $metric = $command->metric; - $createdAt = $command->createdAt; + $createdAt = $command->created_at; $data = [ 'metric_id' => $metric->id, diff --git a/app/Http/Controllers/Dashboard/IncidentController.php b/app/Http/Controllers/Dashboard/IncidentController.php index 443481fae..475581940 100644 --- a/app/Http/Controllers/Dashboard/IncidentController.php +++ b/app/Http/Controllers/Dashboard/IncidentController.php @@ -112,6 +112,8 @@ class IncidentController extends Controller */ public function createIncidentAction() { + $incidentDate = null; + if ($createdAt = Binput::get('created_at')) { $incidentDate = Date::createFromFormat('d/m/Y H:i', $createdAt, Setting::get('app_timezone'))->setTimezone(Config::get('app.timezone')); } @@ -124,15 +126,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), + $incidentDate )); - - if (isset($incidentDate)) { - $incident->update([ - 'created_at' => $incidentDate, - 'updated_at' => $incidentDate, - ]); - } } catch (ValidationException $e) { return Redirect::route('dashboard.incidents.add') ->withInput(Binput::all())