-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathFindContentCommand.php
More file actions
53 lines (42 loc) · 1.64 KB
/
Copy pathFindContentCommand.php
File metadata and controls
53 lines (42 loc) · 1.64 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
<?php declare(strict_types=1);
namespace App\Command;
use Ibexa\Contracts\Core\Repository\SearchService;
use Ibexa\Contracts\Core\Repository\Values\Content\LocationQuery;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion;
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_content',
description: 'Lists content belonging to the provided content type.'
)]
class FindContentCommand extends Command
{
private SearchService $searchService;
public function __construct(SearchService $searchService)
{
$this->searchService = $searchService;
parent::__construct();
}
protected function configure(): void
{
$this
->setDefinition([
new InputArgument('contentTypeIdentifier', InputArgument::REQUIRED, 'Content type identifier'),
]);
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$contentTypeIdentifier = $input->getArgument('contentTypeIdentifier');
$query = new LocationQuery();
$query->filter = new Criterion\ContentTypeIdentifier($contentTypeIdentifier);
$result = $this->searchService->findContentInfo($query);
$output->writeln('Found ' . $result->totalCount . ' items');
foreach ($result->searchHits as $searchHit) {
$output->writeln($searchHit->valueObject->name);
}
return self::SUCCESS;
}
}