mirror of
https://github.com/YunoHost-Apps/kanboard_ynh.git
synced 2024-09-03 19:36:17 +02:00
79 lines
2 KiB
Text
79 lines
2 KiB
Text
|
#!/usr/bin/env php
|
||
|
<?php
|
||
|
|
||
|
require __DIR__.'/app/common.php';
|
||
|
|
||
|
use Core\Cli;
|
||
|
use Core\Tool;
|
||
|
use Core\Translator;
|
||
|
use Model\Config;
|
||
|
use Model\Task;
|
||
|
use Model\Notification;
|
||
|
|
||
|
$config = new Config($registry);
|
||
|
|
||
|
// Load translations
|
||
|
$language = $config->get('language', 'en_US');
|
||
|
if ($language !== 'en_US') Translator::load($language);
|
||
|
|
||
|
// Set timezone
|
||
|
date_default_timezone_set($config->get('timezone', 'UTC'));
|
||
|
|
||
|
// Setup CLI
|
||
|
$cli = new Cli;
|
||
|
|
||
|
// Usage
|
||
|
$cli->register('help', function() {
|
||
|
echo 'Kanboard command line interface'.PHP_EOL.'==============================='.PHP_EOL.PHP_EOL;
|
||
|
echo '- Task export to stdout (CSV format): '.$GLOBALS['argv'][0].' export-csv <project_id> <start_date> <end_date>'.PHP_EOL;
|
||
|
echo '- Send notifications for due tasks: '.$GLOBALS['argv'][0].' send-notifications-due-tasks'.PHP_EOL;
|
||
|
});
|
||
|
|
||
|
// CSV Export
|
||
|
$cli->register('export-csv', function() use ($cli, $registry) {
|
||
|
|
||
|
if ($GLOBALS['argc'] !== 5) {
|
||
|
$cli->call($cli->default_command);
|
||
|
}
|
||
|
|
||
|
$project_id = $GLOBALS['argv'][2];
|
||
|
$start_date = $GLOBALS['argv'][3];
|
||
|
$end_date = $GLOBALS['argv'][4];
|
||
|
|
||
|
$taskModel = new Task($registry);
|
||
|
$data = $taskModel->export($project_id, $start_date, $end_date);
|
||
|
|
||
|
if (is_array($data)) {
|
||
|
Tool::csv($data);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
// Send notification for tasks due
|
||
|
$cli->register('send-notifications-due-tasks', function() use ($cli, $registry) {
|
||
|
|
||
|
$notificationModel = new Notification($registry);
|
||
|
$taskModel = new Task($registry);
|
||
|
$tasks = $taskModel->getOverdueTasks();
|
||
|
|
||
|
// Group tasks by project
|
||
|
$projects = array();
|
||
|
|
||
|
foreach ($tasks as $task) {
|
||
|
$projects[$task['project_id']][] = $task;
|
||
|
}
|
||
|
|
||
|
// Send notifications for each project
|
||
|
foreach ($projects as $project_id => $project_tasks) {
|
||
|
|
||
|
$users = $notificationModel->getUsersList($project_id);
|
||
|
|
||
|
$notificationModel->sendEmails(
|
||
|
'notification_task_due',
|
||
|
$users,
|
||
|
array('tasks' => $project_tasks, 'project' => $project_tasks[0]['project_name'])
|
||
|
);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
$cli->execute();
|