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)
71 if(!empty($this->opts['list'])){
75 if(empty($this->opts['group'])){
76 $this->jerr('Missing group - try add [-t {group name}]');
79 $rcpts = DB_DataObject::factory('groups')->lookupMembers("{$this->opts['group']}",'email');
82 $this->jerr("{$this->opts['group']} does not has any memeber");
85 $events = DB_DataObject::factory('Events');
88 DISTINCT(Events.action) AS action,
89 COUNT(Events.id) AS total
92 $events->whereAdd("Events.event_when > NOW() - INTERVAL 1 DAY");
94 if(!empty($this->opts['exclude'])){
95 $exclude = array_unique(array_filter(array_map('trim', explode(',', $this->opts['exclude']))));
98 $events->whereAddIn('!Events.action', $exclude, 'string');
102 $events->groupBy('Events.action');
103 $events->orderBy('Events.action ASC');
105 $summary = $events->fetchAll('action', 'total');
108 $this->jerr('Nothing to be sent');
113 foreach ($summary as $k => $v){
114 $subject[] = "{$v} {$k}";
117 $subject = implode(', ', $subject);
119 if(!empty($this->opts['subject'])){
120 $subject = "{$this->opts['subject']} $subject";
123 $events = DB_DataObject::factory('Events');
126 $events->selectAdd();
129 Events.event_when AS event_when,
130 Events.action AS action,
131 Events.remarks AS remarks
134 $events->selectAddPersonEmail();
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)){
182 $events = DB_DataObject::factory('Events');
183 $events->selectAdd();
185 DISTINCT(Events.action) AS action
187 $events->whereAdd("action != ''");
188 $ar = $events->fetchAll('action');
189 echo implode(",", $ar);