3 require_once 'Pman/Roo.php';
5 class Pman_Admin_Report_SendEventErrors extends Pman_Roo
7 static $cli_desc = "Send event errors occured in the last 24 hours";
9 static $cli_opts = array(
11 'desc' => 'group to send to',
18 'desc' => 'list of actions to exclude from report',
25 'desc' => 'email subject',
32 'desc' => 'mail helo to use',
39 'desc' => 'mail host to use',
47 'desc' => 'list the current actions in the database',
57 $ff = HTML_FlexyFramework::get();
66 function get($args, $opts)
70 if(empty($this->opts['group'])){
71 $this->jerr('Missing group - try add [-t {group name}]');
74 $rcpts = DB_DataObject::factory('groups')->lookupMembers("{$this->opts['group']}",'email');
77 $this->jerr("{$this->opts['group']} does not has any memeber");
80 $events = DB_DataObject::factory('Events');
83 DISTINCT(Events.action) AS action,
84 COUNT(Events.id) AS total
87 $events->whereAdd("Events.event_when > NOW() - INTERVAL 1 DAY");
89 if(!empty($this->opts['exclude'])){
90 $exclude = array_unique(array_filter(array_map('trim', explode(',', $this->opts['exclude']))));
93 $events->whereAddIn('!Events.action', $exclude, 'string');
97 $events->groupBy('Events.action');
98 $events->orderBy('Events.action ASC');
100 $summary = $events->fetchAll('action', 'total');
103 $this->jerr('Nothing to be sent');
108 foreach ($summary as $k => $v){
109 $subject[] = "{$v} {$k}";
112 $subject = implode(', ', $subject);
114 if(!empty($this->opts['subject'])){
115 $subject = "{$this->opts['subject']} $subject";
118 $events = DB_DataObject::factory('Events');
121 $events->selectAdd();
124 Events.event_when AS event_when,
125 Events.action AS action,
126 Events.remarks AS remarks,
127 CASE WHEN Events.person_id != 0 THEN
128 join_person_id_id.email
129 WHEN Events.hydra_person_id != 0 THEN
130 join_hydra_person_id_id.email
136 $events->whereAdd("Events.event_when > NOW() - INTERVAL 1 DAY");
138 $exclude = array_unique(array_filter(array_map('trim', explode(',', $this->opts['exclude']))));
140 if(!empty($exclude)){
141 $events->whereAddIn('!Events.action', $exclude, 'string');
144 if(!$events->count()){
145 $this->jerr('Nothing to be sent');
148 $errors = $events->fetchAll();
150 if(!empty($this->opts['host'])){
151 // reset the mail settings..
152 HTML_FlexyFramework::get()->Mail = array(
153 'host' => $this->opts['host']
157 if(!empty($this->opts['helo'])){
158 HTML_FlexyFramework::get()->Mail['helo'] = $this->opts['helo'];
164 'template' => 'EVENT_ERRORS_REPORT',
167 'subject' => $subject
170 $sent = DB_DataObject::factory('core_email')->send($content);
172 if(!is_object($sent)){