|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of Jitamin. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (C) Jitamin Team |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Jitamin\Console; |
|
13
|
|
|
|
|
14
|
|
|
use Jitamin\Bus\Event\TaskListEvent; |
|
15
|
|
|
use Jitamin\Model\TaskModel; |
|
16
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
17
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Task trigger command class. |
|
21
|
|
|
*/ |
|
22
|
|
|
class TaskTriggerCommand extends BaseCommand |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* Configure the console command. |
|
26
|
|
|
* |
|
27
|
|
|
* @return void |
|
28
|
|
|
*/ |
|
29
|
|
|
protected function configure() |
|
30
|
|
|
{ |
|
31
|
|
|
$this |
|
32
|
|
|
->setName('trigger:tasks') |
|
33
|
|
|
->setDescription('Trigger scheduler event for all tasks'); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Execute the console command. |
|
38
|
|
|
* |
|
39
|
|
|
* @param InputInterface $output |
|
40
|
|
|
* @param OutputInterface $output |
|
41
|
|
|
* |
|
42
|
|
|
* @return void |
|
43
|
|
|
*/ |
|
44
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
45
|
|
|
{ |
|
46
|
|
|
foreach ($this->getProjectIds() as $project_id) { |
|
47
|
|
|
$tasks = $this->taskFinderModel->getAll($project_id); |
|
|
|
|
|
|
48
|
|
|
$nb_tasks = count($tasks); |
|
49
|
|
|
|
|
50
|
|
|
if ($nb_tasks > 0) { |
|
51
|
|
|
$output->writeln('Trigger task event: project_id='.$project_id.', nb_tasks='.$nb_tasks); |
|
52
|
|
|
$this->sendEvent($tasks, $project_id); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Get the project ids. |
|
59
|
|
|
* |
|
60
|
|
|
* @return int[] |
|
61
|
|
|
*/ |
|
62
|
|
|
private function getProjectIds() |
|
63
|
|
|
{ |
|
64
|
|
|
$listeners = $this->dispatcher->getListeners(TaskModel::EVENT_DAILY_CRONJOB); |
|
|
|
|
|
|
65
|
|
|
$project_ids = []; |
|
66
|
|
|
|
|
67
|
|
|
foreach ($listeners as $listener) { |
|
68
|
|
|
$project_ids[] = $listener[0]->getProjectId(); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
return array_unique($project_ids); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Send the event. |
|
76
|
|
|
* |
|
77
|
|
|
* @param array $tasks |
|
78
|
|
|
* @param int $project_id |
|
79
|
|
|
* |
|
80
|
|
|
* @return void |
|
81
|
|
|
*/ |
|
82
|
|
|
private function sendEvent(array &$tasks, $project_id) |
|
83
|
|
|
{ |
|
84
|
|
|
$event = new TaskListEvent(['project_id' => $project_id]); |
|
85
|
|
|
$event->setTasks($tasks); |
|
86
|
|
|
|
|
87
|
|
|
$this->dispatcher->dispatch(TaskModel::EVENT_DAILY_CRONJOB, $event); |
|
|
|
|
|
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.