-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathAddLocationToContentCommand.php
More file actions
68 lines (52 loc) · 2.4 KB
/
Copy pathAddLocationToContentCommand.php
File metadata and controls
68 lines (52 loc) · 2.4 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
61
62
63
64
65
66
67
68
<?php declare(strict_types=1);
namespace App\Command;
use Ibexa\Contracts\Core\Repository\ContentService;
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:add_location',
description: 'Add a Location to content item and hides it.'
)]
class AddLocationToContentCommand extends Command
{
private ContentService $contentService;
private LocationService $locationService;
private UserService $userService;
private PermissionResolver $permissionResolver;
public function __construct(ContentService $contentService, LocationService $locationService, UserService $userService, PermissionResolver $permissionResolver)
{
$this->contentService = $contentService;
$this->locationService = $locationService;
$this->userService = $userService;
$this->permissionResolver = $permissionResolver;
parent::__construct();
}
protected function configure(): void
{
$this
->setDefinition([
new InputArgument('contentId', InputArgument::REQUIRED, 'Content ID'),
new InputArgument('parentLocationId', InputArgument::REQUIRED, 'Parent Location ID'),
]);
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$user = $this->userService->loadUserByLogin('admin');
$this->permissionResolver->setCurrentUserReference($user);
$parentLocationId = (int) $input->getArgument('parentLocationId');
$contentId = (int) $input->getArgument('contentId');
$locationCreateStruct = $this->locationService->newLocationCreateStruct($parentLocationId);
$locationCreateStruct->priority = 500;
$locationCreateStruct->hidden = true;
$contentInfo = $this->contentService->loadContentInfo($contentId);
$newLocation = $this->locationService->createLocation($contentInfo, $locationCreateStruct);
$output->writeln('Added hidden location ' . $newLocation->id . ' to content item: ' . $contentInfo->name);
return self::SUCCESS;
}
}