67 lines
1.9 KiB
PHP
67 lines
1.9 KiB
PHP
<?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\Bus\Handlers\Commands\Component;
|
|
|
|
use CachetHQ\Cachet\Bus\Commands\Component\UpdateComponentCommand;
|
|
use CachetHQ\Cachet\Bus\Events\Component\ComponentStatusWasUpdatedEvent;
|
|
use CachetHQ\Cachet\Bus\Events\Component\ComponentWasUpdatedEvent;
|
|
use CachetHQ\Cachet\Models\Component;
|
|
|
|
class UpdateComponentCommandHandler
|
|
{
|
|
/**
|
|
* Handle the update component command.
|
|
*
|
|
* @param \CachetHQ\Cachet\Bus\Commands\Component\UpdateComponentCommand $command
|
|
*
|
|
* @return \CachetHQ\Cachet\Models\Component
|
|
*/
|
|
public function handle(UpdateComponentCommand $command)
|
|
{
|
|
$component = $command->component;
|
|
|
|
if ($command->status && $component->status !== $command->status) {
|
|
event(new ComponentStatusWasUpdatedEvent($component, $component->status, $command->status));
|
|
}
|
|
|
|
$component->update($this->filter($command));
|
|
|
|
event(new ComponentWasUpdatedEvent($component));
|
|
|
|
return $component;
|
|
}
|
|
|
|
/**
|
|
* Filter the command data.
|
|
*
|
|
* @param \CachetHQ\Cachet\Bus\Commands\Incident\UpdateComponentCommand $command
|
|
*
|
|
* @return array
|
|
*/
|
|
protected function filter(UpdateComponentCommand $command)
|
|
{
|
|
$params = [
|
|
'name' => $command->name,
|
|
'description' => $command->description,
|
|
'link' => $command->link,
|
|
'status' => $command->status,
|
|
'enabled' => $command->enabled,
|
|
'order' => $command->order,
|
|
'group_id' => $command->group_id,
|
|
];
|
|
|
|
return array_filter($params, function ($val) {
|
|
return $val !== null;
|
|
});
|
|
}
|
|
}
|