mirror of
https://github.com/CachetHQ/Cachet.git
synced 2025-01-18 05:58:18 +01:00
Added commands to delete component group (also fixes bug in API)
This commit is contained in:
parent
c466620435
commit
be080a10ef
36
app/Commands/ComponentGroup/RemoveComponentGroupCommand.php
Normal file
36
app/Commands/ComponentGroup/RemoveComponentGroupCommand.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?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\Commands\ComponentGroup;
|
||||
|
||||
use CachetHQ\Cachet\Models\ComponentGroup;
|
||||
|
||||
class RemoveComponentGroupCommand
|
||||
{
|
||||
/**
|
||||
* The component group to remove.
|
||||
*
|
||||
* @var \CachetHQ\Cachet\Models\ComponentGroup
|
||||
*/
|
||||
public $group;
|
||||
|
||||
/**
|
||||
* Create a new remove component group command instance.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\ComponentGroup $group
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(ComponentGroup $group)
|
||||
{
|
||||
$this->group = $group;
|
||||
}
|
||||
}
|
34
app/Events/ComponentGroup/ComponentGroupWasAddedEvent.php
Normal file
34
app/Events/ComponentGroup/ComponentGroupWasAddedEvent.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?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\Events\ComponentGroup;
|
||||
|
||||
use CachetHQ\Cachet\Models\ComponentGroup;
|
||||
|
||||
class ComponentGroupWasAddedEvent
|
||||
{
|
||||
/**
|
||||
* The component group that was added.
|
||||
*
|
||||
* @var \CachetHQ\Cachet\Models\ComponentGroup
|
||||
*/
|
||||
public $group;
|
||||
|
||||
/**
|
||||
* Create a new component group was added event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(ComponentGroup $group)
|
||||
{
|
||||
$this->group = $group;
|
||||
}
|
||||
}
|
34
app/Events/ComponentGroup/ComponentGroupWasRemovedEvent.php
Normal file
34
app/Events/ComponentGroup/ComponentGroupWasRemovedEvent.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?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\Events\ComponentGroup;
|
||||
|
||||
use CachetHQ\Cachet\Models\ComponentGroup;
|
||||
|
||||
class ComponentGroupWasRemovedEvent
|
||||
{
|
||||
/**
|
||||
* The component group that was removed.
|
||||
*
|
||||
* @var \CachetHQ\Cachet\Models\ComponentGroup
|
||||
*/
|
||||
public $group;
|
||||
|
||||
/**
|
||||
* Create a new component group was removed event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(ComponentGroup $group)
|
||||
{
|
||||
$this->group = $group;
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -11,14 +11,18 @@
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Api;
|
||||
|
||||
use CachetHQ\Cachet\Commands\ComponentGroup\RemoveComponentGroupCommand;
|
||||
use CachetHQ\Cachet\Models\ComponentGroup;
|
||||
use Exception;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
|
||||
class ComponentGroupController extends AbstractApiController
|
||||
{
|
||||
use DispatchesJobs;
|
||||
|
||||
/**
|
||||
* Get all groups.
|
||||
*
|
||||
@ -93,7 +97,7 @@ class ComponentGroupController extends AbstractApiController
|
||||
*/
|
||||
public function deleteGroup(ComponentGroup $group)
|
||||
{
|
||||
$group->delete();
|
||||
$this->dispatch(new RemoveComponentGroupCommand($group));
|
||||
|
||||
return $this->noContent();
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ namespace CachetHQ\Cachet\Http\Controllers\Dashboard;
|
||||
use AltThree\Validator\ValidationException;
|
||||
use CachetHQ\Cachet\Commands\Component\AddComponentCommand;
|
||||
use CachetHQ\Cachet\Commands\Component\RemoveComponentCommand;
|
||||
use CachetHQ\Cachet\Commands\ComponentGroup\RemoveComponentGroupCommand;
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use CachetHQ\Cachet\Models\ComponentGroup;
|
||||
use CachetHQ\Cachet\Models\Tag;
|
||||
@ -207,11 +208,7 @@ class ComponentController extends Controller
|
||||
*/
|
||||
public function deleteComponentGroupAction(ComponentGroup $group)
|
||||
{
|
||||
$group->components->map(function ($component) {
|
||||
$component->update(['group_id' => 0]);
|
||||
});
|
||||
|
||||
$group->delete();
|
||||
$this->dispatch(new RemoveComponentGroupCommand($group));
|
||||
|
||||
return Redirect::route('dashboard.components.index');
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user