Fixes and validation rules

This commit is contained in:
Joseph Cohen 2015-09-24 23:07:39 -05:00
parent 354bfffc97
commit 3f8471d8da
12 changed files with 108 additions and 29 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

@ -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',
];
/**

View File

@ -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.
*

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

@ -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;
}
}

View File

@ -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.
*

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

@ -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',
];

View File

@ -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;
}
}

View File

@ -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([

View File

@ -28,7 +28,7 @@ class UpdateMetricPointCommandHandler
{
$point = $command->point;
$metric = $command->metric;
$createdAt = $command->createdAt;
$createdAt = $command->created_at;
$data = [
'metric_id' => $metric->id,

View File

@ -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())