|
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 SWP\Bundle\ElasticSearchBundle\Criteria\Criteria; |
|
20
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
|
21
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
22
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
23
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
24
|
|
|
|
|
25
|
|
|
class ProcessArticleBodyCommand extends ContainerAwareCommand |
|
26
|
|
|
{ |
|
27
|
|
|
protected static $defaultName = 'swp:article:process:body'; |
|
28
|
|
|
|
|
29
|
|
|
public function __construct() |
|
30
|
|
|
{ |
|
31
|
|
|
parent::__construct(); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
protected function configure(): void |
|
35
|
|
|
{ |
|
36
|
|
|
$this |
|
37
|
|
|
->setName(self::$defaultName) |
|
38
|
|
|
->setDescription('Finds articles by term and runs articles body processors on it.') |
|
39
|
|
|
->addArgument('term', InputArgument::REQUIRED, 'Search term.') |
|
40
|
|
|
->addOption('limit', null, InputArgument::OPTIONAL, 'Limit.', 10) |
|
41
|
|
|
->addOption('offset', null, InputArgument::OPTIONAL, 'Offset.', 0) |
|
42
|
|
|
->setHelp(<<<'EOT' |
|
43
|
|
|
The <info>swp:article:process</info> finds articles by given term and runs article's body processors on it. |
|
44
|
|
|
|
|
45
|
|
|
<info>php %command.full_name% term embedded_image</info> |
|
46
|
|
|
|
|
47
|
|
|
<info>term</info> argument is the value of the string by which to find the articles. |
|
48
|
|
|
|
|
49
|
|
|
EOT |
|
50
|
|
|
); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): void |
|
54
|
|
|
{ |
|
55
|
|
|
$term = $input->getArgument('term'); |
|
56
|
|
|
|
|
57
|
|
|
$currentTenant = $this->getContainer()->get('swp_multi_tenancy.tenant_context')->getTenant(); |
|
58
|
|
|
|
|
59
|
|
|
$criteria = Criteria::fromQueryParameters( |
|
60
|
|
|
$term, |
|
61
|
|
|
[ |
|
62
|
|
|
'sort' => ['publishedAt' => 'desc'], |
|
63
|
|
|
'tenantCode' => $currentTenant->getCode(), |
|
64
|
|
|
] |
|
65
|
|
|
); |
|
66
|
|
|
|
|
67
|
|
|
$repositoryManager = $this->getContainer()->get('fos_elastica.manager'); |
|
68
|
|
|
$repository = $repositoryManager->getRepository($this->getContainer()->getParameter('swp.model.article.class')); |
|
69
|
|
|
$articles = $repository |
|
70
|
|
|
->findByCriteria($criteria) |
|
71
|
|
|
->getResults((int) $input->getOption('offset'), (int) $input->getOption('limit')); |
|
72
|
|
|
|
|
73
|
|
|
$output->writeln('<bg=green;options=bold>There are total of '.$articles->getTotalHits().' articles.</>'); |
|
74
|
|
|
|
|
75
|
|
|
$articleBodyProcessorChain = $this->getContainer()->get('swp_content_bundle.processor.article_body'); |
|
76
|
|
|
$articleRepository = $this->getContainer()->get('swp.repository.article'); |
|
77
|
|
|
|
|
78
|
|
|
foreach ($articles->toArray() as $article) { |
|
79
|
|
|
foreach ($article->getMedia() as $media) { |
|
80
|
|
|
$articleBodyProcessorChain->process($article, $media); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
$articleRepository->flush(); |
|
85
|
|
|
|
|
86
|
|
|
$output->writeln('<bg=green;options=bold>Done. Processed '.\count($articles->toArray()).' articles.</>'); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|