|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Superdesk Web Publisher Core Bundle. |
|
7
|
|
|
* |
|
8
|
|
|
* Copyright 2019 Sourcefabric z.ú. and contributors. |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please see the |
|
11
|
|
|
* AUTHORS and LICENSE files distributed with this source code. |
|
12
|
|
|
* |
|
13
|
|
|
* @copyright 2019 Sourcefabric z.ú |
|
14
|
|
|
* @license http://www.superdesk.org/license |
|
15
|
|
|
*/ |
|
16
|
|
|
|
|
17
|
|
|
namespace SWP\Bundle\CoreBundle\Command; |
|
18
|
|
|
|
|
19
|
|
|
use FOS\ElasticaBundle\Manager\RepositoryManagerInterface; |
|
20
|
|
|
use SWP\Bundle\ElasticSearchBundle\Criteria\Criteria; |
|
21
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
|
22
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
23
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
24
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
25
|
|
|
|
|
26
|
|
|
class ProcessArticleBodyCommand extends ContainerAwareCommand |
|
|
|
|
|
|
27
|
|
|
{ |
|
28
|
|
|
protected static $defaultName = 'swp:article:process:body'; |
|
29
|
|
|
|
|
30
|
|
|
public function __construct(RepositoryManagerInterface $repositoryManager) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->repositoryManager = $repositoryManager; |
|
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
parent::__construct(); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
protected function configure(): void |
|
38
|
|
|
{ |
|
39
|
|
|
$this |
|
40
|
|
|
->setName(self::$defaultName) |
|
41
|
|
|
->setDescription('Finds articles by term and runs articles body processors on it.') |
|
42
|
|
|
->addArgument('term', InputArgument::REQUIRED, 'Search term.') |
|
43
|
|
|
->addOption('limit', null, InputArgument::OPTIONAL, 'Limit.', 10) |
|
44
|
|
|
->addOption('offset', null, InputArgument::OPTIONAL, 'Offset.', 0) |
|
45
|
|
|
->setHelp(<<<'EOT' |
|
46
|
|
|
The <info>swp:article:process</info> finds articles by given term and runs article's body processors on it. |
|
47
|
|
|
|
|
48
|
|
|
<info>php %command.full_name% term embedded_image</info> |
|
49
|
|
|
|
|
50
|
|
|
<info>term</info> argument is the value of the string by which to find the articles. |
|
51
|
|
|
|
|
52
|
|
|
EOT |
|
53
|
|
|
); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): void |
|
57
|
|
|
{ |
|
58
|
|
|
$term = $input->getArgument('term'); |
|
59
|
|
|
|
|
60
|
|
|
$currentTenant = $this->getContainer()->get('swp_multi_tenancy.tenant_context')->getTenant(); |
|
61
|
|
|
|
|
62
|
|
|
$criteria = Criteria::fromQueryParameters( |
|
63
|
|
|
$term, |
|
64
|
|
|
[ |
|
65
|
|
|
'sort' => ['publishedAt' => 'desc'], |
|
66
|
|
|
'tenantCode' => $currentTenant->getCode(), |
|
67
|
|
|
] |
|
68
|
|
|
); |
|
69
|
|
|
|
|
70
|
|
|
$repository = $this->repositoryManager->getRepository($this->getContainer()->getParameter('swp.model.article.class')); |
|
71
|
|
|
$articles = $repository |
|
72
|
|
|
->findByCriteria($criteria) |
|
73
|
|
|
->getResults((int) $input->getOption('offset'), (int) $input->getOption('limit')); |
|
74
|
|
|
|
|
75
|
|
|
$output->writeln('<bg=green;options=bold>There are total of '.$articles->getTotalHits().' articles.</>'); |
|
76
|
|
|
|
|
77
|
|
|
$articleBodyProcessorChain = $this->getContainer()->get('swp_content_bundle.processor.article_body'); |
|
78
|
|
|
$articleRepository = $this->getContainer()->get('swp.repository.article'); |
|
79
|
|
|
|
|
80
|
|
|
foreach ($articles->toArray() as $article) { |
|
81
|
|
|
foreach ($article->getMedia() as $media) { |
|
82
|
|
|
$articleBodyProcessorChain->process($article, $media); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
$articleRepository->flush(); |
|
87
|
|
|
|
|
88
|
|
|
$output->writeln('<bg=green;options=bold>Done. Processed '.\count($articles->toArray()).' articles.</>'); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.