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/Base.php | 61 ----------- app/Console/BaseCommand.php | 61 +++++++++++ app/Console/Cronjob.php | 32 ------ app/Console/CronjobCommand.php | 32 ++++++ app/Console/LocaleComparator.php | 81 -------------- app/Console/LocaleComparatorCommand.php | 81 ++++++++++++++ app/Console/LocaleSync.php | 53 ---------- app/Console/LocaleSyncCommand.php | 53 ++++++++++ app/Console/ProjectDailyColumnStatsExport.php | 34 ------ .../ProjectDailyColumnStatsExportCommand.php | 34 ++++++ app/Console/ProjectDailyStatsCalculation.php | 28 ----- .../ProjectDailyStatsCalculationCommand.php | 28 +++++ app/Console/SubtaskExport.php | 34 ------ app/Console/SubtaskExportCommand.php | 34 ++++++ app/Console/TaskExport.php | 34 ------ app/Console/TaskExportCommand.php | 34 ++++++ app/Console/TaskOverdueNotification.php | 116 --------------------- app/Console/TaskOverdueNotificationCommand.php | 116 +++++++++++++++++++++ app/Console/TaskTrigger.php | 51 --------- app/Console/TaskTriggerCommand.php | 51 +++++++++ app/Console/TransitionExport.php | 34 ------ app/Console/TransitionExportCommand.php | 34 ++++++ kanboard | 40 +++---- 23 files changed, 578 insertions(+), 578 deletions(-) delete mode 100644 app/Console/Base.php create mode 100644 app/Console/BaseCommand.php delete mode 100644 app/Console/Cronjob.php create mode 100644 app/Console/CronjobCommand.php delete mode 100644 app/Console/LocaleComparator.php create mode 100644 app/Console/LocaleComparatorCommand.php delete mode 100644 app/Console/LocaleSync.php create mode 100644 app/Console/LocaleSyncCommand.php delete mode 100644 app/Console/ProjectDailyColumnStatsExport.php create mode 100644 app/Console/ProjectDailyColumnStatsExportCommand.php delete mode 100644 app/Console/ProjectDailyStatsCalculation.php create mode 100644 app/Console/ProjectDailyStatsCalculationCommand.php delete mode 100644 app/Console/SubtaskExport.php create mode 100644 app/Console/SubtaskExportCommand.php delete mode 100644 app/Console/TaskExport.php create mode 100644 app/Console/TaskExportCommand.php delete mode 100644 app/Console/TaskOverdueNotification.php create mode 100644 app/Console/TaskOverdueNotificationCommand.php delete mode 100644 app/Console/TaskTrigger.php create mode 100644 app/Console/TaskTriggerCommand.php delete mode 100644 app/Console/TransitionExport.php create mode 100644 app/Console/TransitionExportCommand.php diff --git a/app/Console/Base.php b/app/Console/Base.php deleted file mode 100644 index 25d48e44..00000000 --- a/app/Console/Base.php +++ /dev/null @@ -1,61 +0,0 @@ -container = $container; - } - - /** - * Load automatically models - * - * @access public - * @param string $name Model name - * @return mixed - */ - public function __get($name) - { - return $this->container[$name]; - } -} diff --git a/app/Console/BaseCommand.php b/app/Console/BaseCommand.php new file mode 100644 index 00000000..bf86ae0d --- /dev/null +++ b/app/Console/BaseCommand.php @@ -0,0 +1,61 @@ +container = $container; + } + + /** + * Load automatically models + * + * @access public + * @param string $name Model name + * @return mixed + */ + public function __get($name) + { + return $this->container[$name]; + } +} diff --git a/app/Console/Cronjob.php b/app/Console/Cronjob.php deleted file mode 100644 index 3a5c5596..00000000 --- a/app/Console/Cronjob.php +++ /dev/null @@ -1,32 +0,0 @@ -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/CronjobCommand.php b/app/Console/CronjobCommand.php new file mode 100644 index 00000000..dae13af9 --- /dev/null +++ b/app/Console/CronjobCommand.php @@ -0,0 +1,32 @@ +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/LocaleComparator.php b/app/Console/LocaleComparator.php deleted file mode 100644 index 8e5e0904..00000000 --- a/app/Console/LocaleComparator.php +++ /dev/null @@ -1,81 +0,0 @@ -setName('locale:compare') - ->setDescription('Compare application translations with the '.self::REF_LOCALE.' locale'); - } - - protected function execute(InputInterface $input, OutputInterface $output) - { - $strings = array(); - $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator('app')); - $it->rewind(); - - while ($it->valid()) { - if (! $it->isDot() && substr($it->key(), -4) === '.php') { - $strings = array_merge($strings, $this->search($it->key())); - } - - $it->next(); - } - - $this->compare(array_unique($strings)); - } - - public function show(array $strings) - { - foreach ($strings as $string) { - echo " '".str_replace("'", "\'", $string)."' => '',".PHP_EOL; - } - } - - public function compare(array $strings) - { - $reference_file = 'app/Locale/'.self::REF_LOCALE.'/translations.php'; - $reference = include $reference_file; - - echo str_repeat('#', 70).PHP_EOL; - echo 'MISSING STRINGS'.PHP_EOL; - echo str_repeat('#', 70).PHP_EOL; - $this->show(array_diff($strings, array_keys($reference))); - - echo str_repeat('#', 70).PHP_EOL; - echo 'USELESS STRINGS'.PHP_EOL; - echo str_repeat('#', 70).PHP_EOL; - $this->show(array_diff(array_keys($reference), $strings)); - } - - public function search($filename) - { - $content = file_get_contents($filename); - $strings = array(); - - if (preg_match_all('/\b[et]\((\'\K.*?\') *[\)\,]/', $content, $matches) && isset($matches[1])) { - $strings = $matches[1]; - } - - if (preg_match_all('/\bdt\((\'\K.*?\') *[\)\,]/', $content, $matches) && isset($matches[1])) { - $strings = array_merge($strings, $matches[1]); - } - - array_walk($strings, function (&$value) { - $value = trim($value, "'"); - $value = str_replace("\'", "'", $value); - }); - - return $strings; - } -} diff --git a/app/Console/LocaleComparatorCommand.php b/app/Console/LocaleComparatorCommand.php new file mode 100644 index 00000000..de83714f --- /dev/null +++ b/app/Console/LocaleComparatorCommand.php @@ -0,0 +1,81 @@ +setName('locale:compare') + ->setDescription('Compare application translations with the '.self::REF_LOCALE.' locale'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $strings = array(); + $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator('app')); + $it->rewind(); + + while ($it->valid()) { + if (! $it->isDot() && substr($it->key(), -4) === '.php') { + $strings = array_merge($strings, $this->search($it->key())); + } + + $it->next(); + } + + $this->compare(array_unique($strings)); + } + + public function show(array $strings) + { + foreach ($strings as $string) { + echo " '".str_replace("'", "\'", $string)."' => '',".PHP_EOL; + } + } + + public function compare(array $strings) + { + $reference_file = 'app/Locale/'.self::REF_LOCALE.'/translations.php'; + $reference = include $reference_file; + + echo str_repeat('#', 70).PHP_EOL; + echo 'MISSING STRINGS'.PHP_EOL; + echo str_repeat('#', 70).PHP_EOL; + $this->show(array_diff($strings, array_keys($reference))); + + echo str_repeat('#', 70).PHP_EOL; + echo 'USELESS STRINGS'.PHP_EOL; + echo str_repeat('#', 70).PHP_EOL; + $this->show(array_diff(array_keys($reference), $strings)); + } + + public function search($filename) + { + $content = file_get_contents($filename); + $strings = array(); + + if (preg_match_all('/\b[et]\((\'\K.*?\') *[\)\,]/', $content, $matches) && isset($matches[1])) { + $strings = $matches[1]; + } + + if (preg_match_all('/\bdt\((\'\K.*?\') *[\)\,]/', $content, $matches) && isset($matches[1])) { + $strings = array_merge($strings, $matches[1]); + } + + array_walk($strings, function (&$value) { + $value = trim($value, "'"); + $value = str_replace("\'", "'", $value); + }); + + return $strings; + } +} diff --git a/app/Console/LocaleSync.php b/app/Console/LocaleSync.php deleted file mode 100644 index d62b40b5..00000000 --- a/app/Console/LocaleSync.php +++ /dev/null @@ -1,53 +0,0 @@ -setName('locale:sync') - ->setDescription('Synchronize all translations based on the '.self::REF_LOCALE.' locale'); - } - - protected function execute(InputInterface $input, OutputInterface $output) - { - $reference_file = 'app/Locale/'.self::REF_LOCALE.'/translations.php'; - $reference = include $reference_file; - - foreach (new DirectoryIterator('app/Locale') as $fileInfo) { - if (! $fileInfo->isDot() && $fileInfo->isDir() && $fileInfo->getFilename() !== self::REF_LOCALE) { - $filename = 'app/Locale/'.$fileInfo->getFilename().'/translations.php'; - echo $fileInfo->getFilename().' ('.$filename.')'.PHP_EOL; - - file_put_contents($filename, $this->updateFile($reference, $filename)); - } - } - } - - public function updateFile(array $reference, $outdated_file) - { - $outdated = include $outdated_file; - - $output = ' $value) { - if (! empty($outdated[$key])) { - $output .= " '".str_replace("'", "\'", $key)."' => '".str_replace("'", "\'", $outdated[$key])."',\n"; - } else { - $output .= " // '".str_replace("'", "\'", $key)."' => '',\n"; - } - } - - $output .= ");\n"; - return $output; - } -} diff --git a/app/Console/LocaleSyncCommand.php b/app/Console/LocaleSyncCommand.php new file mode 100644 index 00000000..11cfbde0 --- /dev/null +++ b/app/Console/LocaleSyncCommand.php @@ -0,0 +1,53 @@ +setName('locale:sync') + ->setDescription('Synchronize all translations based on the '.self::REF_LOCALE.' locale'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $reference_file = 'app/Locale/'.self::REF_LOCALE.'/translations.php'; + $reference = include $reference_file; + + foreach (new DirectoryIterator('app/Locale') as $fileInfo) { + if (! $fileInfo->isDot() && $fileInfo->isDir() && $fileInfo->getFilename() !== self::REF_LOCALE) { + $filename = 'app/Locale/'.$fileInfo->getFilename().'/translations.php'; + echo $fileInfo->getFilename().' ('.$filename.')'.PHP_EOL; + + file_put_contents($filename, $this->updateFile($reference, $filename)); + } + } + } + + public function updateFile(array $reference, $outdated_file) + { + $outdated = include $outdated_file; + + $output = ' $value) { + if (! empty($outdated[$key])) { + $output .= " '".str_replace("'", "\'", $key)."' => '".str_replace("'", "\'", $outdated[$key])."',\n"; + } else { + $output .= " // '".str_replace("'", "\'", $key)."' => '',\n"; + } + } + + $output .= ");\n"; + return $output; + } +} diff --git a/app/Console/ProjectDailyColumnStatsExport.php b/app/Console/ProjectDailyColumnStatsExport.php deleted file mode 100644 index 2513fbf1..00000000 --- a/app/Console/ProjectDailyColumnStatsExport.php +++ /dev/null @@ -1,34 +0,0 @@ -setName('export:daily-project-column-stats') - ->setDescription('Daily project column stats CSV export (number of tasks per column and per day)') - ->addArgument('project_id', InputArgument::REQUIRED, 'Project id') - ->addArgument('start_date', InputArgument::REQUIRED, 'Start date (YYYY-MM-DD)') - ->addArgument('end_date', InputArgument::REQUIRED, 'End date (YYYY-MM-DD)'); - } - - protected function execute(InputInterface $input, OutputInterface $output) - { - $data = $this->projectDailyColumnStats->getAggregatedMetrics( - $input->getArgument('project_id'), - $input->getArgument('start_date'), - $input->getArgument('end_date') - ); - - if (is_array($data)) { - Csv::output($data); - } - } -} diff --git a/app/Console/ProjectDailyColumnStatsExportCommand.php b/app/Console/ProjectDailyColumnStatsExportCommand.php new file mode 100644 index 00000000..ced1a374 --- /dev/null +++ b/app/Console/ProjectDailyColumnStatsExportCommand.php @@ -0,0 +1,34 @@ +setName('export:daily-project-column-stats') + ->setDescription('Daily project column stats CSV export (number of tasks per column and per day)') + ->addArgument('project_id', InputArgument::REQUIRED, 'Project id') + ->addArgument('start_date', InputArgument::REQUIRED, 'Start date (YYYY-MM-DD)') + ->addArgument('end_date', InputArgument::REQUIRED, 'End date (YYYY-MM-DD)'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $data = $this->projectDailyColumnStats->getAggregatedMetrics( + $input->getArgument('project_id'), + $input->getArgument('start_date'), + $input->getArgument('end_date') + ); + + if (is_array($data)) { + Csv::output($data); + } + } +} diff --git a/app/Console/ProjectDailyStatsCalculation.php b/app/Console/ProjectDailyStatsCalculation.php deleted file mode 100644 index 9884cc1c..00000000 --- a/app/Console/ProjectDailyStatsCalculation.php +++ /dev/null @@ -1,28 +0,0 @@ -setName('projects:daily-stats') - ->setDescription('Calculate daily statistics for all projects'); - } - - protected function execute(InputInterface $input, OutputInterface $output) - { - $projects = $this->project->getAllByStatus(Project::ACTIVE); - - foreach ($projects as $project) { - $output->writeln('Run calculation for '.$project['name']); - $this->projectDailyColumnStats->updateTotals($project['id'], date('Y-m-d')); - $this->projectDailyStats->updateTotals($project['id'], date('Y-m-d')); - } - } -} diff --git a/app/Console/ProjectDailyStatsCalculationCommand.php b/app/Console/ProjectDailyStatsCalculationCommand.php new file mode 100644 index 00000000..5b898f02 --- /dev/null +++ b/app/Console/ProjectDailyStatsCalculationCommand.php @@ -0,0 +1,28 @@ +setName('projects:daily-stats') + ->setDescription('Calculate daily statistics for all projects'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $projects = $this->project->getAllByStatus(Project::ACTIVE); + + foreach ($projects as $project) { + $output->writeln('Run calculation for '.$project['name']); + $this->projectDailyColumnStats->updateTotals($project['id'], date('Y-m-d')); + $this->projectDailyStats->updateTotals($project['id'], date('Y-m-d')); + } + } +} diff --git a/app/Console/SubtaskExport.php b/app/Console/SubtaskExport.php deleted file mode 100644 index aaa95276..00000000 --- a/app/Console/SubtaskExport.php +++ /dev/null @@ -1,34 +0,0 @@ -setName('export:subtasks') - ->setDescription('Subtasks CSV export') - ->addArgument('project_id', InputArgument::REQUIRED, 'Project id') - ->addArgument('start_date', InputArgument::REQUIRED, 'Start date (YYYY-MM-DD)') - ->addArgument('end_date', InputArgument::REQUIRED, 'End date (YYYY-MM-DD)'); - } - - protected function execute(InputInterface $input, OutputInterface $output) - { - $data = $this->subtaskExport->export( - $input->getArgument('project_id'), - $input->getArgument('start_date'), - $input->getArgument('end_date') - ); - - if (is_array($data)) { - Csv::output($data); - } - } -} diff --git a/app/Console/SubtaskExportCommand.php b/app/Console/SubtaskExportCommand.php new file mode 100644 index 00000000..986af1a4 --- /dev/null +++ b/app/Console/SubtaskExportCommand.php @@ -0,0 +1,34 @@ +setName('export:subtasks') + ->setDescription('Subtasks CSV export') + ->addArgument('project_id', InputArgument::REQUIRED, 'Project id') + ->addArgument('start_date', InputArgument::REQUIRED, 'Start date (YYYY-MM-DD)') + ->addArgument('end_date', InputArgument::REQUIRED, 'End date (YYYY-MM-DD)'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $data = $this->subtaskExport->export( + $input->getArgument('project_id'), + $input->getArgument('start_date'), + $input->getArgument('end_date') + ); + + if (is_array($data)) { + Csv::output($data); + } + } +} diff --git a/app/Console/TaskExport.php b/app/Console/TaskExport.php deleted file mode 100644 index 4515bf95..00000000 --- a/app/Console/TaskExport.php +++ /dev/null @@ -1,34 +0,0 @@ -setName('export:tasks') - ->setDescription('Tasks CSV export') - ->addArgument('project_id', InputArgument::REQUIRED, 'Project id') - ->addArgument('start_date', InputArgument::REQUIRED, 'Start date (YYYY-MM-DD)') - ->addArgument('end_date', InputArgument::REQUIRED, 'End date (YYYY-MM-DD)'); - } - - protected function execute(InputInterface $input, OutputInterface $output) - { - $data = $this->taskExport->export( - $input->getArgument('project_id'), - $input->getArgument('start_date'), - $input->getArgument('end_date') - ); - - if (is_array($data)) { - Csv::output($data); - } - } -} diff --git a/app/Console/TaskExportCommand.php b/app/Console/TaskExportCommand.php new file mode 100644 index 00000000..789245bc --- /dev/null +++ b/app/Console/TaskExportCommand.php @@ -0,0 +1,34 @@ +setName('export:tasks') + ->setDescription('Tasks CSV export') + ->addArgument('project_id', InputArgument::REQUIRED, 'Project id') + ->addArgument('start_date', InputArgument::REQUIRED, 'Start date (YYYY-MM-DD)') + ->addArgument('end_date', InputArgument::REQUIRED, 'End date (YYYY-MM-DD)'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $data = $this->taskExport->export( + $input->getArgument('project_id'), + $input->getArgument('start_date'), + $input->getArgument('end_date') + ); + + if (is_array($data)) { + Csv::output($data); + } + } +} diff --git a/app/Console/TaskOverdueNotification.php b/app/Console/TaskOverdueNotification.php deleted file mode 100644 index 43be4df8..00000000 --- a/app/Console/TaskOverdueNotification.php +++ /dev/null @@ -1,116 +0,0 @@ -setName('notification:overdue-tasks') - ->setDescription('Send notifications for overdue tasks') - ->addOption('show', null, InputOption::VALUE_NONE, 'Show sent overdue tasks'); - } - - protected function execute(InputInterface $input, OutputInterface $output) - { - $tasks = $this->sendOverdueTaskNotifications(); - - if ($input->getOption('show')) { - $this->showTable($output, $tasks); - } - } - - public function showTable(OutputInterface $output, array $tasks) - { - $rows = array(); - - foreach ($tasks as $task) { - $rows[] = array( - $task['id'], - $task['title'], - date('Y-m-d', $task['date_due']), - $task['project_id'], - $task['project_name'], - $task['assignee_name'] ?: $task['assignee_username'], - ); - } - - $table = new Table($output); - $table - ->setHeaders(array('Id', 'Title', 'Due date', 'Project Id', 'Project name', 'Assignee')) - ->setRows($rows) - ->render(); - } - - /** - * Send overdue tasks - * - * @access public - */ - public function sendOverdueTaskNotifications() - { - $tasks = $this->taskFinder->getOverdueTasks(); - - foreach ($this->groupByColumn($tasks, 'project_id') as $project_id => $project_tasks) { - $users = $this->userNotification->getUsersWithNotificationEnabled($project_id); - - foreach ($users as $user) { - $this->sendUserOverdueTaskNotifications($user, $project_tasks); - } - } - - return $tasks; - } - - /** - * Send overdue tasks for a given user - * - * @access public - * @param array $user - * @param array $tasks - */ - public function sendUserOverdueTaskNotifications(array $user, array $tasks) - { - $user_tasks = array(); - - foreach ($tasks as $task) { - if ($this->userNotificationFilter->shouldReceiveNotification($user, array('task' => $task))) { - $user_tasks[] = $task; - } - } - - if (! empty($user_tasks)) { - $this->userNotification->sendUserNotification( - $user, - Task::EVENT_OVERDUE, - array('tasks' => $user_tasks, 'project_name' => $tasks[0]['project_name']) - ); - } - } - - /** - * Group a collection of records by a column - * - * @access public - * @param array $collection - * @param string $column - * @return array - */ - public function groupByColumn(array $collection, $column) - { - $result = array(); - - foreach ($collection as $item) { - $result[$item[$column]][] = $item; - } - - return $result; - } -} diff --git a/app/Console/TaskOverdueNotificationCommand.php b/app/Console/TaskOverdueNotificationCommand.php new file mode 100644 index 00000000..7d176ab1 --- /dev/null +++ b/app/Console/TaskOverdueNotificationCommand.php @@ -0,0 +1,116 @@ +setName('notification:overdue-tasks') + ->setDescription('Send notifications for overdue tasks') + ->addOption('show', null, InputOption::VALUE_NONE, 'Show sent overdue tasks'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $tasks = $this->sendOverdueTaskNotifications(); + + if ($input->getOption('show')) { + $this->showTable($output, $tasks); + } + } + + public function showTable(OutputInterface $output, array $tasks) + { + $rows = array(); + + foreach ($tasks as $task) { + $rows[] = array( + $task['id'], + $task['title'], + date('Y-m-d', $task['date_due']), + $task['project_id'], + $task['project_name'], + $task['assignee_name'] ?: $task['assignee_username'], + ); + } + + $table = new Table($output); + $table + ->setHeaders(array('Id', 'Title', 'Due date', 'Project Id', 'Project name', 'Assignee')) + ->setRows($rows) + ->render(); + } + + /** + * Send overdue tasks + * + * @access public + */ + public function sendOverdueTaskNotifications() + { + $tasks = $this->taskFinder->getOverdueTasks(); + + foreach ($this->groupByColumn($tasks, 'project_id') as $project_id => $project_tasks) { + $users = $this->userNotification->getUsersWithNotificationEnabled($project_id); + + foreach ($users as $user) { + $this->sendUserOverdueTaskNotifications($user, $project_tasks); + } + } + + return $tasks; + } + + /** + * Send overdue tasks for a given user + * + * @access public + * @param array $user + * @param array $tasks + */ + public function sendUserOverdueTaskNotifications(array $user, array $tasks) + { + $user_tasks = array(); + + foreach ($tasks as $task) { + if ($this->userNotificationFilter->shouldReceiveNotification($user, array('task' => $task))) { + $user_tasks[] = $task; + } + } + + if (! empty($user_tasks)) { + $this->userNotification->sendUserNotification( + $user, + Task::EVENT_OVERDUE, + array('tasks' => $user_tasks, 'project_name' => $tasks[0]['project_name']) + ); + } + } + + /** + * Group a collection of records by a column + * + * @access public + * @param array $collection + * @param string $column + * @return array + */ + public function groupByColumn(array $collection, $column) + { + $result = array(); + + foreach ($collection as $item) { + $result[$item[$column]][] = $item; + } + + return $result; + } +} diff --git a/app/Console/TaskTrigger.php b/app/Console/TaskTrigger.php deleted file mode 100644 index 8d707211..00000000 --- a/app/Console/TaskTrigger.php +++ /dev/null @@ -1,51 +0,0 @@ -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); - } -} 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); + } +} diff --git a/app/Console/TransitionExport.php b/app/Console/TransitionExport.php deleted file mode 100644 index d9f805a4..00000000 --- a/app/Console/TransitionExport.php +++ /dev/null @@ -1,34 +0,0 @@ -setName('export:transitions') - ->setDescription('Task transitions CSV export') - ->addArgument('project_id', InputArgument::REQUIRED, 'Project id') - ->addArgument('start_date', InputArgument::REQUIRED, 'Start date (YYYY-MM-DD)') - ->addArgument('end_date', InputArgument::REQUIRED, 'End date (YYYY-MM-DD)'); - } - - protected function execute(InputInterface $input, OutputInterface $output) - { - $data = $this->transitionExport->export( - $input->getArgument('project_id'), - $input->getArgument('start_date'), - $input->getArgument('end_date') - ); - - if (is_array($data)) { - Csv::output($data); - } - } -} diff --git a/app/Console/TransitionExportCommand.php b/app/Console/TransitionExportCommand.php new file mode 100644 index 00000000..265757b3 --- /dev/null +++ b/app/Console/TransitionExportCommand.php @@ -0,0 +1,34 @@ +setName('export:transitions') + ->setDescription('Task transitions CSV export') + ->addArgument('project_id', InputArgument::REQUIRED, 'Project id') + ->addArgument('start_date', InputArgument::REQUIRED, 'Start date (YYYY-MM-DD)') + ->addArgument('end_date', InputArgument::REQUIRED, 'End date (YYYY-MM-DD)'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $data = $this->transitionExport->export( + $input->getArgument('project_id'), + $input->getArgument('start_date'), + $input->getArgument('end_date') + ); + + if (is_array($data)) { + Csv::output($data); + } + } +} diff --git a/kanboard b/kanboard index 5046181d..8ac49d79 100755 --- a/kanboard +++ b/kanboard @@ -5,28 +5,28 @@ require __DIR__.'/app/common.php'; use Symfony\Component\Console\Application; use Symfony\Component\EventDispatcher\Event; -use Kanboard\Console\TaskOverdueNotification; -use Kanboard\Console\SubtaskExport; -use Kanboard\Console\TaskExport; -use Kanboard\Console\ProjectDailyStatsCalculation; -use Kanboard\Console\ProjectDailyColumnStatsExport; -use Kanboard\Console\TransitionExport; -use Kanboard\Console\LocaleSync; -use Kanboard\Console\LocaleComparator; -use Kanboard\Console\TaskTrigger; -use Kanboard\Console\Cronjob; +use Kanboard\Console\TaskOverdueNotificationCommand; +use Kanboard\Console\SubtaskExportCommand; +use Kanboard\Console\TaskExportCommand; +use Kanboard\Console\ProjectDailyStatsCalculationCommand; +use Kanboard\Console\ProjectDailyColumnStatsExportCommand; +use Kanboard\Console\TransitionExportCommand; +use Kanboard\Console\LocaleSyncCommand; +use Kanboard\Console\LocaleComparatorCommand; +use Kanboard\Console\TaskTriggerCommand; +use Kanboard\Console\CronjobCommand; $container['dispatcher']->dispatch('app.bootstrap', new Event); $application = new Application('Kanboard', APP_VERSION); -$application->add(new TaskOverdueNotification($container)); -$application->add(new SubtaskExport($container)); -$application->add(new TaskExport($container)); -$application->add(new ProjectDailyStatsCalculation($container)); -$application->add(new ProjectDailyColumnStatsExport($container)); -$application->add(new TransitionExport($container)); -$application->add(new LocaleSync($container)); -$application->add(new LocaleComparator($container)); -$application->add(new TaskTrigger($container)); -$application->add(new Cronjob($container)); +$application->add(new TaskOverdueNotificationCommand($container)); +$application->add(new SubtaskExportCommand($container)); +$application->add(new TaskExportCommand($container)); +$application->add(new ProjectDailyStatsCalculationCommand($container)); +$application->add(new ProjectDailyColumnStatsExportCommand($container)); +$application->add(new TransitionExportCommand($container)); +$application->add(new LocaleSyncCommand($container)); +$application->add(new LocaleComparatorCommand($container)); +$application->add(new TaskTriggerCommand($container)); +$application->add(new CronjobCommand($container)); $application->run(); -- cgit v1.2.3