1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dtc\QueueBundle\ORM; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\EntityManager; |
6
|
|
|
use Dtc\GridBundle\Grid\Column\GridColumn; |
7
|
|
|
use Dtc\GridBundle\Grid\Source\EntityGridSource; |
8
|
|
|
use Dtc\QueueBundle\Model\BaseJob; |
9
|
|
|
|
10
|
|
|
class LiveJobsGridSource extends EntityGridSource |
11
|
|
|
{ |
12
|
|
|
protected $jobManager; |
13
|
|
|
protected $running = false; |
14
|
|
|
|
15
|
2 |
|
public function getId() |
16
|
|
|
{ |
17
|
2 |
|
return 'dtc_queue.grid_source.jobs_'.($this->isRunning() ? 'running' : 'waiting').'.orm'; |
18
|
|
|
} |
19
|
|
|
|
20
|
9 |
|
public function __construct(JobManager $jobManager) |
21
|
|
|
{ |
22
|
9 |
|
$this->jobManager = $jobManager; |
23
|
|
|
/** @var EntityManager $entityManager */ |
24
|
9 |
|
$entityManager = $jobManager->getObjectManager(); |
25
|
9 |
|
parent::__construct($entityManager, $jobManager->getJobClass()); |
26
|
9 |
|
} |
27
|
|
|
|
28
|
2 |
|
public function getColumns() |
29
|
|
|
{ |
30
|
2 |
|
if ($columns = parent::getColumns()) { |
31
|
2 |
|
return $columns; |
32
|
|
|
} |
33
|
2 |
|
$this->autoDiscoverColumns(); |
34
|
|
|
|
35
|
2 |
|
return parent::getColumns(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param bool $flag |
40
|
|
|
*/ |
41
|
9 |
|
public function setRunning($flag) |
42
|
|
|
{ |
43
|
9 |
|
$this->running = $flag; |
44
|
9 |
|
} |
45
|
|
|
|
46
|
2 |
|
public function isRunning() |
47
|
|
|
{ |
48
|
2 |
|
return $this->running; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
protected function getRunningQueryBuilder() |
52
|
|
|
{ |
53
|
|
|
/** @var EntityManager $entityManager */ |
54
|
|
|
$entityManager = $this->jobManager->getObjectManager(); |
55
|
|
|
$queryBuilder = $entityManager->createQueryBuilder()->add('select', 'j'); |
|
|
|
|
56
|
|
|
$queryBuilder->from($this->jobManager->getJobClass(), 'j'); |
57
|
|
|
$queryBuilder->where('j.status = :status')->setParameter(':status', BaseJob::STATUS_RUNNING); |
58
|
|
|
$queryBuilder->orderBy('j.startedAt', 'DESC'); |
59
|
|
|
$queryBuilder->setFirstResult($this->offset) |
60
|
|
|
->setMaxResults($this->limit); |
61
|
|
|
|
62
|
|
|
return $queryBuilder; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
View Code Duplication |
protected function getQueryBuilder() |
|
|
|
|
66
|
|
|
{ |
67
|
|
|
if ($this->isRunning()) { |
68
|
|
|
return $this->getRunningQueryBuilder(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
$queryBuilder = $this->jobManager->getJobQueryBuilder(); |
72
|
|
|
$queryBuilder->add('select', 'j'); |
|
|
|
|
73
|
|
|
$queryBuilder->setFirstResult($this->offset) |
74
|
|
|
->setMaxResults($this->limit); |
75
|
|
|
|
76
|
|
|
return $queryBuilder; |
77
|
|
|
} |
78
|
|
|
|
79
|
2 |
View Code Duplication |
public function autoDiscoverColumns() |
|
|
|
|
80
|
|
|
{ |
81
|
2 |
|
parent::autoDiscoverColumns(); |
82
|
2 |
|
if ($this->columns) { |
|
|
|
|
83
|
2 |
|
foreach ($this->columns as $column) { |
84
|
2 |
|
if ($column instanceof GridColumn) { |
85
|
2 |
|
$column->setOption('sortable', false); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
} |
89
|
2 |
|
} |
90
|
|
|
|
91
|
2 |
|
public function getDefaultSort() |
92
|
|
|
{ |
93
|
2 |
|
return null; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function getCount() |
97
|
|
|
{ |
98
|
|
|
$qb = $this->getQueryBuilder(); |
99
|
|
|
$qb->add('select', 'count(j)') |
|
|
|
|
100
|
|
|
->setFirstResult(null) |
101
|
|
|
->setMaxResults(null); |
102
|
|
|
|
103
|
|
|
return $qb->getQuery() |
104
|
|
|
->getSingleScalarResult(); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
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: