-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathSetMainLocationCommand.php
More file actions
58 lines (44 loc) · 2.1 KB
/
SetMainLocationCommand.php
File metadata and controls
58 lines (44 loc) · 2.1 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
<?php declare(strict_types=1);
namespace App\Command;
use Ibexa\Contracts\Core\Repository\ContentService;
use Ibexa\Contracts\Core\Repository\PermissionResolver;
use Ibexa\Contracts\Core\Repository\UserService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class SetMainLocationCommand extends Command
{
private ContentService $contentService;
private UserService $userService;
private PermissionResolver $permissionResolver;
public function __construct(ContentService $contentService, UserService $userService, PermissionResolver $permissionResolver)
{
$this->contentService = $contentService;
$this->userService = $userService;
$this->permissionResolver = $permissionResolver;
parent::__construct('doc:set_main_location');
}
protected function configure(): void
{
$this
->setDescription('Set a Location as content item\'s main')
->setDefinition([
new InputArgument('contentId', InputArgument::REQUIRED, 'The Content ID'),
new InputArgument('locationId', InputArgument::REQUIRED, 'One of the Locations of the Content'),
]);
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$user = $this->userService->loadUserByLogin('admin');
$this->permissionResolver->setCurrentUserReference($user);
$contentId = (int) $input->getArgument('contentId');
$locationId = (int) $input->getArgument('locationId');
$contentInfo = $this->contentService->loadContentInfo($contentId);
$contentUpdateStruct = $this->contentService->newContentMetadataUpdateStruct();
$contentUpdateStruct->mainLocationId = $locationId;
$this->contentService->updateContentMetadata($contentInfo, $contentUpdateStruct);
$output->writeln('Location ' . $locationId . ' is now the main Location for ' . $contentInfo->name);
return self::SUCCESS;
}
}