From af7027ea31a691e2eea6d813f6aa3cf08f8b9d0a Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Tue, 12 Apr 2016 21:26:17 -0400 Subject: Rename CLI classes --- app/Console/TaskTriggerCommand.php | 51 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 app/Console/TaskTriggerCommand.php (limited to 'app/Console/TaskTriggerCommand.php') diff --git a/app/Console/TaskTriggerCommand.php b/app/Console/TaskTriggerCommand.php new file mode 100644 index 00000000..9e9554f9 --- /dev/null +++ b/app/Console/TaskTriggerCommand.php @@ -0,0 +1,51 @@ +setName('trigger:tasks') + ->setDescription('Trigger scheduler event for all tasks'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + foreach ($this->getProjectIds() as $project_id) { + $tasks = $this->taskFinder->getAll($project_id); + $nb_tasks = count($tasks); + + if ($nb_tasks > 0) { + $output->writeln('Trigger task event: project_id='.$project_id.', nb_tasks='.$nb_tasks); + $this->sendEvent($tasks, $project_id); + } + } + } + + private function getProjectIds() + { + $listeners = $this->dispatcher->getListeners(Task::EVENT_DAILY_CRONJOB); + $project_ids = array(); + + foreach ($listeners as $listener) { + $project_ids[] = $listener[0]->getProjectId(); + } + + return array_unique($project_ids); + } + + private function sendEvent(array &$tasks, $project_id) + { + $event = new TaskListEvent(array('project_id' => $project_id)); + $event->setTasks($tasks); + + $this->dispatcher->dispatch(Task::EVENT_DAILY_CRONJOB, $event); + } +} -- cgit v1.2.3