|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* YAWIK |
|
4
|
|
|
* |
|
5
|
|
|
* @filesource |
|
6
|
|
|
* @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de) |
|
7
|
|
|
* @license MIT |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Solr\Controller; |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
use Core\Console\ProgressBar; |
|
14
|
|
|
use Jobs\Repository\Job as JobRepository; |
|
15
|
|
|
use SolrClient; |
|
16
|
|
|
use Zend\Mvc\Controller\AbstractActionController; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @author Anthonius Munthi <[email protected]> |
|
20
|
|
|
* @author Miroslav Fedeleš <[email protected]> |
|
21
|
|
|
* @since 0.26 |
|
22
|
|
|
* @package Solr\Controller |
|
23
|
|
|
*/ |
|
24
|
|
|
class ConsoleController extends AbstractActionController |
|
25
|
|
|
{ |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var SolrClient |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $solrClient; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var JobRepository |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $jobRepository; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var callable |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $progressBarFactory; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param SolrClient $solrClient |
|
44
|
|
|
* @param JobRepository $jobRepository |
|
45
|
|
|
* @param callable $progressBarFactory |
|
46
|
|
|
* @since 0.27 |
|
47
|
|
|
*/ |
|
48
|
|
|
public function __construct(SolrClient $solrClient, JobRepository $jobRepository, callable $progressBarFactory) |
|
49
|
|
|
{ |
|
50
|
|
|
$this->solrClient = $solrClient; |
|
51
|
|
|
$this->jobRepository = $jobRepository; |
|
52
|
|
|
$this->progressBarFactory = $progressBarFactory; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function activeJobIndexAction() |
|
56
|
|
|
{ |
|
57
|
|
|
$jobs = $this->jobRepository->findActiveJob(); |
|
58
|
|
|
$count = $jobs->count(); |
|
59
|
|
|
|
|
60
|
|
|
// check if there is any active job |
|
61
|
|
|
if (0 === $count) { |
|
62
|
|
|
return 'There is no active job'.PHP_EOL; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
$i = 1; |
|
66
|
|
|
$progressBarFactory = $this->progressBarFactory; |
|
67
|
|
|
$progressBar = $progressBarFactory($count); |
|
68
|
|
|
$entityToDocument = new \Solr\Filter\EntityToDocument\Job(); |
|
69
|
|
|
|
|
70
|
|
|
// add jobs in the Solr index |
|
71
|
|
|
foreach ($jobs as $job) { |
|
72
|
|
|
$document = $entityToDocument->filter($job); |
|
|
|
|
|
|
73
|
|
|
$this->solrClient->addDocument($document); |
|
74
|
|
|
$progressBar->update($i, 'Job ' . $i . ' / ' . $count); |
|
75
|
|
|
$i++; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
$this->solrClient->commit(); |
|
79
|
|
|
$this->solrClient->optimize(); |
|
80
|
|
|
|
|
81
|
|
|
return PHP_EOL; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @return callable |
|
86
|
|
|
*/ |
|
87
|
|
|
public function getProgressBarFactory() |
|
88
|
|
|
{ |
|
89
|
|
|
return $this->progressBarFactory; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
} |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: