-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathFindComplexCommand.php
More file actions
74 lines (61 loc) · 2.6 KB
/
Copy pathFindComplexCommand.php
File metadata and controls
74 lines (61 loc) · 2.6 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
69
70
71
72
73
74
<?php declare(strict_types=1);
namespace App\Command;
use Ibexa\Contracts\Core\Repository\LocationService;
use Ibexa\Contracts\Core\Repository\SearchService;
use Ibexa\Contracts\Core\Repository\Values\Content\LocationQuery;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\SortClause;
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:find_complex',
description: 'Lists content belonging to the provided content type.'
)]
class FindComplexCommand extends Command
{
private SearchService $searchService;
private LocationService $locationService;
public function __construct(SearchService $searchService, LocationService $locationService)
{
$this->searchService = $searchService;
$this->locationService = $locationService;
parent::__construct();
}
protected function configure(): void
{
$this
->setDefinition([
new InputArgument('locationId', InputArgument::REQUIRED, ''),
new InputArgument('contentTypeIdentifier', InputArgument::REQUIRED, 'Content type identifier'),
new InputArgument('text', InputArgument::REQUIRED, ''),
]);
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$locationId = (int) $input->getArgument('locationId');
$contentTypeIdentifier = $input->getArgument('contentTypeIdentifier');
$text = $input->getArgument('text');
$query = new LocationQuery();
$query->query = new Criterion\LogicalAnd([
new Criterion\Subtree($this->locationService->loadLocation($locationId)->pathString),
new Criterion\ContentTypeIdentifier($contentTypeIdentifier),
new Criterion\FullText($text),
new Criterion\LogicalNot(
new Criterion\SectionIdentifier('Media')
),
]);
$query->sortClauses = [
new SortClause\DatePublished(LocationQuery::SORT_ASC),
new SortClause\ContentName(LocationQuery::SORT_DESC),
];
$result = $this->searchService->findContentInfo($query);
$output->writeln('Found ' . $result->totalCount . ' items');
foreach ($result->searchHits as $searchHit) {
$output->writeln($searchHit->valueObject->name);
}
return self::SUCCESS;
}
}