-
-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathUpdateComponentGroup.php
More file actions
37 lines (32 loc) · 1.08 KB
/
UpdateComponentGroup.php
File metadata and controls
37 lines (32 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
namespace Cachet\Actions\ComponentGroup;
use Cachet\Data\Requests\ComponentGroup\UpdateComponentGroupRequestData;
use Cachet\Models\ComponentGroup;
use Cachet\Verbs\Events\ComponentGroups\ComponentGroupUpdated;
use Cachet\Verbs\Events\Components\ComponentUpdated;
class UpdateComponentGroup
{
/**
* Handle the action.
*/
public function handle(ComponentGroup $componentGroup, UpdateComponentGroupRequestData $data): ComponentGroup
{
$result = ComponentGroupUpdated::commit(
component_group_id: $componentGroup->id,
name: $data->name,
order: $data->order,
collapsed: $data->collapsed ?? null,
visible: $data->visible,
);
// Assign components to the group via update events
if ($data->components) {
foreach ($data->components as $componentId) {
ComponentUpdated::commit(
component_id: $componentId,
component_group_id: $componentGroup->id,
);
}
}
return $result;
}
}