-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathFindUrlCommand.php
More file actions
64 lines (51 loc) · 1.94 KB
/
Copy pathFindUrlCommand.php
File metadata and controls
64 lines (51 loc) · 1.94 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
<?php declare(strict_types=1);
namespace App\Command;
use Ibexa\Contracts\Core\Repository\PermissionResolver;
use Ibexa\Contracts\Core\Repository\URLService;
use Ibexa\Contracts\Core\Repository\UserService;
use Ibexa\Contracts\Core\Repository\Values\URL\Query\Criterion;
use Ibexa\Contracts\Core\Repository\Values\URL\Query\SortClause;
use Ibexa\Contracts\Core\Repository\Values\URL\URLQuery;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
#[AsCommand(
name: 'doc:find_url',
description: 'Finds all valid URLs in the provided Section.'
)]
class FindUrlCommand extends Command
{
private URLService $urlService;
private UserService $userService;
private PermissionResolver $permissionResolver;
public function __construct(URLService $URLService, UserService $userService, PermissionResolver $permissionResolver)
{
$this->urlService = $URLService;
$this->userService = $userService;
$this->permissionResolver = $permissionResolver;
parent::__construct();
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$user = $this->userService->loadUserByLogin('admin');
$this->permissionResolver->setCurrentUserReference($user);
$query = new URLQuery();
$query->filter = new Criterion\LogicalAnd(
[
new Criterion\SectionIdentifier(['standard']),
new Criterion\Validity(true),
]
);
$query->sortClauses = [
new SortClause\URL(SortClause::SORT_DESC),
];
$query->offset = 0;
$query->limit = 25;
$results = $this->urlService->findUrls($query);
foreach ($results->items as $result) {
$output->writeln($result->url);
}
return self::SUCCESS;
}
}