summaryrefslogtreecommitdiff
path: root/kanboard
blob: 3e0cef3df3373395c2ff5c3df7ce061c33e506d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env php
<?php

require __DIR__.'/app/common.php';

use Core\Cli;
use Core\Tool;
use Model\Config;
use Model\Task;
use Model\TaskFinder;
use Model\TaskExport;
use Model\Notification;

$config = new Config($container);
$config->setupTranslations();
$config->setupTimezone();

// 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, $container) {

    if ($GLOBALS['argc'] !== 5) {
        $cli->call($cli->default_command);
    }

    $project_id = $GLOBALS['argv'][2];
    $start_date = $GLOBALS['argv'][3];
    $end_date = $GLOBALS['argv'][4];

    $taskExport = new TaskExport($container);
    $data = $taskExport->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, $container) {

    $notificationModel = new Notification($container);
    $taskModel = new TaskFinder($container);
    $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();