-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcli.php
78 lines (69 loc) · 1.83 KB
/
cli.php
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
75
76
77
78
<?php
use dokuwiki\Extension\CLIPlugin;
use splitbrain\phpcli\Exception;
use splitbrain\phpcli\Options;
class cli_plugin_watchcycle extends CLIPlugin
{
/** @var helper_plugin_watchcycle_db */
protected $dbHelper;
/** @var helper_plugin_watchcycle */
protected $helper;
/**
* Initialize helper plugins
*/
public function __construct()
{
parent::__construct();
$this->dbHelper = plugin_load('helper', 'watchcycle_db');
$this->helper = plugin_load('helper', 'watchcycle');
}
/**
* Register options and arguments on the given $options object
*
* @param Options $options
* @return void
* @throws Exception
*/
protected function setup(Options $options)
{
$options->setHelp('Watchcycle notification dispatcher');
$options->registerCommand('send', 'Notify maintainers if necessary');
}
/**
* Your main program
*
* Arguments and options have been parsed when this is run
*
* @param Options $options
* @return void
*/
protected function main(Options $options)
{
$cmd = $options->getCmd();
switch ($cmd) {
case 'send':
$this->sendNotifications();
break;
default:
$this->error('No command provided');
exit(1);
}
}
/**
* Check and send notifications
*/
protected function sendNotifications()
{
$rows = $this->dbHelper->getAll();
if (!is_array($rows)) {
$this->info('Exiting: no users to notify found.');
return;
}
auth_setup();
foreach ($rows as $row) {
if (!$row['uptodate']) {
$this->helper->informMaintainer($row['maintainer'], $row['page']);
}
}
}
}