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' => 'list of actions only to report',
32 'desc' => 'Unique identifier - eg. FAILREPORT',
39 'desc' => 'email subject',
46 'desc' => 'mail helo to use',
53 'desc' => 'mail host to use',
61 'desc' => 'list the current actions in the database',
71 $ff = HTML_FlexyFramework::get();
80 function get($args, $opts)
85 if(!empty($this->opts['list'])){
89 if(empty($this->opts['group'])){
90 $this->jerr('Missing group - try add [-t {group name}]');
93 $rcpts = DB_DataObject::factory('groups')->lookupMembers("{$this->opts['group']}",'email');
97 $this->jerr("{$this->opts['group']} does not has any memeber");
99 // see the last date of notification to these users...
100 $rcpt_ids = DB_DataObject::factory('groups')->lookupMembers("{$this->opts['group']}",'id');
103 if (!empty($this->opts['uid'])) {}
104 $events = DB_DataObject::factory('Events');
105 $events->action = 'ERROR-REPORT-' . $this->opts['uid'];
106 $events->orderBy('id DESC');
109 if ($events->find(true)) {
115 $events = DB_DataObject::factory('Events');
116 $events->selectAdd();
118 DISTINCT(Events.action) AS action,
119 COUNT(Events.id) AS total
121 $events->whereAdd('id > '. $min);
123 $events->whereAdd("Events.event_when > NOW() - INTERVAL 1 DAY");
125 if(!empty($this->opts['exclude'])){
126 $exclude = array_unique(array_filter(array_map('trim', explode(',', $this->opts['exclude']))));
128 if(!empty($exclude)){
129 $events->whereAddIn('!Events.action', $exclude, 'string');
132 if(!empty($this->opts['only'])){
133 $only= array_unique(array_filter(array_map('trim', explode(',', $this->opts['only']))));
136 $events->whereAddIn('Events.action', $only, 'string');
141 $events->groupBy('Events.action');
142 $events->orderBy('Events.action ASC');
144 $summary = $events->fetchAll('action', 'total');
147 $this->jerror('ERROR-REPORT', 'Nothing to be sent');
150 $e = DB_DataObject::factory('Events');
151 $e->init('ERROR-REPORT',false,"Sending");
152 $e->event_when = date('Y-m-d H:i:s');
157 foreach ($summary as $k => $v){
158 $subject[] = "{$v} {$k}";
161 $subject = implode(', ', $subject);
163 if(!empty($this->opts['subject'])){
164 $subject = "{$this->opts['subject']} $subject";
167 $events = DB_DataObject::factory('Events');
170 $events->selectAdd();
173 Events.event_when AS event_when,
174 Events.action AS action,
175 Events.remarks AS remarks
178 $events->selectAddPersonEmail();
180 $events->whereAdd("Events.event_when > NOW() - INTERVAL 1 DAY");
182 $exclude = array_unique(array_filter(array_map('trim', explode(',', $this->opts['exclude']))));
184 if(!empty($exclude)){
185 $events->whereAddIn('!Events.action', $exclude, 'string');
188 if(!$events->count()){
189 $this->jerr('Nothing to be sent');
192 $errors = $events->fetchAll();
194 if(!empty($this->opts['host'])){
195 // reset the mail settings..
196 HTML_FlexyFramework::get()->Mail = array(
197 'host' => $this->opts['host']
201 if(!empty($this->opts['helo'])){
202 HTML_FlexyFramework::get()->Mail['helo'] = $this->opts['helo'];
208 'template' => 'EVENT_ERRORS_REPORT',
211 'subject' => $subject
214 $sent = DB_DataObject::factory('core_email')->send($content);
216 if(!is_object($sent)){
226 $events = DB_DataObject::factory('Events');
227 $events->selectAdd();
229 DISTINCT(Events.action) AS action
231 $events->whereAdd("action != ''");
232 $ar = $events->fetchAll('action');
233 echo implode(",", $ar);