Merge pull request #3704 from CachetHQ/hotfix/tags-syncing

Improved Tags Management
This commit is contained in:
James Brooks
2019-07-13 09:12:23 +01:00
committed by GitHub
27 changed files with 255 additions and 749 deletions
@@ -15,14 +15,10 @@ use AltThree\Validator\ValidationException;
use CachetHQ\Cachet\Bus\Commands\Component\CreateComponentCommand;
use CachetHQ\Cachet\Bus\Commands\Component\RemoveComponentCommand;
use CachetHQ\Cachet\Bus\Commands\Component\UpdateComponentCommand;
use CachetHQ\Cachet\Bus\Commands\Tag\ApplyTagCommand;
use CachetHQ\Cachet\Bus\Commands\Tag\CreateTagCommand;
use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\ComponentGroup;
use GrahamCampbell\Binput\Facades\Binput;
use Illuminate\Routing\Controller;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\View;
/**
@@ -113,7 +109,6 @@ class ComponentController extends Controller
public function updateComponentAction(Component $component)
{
$componentData = Binput::get('component');
$tags = Arr::pull($componentData, 'tags');
try {
$component = execute(new UpdateComponentCommand(
@@ -126,6 +121,7 @@ class ComponentController extends Controller
$componentData['group_id'],
$componentData['enabled'],
null, // Meta data cannot be supplied through the dashboard yet.
$componentData['tags'], // Meta data cannot be supplied through the dashboard yet.
true // Silent since we're not really making changes to the component (this should be optional)
));
} catch (ValidationException $e) {
@@ -135,17 +131,6 @@ class ComponentController extends Controller
->withErrors($e->getMessageBag());
}
$component->tags()->delete();
// The component was added successfully, so now let's deal with the tags.
Collection::make(preg_split('/ ?, ?/', $tags))->map(function ($tag) {
return trim($tag);
})->map(function ($tag) {
return execute(new CreateTagCommand($tag));
})->each(function ($tag) use ($component) {
execute(new ApplyTagCommand($component, $tag));
});
return cachet_redirect('dashboard.components.edit', [$component->id])
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.components.edit.success')));
}
@@ -170,7 +155,6 @@ class ComponentController extends Controller
public function createComponentAction()
{
$componentData = Binput::get('component');
$tags = Arr::pull($componentData, 'tags');
try {
$component = execute(new CreateComponentCommand(
@@ -181,7 +165,8 @@ class ComponentController extends Controller
$componentData['order'],
$componentData['group_id'],
$componentData['enabled'],
null // Meta data cannot be supplied through the dashboard yet.
null, // Meta data cannot be supplied through the dashboard yet.
$componentData['tags']
));
} catch (ValidationException $e) {
return cachet_redirect('dashboard.components.create')
@@ -190,15 +175,6 @@ class ComponentController extends Controller
->withErrors($e->getMessageBag());
}
// The component was added successfully, so now let's deal with the tags.
Collection::make(preg_split('/ ?, ?/', $tags))->map(function ($tag) {
return trim($tag);
})->map(function ($tag) {
return execute(new CreateTagCommand($tag));
})->each(function ($tag) use ($component) {
execute(new ApplyTagCommand($component, $tag));
});
return cachet_redirect('dashboard.components')
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.components.add.success')));
}