Update a SEO title and description in the incident meta
This commit is contained in:
@@ -15,6 +15,7 @@ use CachetHQ\Cachet\Bus\Commands\Component\UpdateComponentCommand;
|
||||
use CachetHQ\Cachet\Bus\Commands\Incident\CreateIncidentCommand;
|
||||
use CachetHQ\Cachet\Bus\Events\Incident\IncidentWasCreatedEvent;
|
||||
use CachetHQ\Cachet\Bus\Exceptions\Incident\InvalidIncidentTimestampException;
|
||||
use CachetHQ\Cachet\Bus\Handlers\Traits\StoresMeta;
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
use CachetHQ\Cachet\Models\IncidentTemplate;
|
||||
@@ -32,6 +33,8 @@ use Twig_Loader_Array;
|
||||
*/
|
||||
class CreateIncidentCommandHandler
|
||||
{
|
||||
use StoresMeta;
|
||||
|
||||
/**
|
||||
* The authentication guard instance.
|
||||
*
|
||||
@@ -103,18 +106,7 @@ class CreateIncidentCommandHandler
|
||||
|
||||
// Store any meta?
|
||||
if ($meta = $command->meta) {
|
||||
foreach ($meta as $key => $value) {
|
||||
if (empty($value)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Meta::create([
|
||||
'key' => $key,
|
||||
'value' => $value,
|
||||
'meta_type' => 'incidents',
|
||||
'meta_id' => $incident->id,
|
||||
]);
|
||||
}
|
||||
$this->storeMeta($command->meta, 'incidents', $incident->id);
|
||||
}
|
||||
|
||||
// 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\Events\Incident\IncidentWasUpdatedEvent;
|
||||
use CachetHQ\Cachet\Bus\Exceptions\Incident\InvalidIncidentTimestampException;
|
||||
use CachetHQ\Cachet\Bus\Handlers\Traits\StoresMeta;
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
use CachetHQ\Cachet\Models\IncidentTemplate;
|
||||
@@ -30,6 +31,8 @@ use Twig_Loader_Array;
|
||||
*/
|
||||
class UpdateIncidentCommandHandler
|
||||
{
|
||||
use StoresMeta;
|
||||
|
||||
/**
|
||||
* The authentication guard instance.
|
||||
*
|
||||
@@ -86,6 +89,11 @@ class UpdateIncidentCommandHandler
|
||||
// Rather than making lots of updates, just fill and save.
|
||||
$incident->save();
|
||||
|
||||
// Store any meta?
|
||||
if ($meta = $command->meta) {
|
||||
$this->storeMeta($command->meta, 'incidents', $incident->id);
|
||||
}
|
||||
|
||||
// Update the component.
|
||||
if ($component = Component::find($command->component_id)) {
|
||||
dispatch(new UpdateComponentCommand(
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user