-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathHideLocationCommand.php
More file actions
60 lines (46 loc) · 1.88 KB
/
Copy pathHideLocationCommand.php
File metadata and controls
60 lines (46 loc) · 1.88 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php declare(strict_types=1);
namespace App\Command;
use Ibexa\Contracts\Core\Repository\LocationService;
use Ibexa\Contracts\Core\Repository\PermissionResolver;
use Ibexa\Contracts\Core\Repository\UserService;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
#[AsCommand(
name: 'doc:hide',
description: 'Hides and reveals again selected Location.'
)]
class HideLocationCommand extends Command
{
private LocationService $locationService;
private UserService $userService;
private PermissionResolver $permissionResolver;
public function __construct(LocationService $locationService, UserService $userService, PermissionResolver $permissionResolver)
{
$this->locationService = $locationService;
$this->userService = $userService;
$this->permissionResolver = $permissionResolver;
parent::__construct();
}
protected function configure(): void
{
$this
->setDefinition([
new InputArgument('location_id', InputArgument::REQUIRED, 'Location ID'),
]);
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$user = $this->userService->loadUserByLogin('admin');
$this->permissionResolver->setCurrentUserReference($user);
$locationId = (int) $input->getArgument('location_id');
$location = $this->locationService->loadLocation($locationId);
$this->locationService->hideLocation($location);
$output->writeln('Location hidden: ' . $locationId);
$this->locationService->unhideLocation($location);
$output->writeln('Location revealed: ' . $locationId);
return self::SUCCESS;
}
}