Added commands to delete component group (also fixes bug in API)

This commit is contained in:
James Brooks
2015-08-26 13:36:10 +01:00
parent c466620435
commit be080a10ef
6 changed files with 151 additions and 6 deletions

View File

@@ -0,0 +1,40 @@
<?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\Handlers\Commands\ComponentGroup;
use CachetHQ\Cachet\Commands\ComponentGroup\RemoveComponentGroupCommand;
use CachetHQ\Cachet\Events\ComponentGroup\ComponentGroupWasRemovedEvent;
use CachetHQ\Cachet\Models\ComponentGroup;
class RemoveComponentGroupCommandHandler
{
/**
* Handle the remove component group command.
*
* @param \CachetHQ\Cachet\Commands\ComponentGroup\RemoveComponentGroupCommand $command
*
* @return void
*/
public function handle(RemoveComponentGroupCommand $command)
{
$group = $command->group;
event(new ComponentGroupWasRemovedEvent($group));
// Remove the group id from all component.
$group->components->map(function ($component) {
$component->update(['group_id' => 0]);
});
$group->delete();
}
}