-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathMoveContentCommand.php
More file actions
59 lines (47 loc) · 2.1 KB
/
Copy pathMoveContentCommand.php
File metadata and controls
59 lines (47 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
59
<?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:move_content',
description: 'Moves the selected Location with its subtree.'
)]
class MoveContentCommand 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('locationId', InputArgument::REQUIRED, 'Location to copy'),
new InputArgument('targetLocationId', InputArgument::REQUIRED, 'Target to copy or move to'),
]);
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$user = $this->userService->loadUserByLogin('admin');
$this->permissionResolver->setCurrentUserReference($user);
$locationId = (int) $input->getArgument('locationId');
$targetLocationId = (int) $input->getArgument('targetLocationId');
$sourceLocation = $this->locationService->loadLocation($locationId);
$targetLocation = $this->locationService->loadLocation($targetLocationId);
$this->locationService->moveSubtree($sourceLocation, $targetLocation);
$output->writeln('Location ' . $locationId . ' moved to ' . $targetLocationId . ' with its subtree.');
return self::SUCCESS;
}
}