summaryrefslogtreecommitdiff
path: root/app/Console
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-01-27 21:45:37 -0500
committerFrederic Guillot <fred@kanboard.net>2016-01-28 08:40:27 -0500
commit32e4a932c801dfa6c52f6e8211a96bdb7849579d (patch)
tree895d519842c69369713eaf4d8e96b7a3a17c1f3d /app/Console
parent320c7971f606a0c9caa4a20bcfcbc2fe2f6c9c00 (diff)
Added automatic actions based on a daily event
Diffstat (limited to 'app/Console')
-rw-r--r--app/Console/Cronjob.php33
-rw-r--r--app/Console/TaskTrigger.php52
2 files changed, 85 insertions, 0 deletions
diff --git a/app/Console/Cronjob.php b/app/Console/Cronjob.php
new file mode 100644
index 00000000..2b12d93d
--- /dev/null
+++ b/app/Console/Cronjob.php
@@ -0,0 +1,33 @@
+<?php
+
+namespace Kanboard\Console;
+
+use Symfony\Component\Console\Input\ArrayInput;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\Console\Output\NullOutput;
+
+class Cronjob extends Base
+{
+ private $commands = array(
+ 'projects:daily-stats',
+ 'notification:overdue-tasks',
+ 'trigger:tasks',
+ );
+
+ protected function configure()
+ {
+ $this
+ ->setName('cronjob')
+ ->setDescription('Execute daily cronjob');
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ foreach ($this->commands as $command) {
+ $job = $this->getApplication()->find($command);
+ $job->run(new ArrayInput(array('command' => $command)), new NullOutput());
+ }
+ }
+}
diff --git a/app/Console/TaskTrigger.php b/app/Console/TaskTrigger.php
new file mode 100644
index 00000000..000d215a
--- /dev/null
+++ b/app/Console/TaskTrigger.php
@@ -0,0 +1,52 @@
+<?php
+
+namespace Kanboard\Console;
+
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use Kanboard\Model\Task;
+use Kanboard\Event\TaskListEvent;
+
+class TaskTrigger extends Base
+{
+ protected function configure()
+ {
+ $this
+ ->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);
+ }
+}