Update a SEO title and description in the incident meta
This commit is contained in:
@@ -106,6 +106,13 @@ final class UpdateIncidentCommand
|
|||||||
*/
|
*/
|
||||||
public $template_vars;
|
public $template_vars;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Meta key/value pairs.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public $meta = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The validation rules.
|
* The validation rules.
|
||||||
*
|
*
|
||||||
@@ -122,6 +129,7 @@ final class UpdateIncidentCommand
|
|||||||
'stickied' => 'nullable|bool',
|
'stickied' => 'nullable|bool',
|
||||||
'occurred_at' => 'nullable|string',
|
'occurred_at' => 'nullable|string',
|
||||||
'template' => 'nullable|string',
|
'template' => 'nullable|string',
|
||||||
|
'meta' => 'nullable|array',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -139,10 +147,11 @@ final class UpdateIncidentCommand
|
|||||||
* @param string|null $occurred_at
|
* @param string|null $occurred_at
|
||||||
* @param string|null $template
|
* @param string|null $template
|
||||||
* @param array $template_vars
|
* @param array $template_vars
|
||||||
|
* @param array $meta
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct(Incident $incident, $name, $status, $message, $visible, $component_id, $component_status, $notify, $stickied, $occurred_at, $template, array $template_vars = [])
|
public function __construct(Incident $incident, $name, $status, $message, $visible, $component_id, $component_status, $notify, $stickied, $occurred_at, $template, array $template_vars = [], $meta = [])
|
||||||
{
|
{
|
||||||
$this->incident = $incident;
|
$this->incident = $incident;
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
@@ -156,5 +165,6 @@ final class UpdateIncidentCommand
|
|||||||
$this->occurred_at = $occurred_at;
|
$this->occurred_at = $occurred_at;
|
||||||
$this->template = $template;
|
$this->template = $template;
|
||||||
$this->template_vars = $template_vars;
|
$this->template_vars = $template_vars;
|
||||||
|
$this->meta = $meta;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ use CachetHQ\Cachet\Bus\Commands\Component\UpdateComponentCommand;
|
|||||||
use CachetHQ\Cachet\Bus\Commands\Incident\CreateIncidentCommand;
|
use CachetHQ\Cachet\Bus\Commands\Incident\CreateIncidentCommand;
|
||||||
use CachetHQ\Cachet\Bus\Events\Incident\IncidentWasCreatedEvent;
|
use CachetHQ\Cachet\Bus\Events\Incident\IncidentWasCreatedEvent;
|
||||||
use CachetHQ\Cachet\Bus\Exceptions\Incident\InvalidIncidentTimestampException;
|
use CachetHQ\Cachet\Bus\Exceptions\Incident\InvalidIncidentTimestampException;
|
||||||
|
use CachetHQ\Cachet\Bus\Handlers\Traits\StoresMeta;
|
||||||
use CachetHQ\Cachet\Models\Component;
|
use CachetHQ\Cachet\Models\Component;
|
||||||
use CachetHQ\Cachet\Models\Incident;
|
use CachetHQ\Cachet\Models\Incident;
|
||||||
use CachetHQ\Cachet\Models\IncidentTemplate;
|
use CachetHQ\Cachet\Models\IncidentTemplate;
|
||||||
@@ -32,6 +33,8 @@ use Twig_Loader_Array;
|
|||||||
*/
|
*/
|
||||||
class CreateIncidentCommandHandler
|
class CreateIncidentCommandHandler
|
||||||
{
|
{
|
||||||
|
use StoresMeta;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The authentication guard instance.
|
* The authentication guard instance.
|
||||||
*
|
*
|
||||||
@@ -103,18 +106,7 @@ class CreateIncidentCommandHandler
|
|||||||
|
|
||||||
// Store any meta?
|
// Store any meta?
|
||||||
if ($meta = $command->meta) {
|
if ($meta = $command->meta) {
|
||||||
foreach ($meta as $key => $value) {
|
$this->storeMeta($command->meta, 'incidents', $incident->id);
|
||||||
if (empty($value)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Meta::create([
|
|
||||||
'key' => $key,
|
|
||||||
'value' => $value,
|
|
||||||
'meta_type' => 'incidents',
|
|
||||||
'meta_id' => $incident->id,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the component.
|
// Update the component.
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ use CachetHQ\Cachet\Bus\Commands\Component\UpdateComponentCommand;
|
|||||||
use CachetHQ\Cachet\Bus\Commands\Incident\UpdateIncidentCommand;
|
use CachetHQ\Cachet\Bus\Commands\Incident\UpdateIncidentCommand;
|
||||||
use CachetHQ\Cachet\Bus\Events\Incident\IncidentWasUpdatedEvent;
|
use CachetHQ\Cachet\Bus\Events\Incident\IncidentWasUpdatedEvent;
|
||||||
use CachetHQ\Cachet\Bus\Exceptions\Incident\InvalidIncidentTimestampException;
|
use CachetHQ\Cachet\Bus\Exceptions\Incident\InvalidIncidentTimestampException;
|
||||||
|
use CachetHQ\Cachet\Bus\Handlers\Traits\StoresMeta;
|
||||||
use CachetHQ\Cachet\Models\Component;
|
use CachetHQ\Cachet\Models\Component;
|
||||||
use CachetHQ\Cachet\Models\Incident;
|
use CachetHQ\Cachet\Models\Incident;
|
||||||
use CachetHQ\Cachet\Models\IncidentTemplate;
|
use CachetHQ\Cachet\Models\IncidentTemplate;
|
||||||
@@ -30,6 +31,8 @@ use Twig_Loader_Array;
|
|||||||
*/
|
*/
|
||||||
class UpdateIncidentCommandHandler
|
class UpdateIncidentCommandHandler
|
||||||
{
|
{
|
||||||
|
use StoresMeta;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The authentication guard instance.
|
* The authentication guard instance.
|
||||||
*
|
*
|
||||||
@@ -86,6 +89,11 @@ class UpdateIncidentCommandHandler
|
|||||||
// Rather than making lots of updates, just fill and save.
|
// Rather than making lots of updates, just fill and save.
|
||||||
$incident->save();
|
$incident->save();
|
||||||
|
|
||||||
|
// Store any meta?
|
||||||
|
if ($meta = $command->meta) {
|
||||||
|
$this->storeMeta($command->meta, 'incidents', $incident->id);
|
||||||
|
}
|
||||||
|
|
||||||
// Update the component.
|
// Update the component.
|
||||||
if ($component = Component::find($command->component_id)) {
|
if ($component = Component::find($command->component_id)) {
|
||||||
dispatch(new UpdateComponentCommand(
|
dispatch(new UpdateComponentCommand(
|
||||||
|
|||||||
40
app/Bus/Handlers/Traits/StoresMeta.php
Normal file
40
app/Bus/Handlers/Traits/StoresMeta.php
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace CachetHQ\Cachet\Bus\Handlers\Traits;
|
||||||
|
|
||||||
|
use CachetHQ\Cachet\Models\Meta;
|
||||||
|
|
||||||
|
trait StoresMeta
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Stores all Meta values of a model
|
||||||
|
*
|
||||||
|
* @param $meta
|
||||||
|
* @param $type
|
||||||
|
* @param $id
|
||||||
|
*/
|
||||||
|
public function storeMeta($meta, $type, $id)
|
||||||
|
{
|
||||||
|
// Validation required instead of type hinting because it could be passed as false or NULL
|
||||||
|
if (!is_array($meta)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($meta as $key => $value) {
|
||||||
|
if (empty($value)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$meta = Meta::firstOrNew([
|
||||||
|
'key' => $key,
|
||||||
|
'meta_type' => $type,
|
||||||
|
'meta_id' => $id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$meta->value = $value;
|
||||||
|
|
||||||
|
$meta->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -262,7 +262,8 @@ class IncidentController extends Controller
|
|||||||
Binput::get('stickied', false),
|
Binput::get('stickied', false),
|
||||||
Binput::get('occurred_at'),
|
Binput::get('occurred_at'),
|
||||||
null,
|
null,
|
||||||
[]
|
[],
|
||||||
|
['seo' => Binput::get('seo', [])]
|
||||||
));
|
));
|
||||||
} catch (ValidationException $e) {
|
} catch (ValidationException $e) {
|
||||||
return cachet_redirect('dashboard.incidents.edit', ['id' => $incident->id])
|
return cachet_redirect('dashboard.incidents.edit', ['id' => $incident->id])
|
||||||
|
|||||||
@@ -111,6 +111,14 @@
|
|||||||
<label>{{ trans('forms.incidents.occurred_at') }}</label> <small class="text-muted">{{ trans('forms.optional') }}</small>
|
<label>{{ trans('forms.incidents.occurred_at') }}</label> <small class="text-muted">{{ trans('forms.optional') }}</small>
|
||||||
<input type="text" name="occurred_at" class="form-control" rel="datepicker-custom" data-date-format="YYYY-MM-DD HH:mm" value="{{ $incident->occurred_at_datetimepicker }}" placeholder="{{ trans('forms.optional') }}">
|
<input type="text" name="occurred_at" class="form-control" rel="datepicker-custom" data-date-format="YYYY-MM-DD HH:mm" value="{{ $incident->occurred_at_datetimepicker }}" placeholder="{{ trans('forms.optional') }}">
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label>{{ trans('forms.seo.title') }}</label> <small class="text-muted">{{ trans('forms.optional') }}</small>
|
||||||
|
<input type="text" name="seo[title]" class="form-control" value="{{ array_get($incident->meta, 'seo.title', '') }}">
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label>{{ trans('forms.seo.description') }}</label> <small class="text-muted">{{ trans('forms.optional') }}</small>
|
||||||
|
<input type="text" name="seo[description]" class="form-control" value="{{ array_get($incident->meta, 'seo.description', '') }}">
|
||||||
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
|||||||
Reference in New Issue
Block a user