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',
68 'desc' => 'Turn on database debugging',
78 $ff = HTML_FlexyFramework::get();
87 function get($args, $opts)
91 if (!empty($this->opts['debug'])) {
92 DB_DataObject::debugLevel(1);
95 if(!empty($this->opts['list'])){
99 if(empty($this->opts['group'])){
100 $this->jerr('Missing group - try add [-t {group name}]');
103 $rcpts = DB_DataObject::factory('groups')->lookupMembers("{$this->opts['group']}",'email');
107 $this->jerr("{$this->opts['group']} does not has any memeber");
109 // see the last date of notification to these users...
110 $rcpt_ids = DB_DataObject::factory('groups')->lookupMembers("{$this->opts['group']}",'id');
114 if ($this->opts['uid'] != 'STD') {
115 $events = DB_DataObject::factory('Events');
116 $events->action = 'ERROR-REPORT-' . $this->opts['uid'];
117 $events->orderBy('id DESC');
119 if ($events->find(true)) {
125 $events = DB_DataObject::factory('Events');
126 $events->selectAdd();
128 DISTINCT(Events.action) AS action,
129 COUNT(Events.id) AS total
131 $events->whereAdd('Eventsid > '. $min);
133 $events->whereAdd("Events.event_when > NOW() - INTERVAL 1 DAY");
135 if(!empty($this->opts['exclude'])){
136 $exclude = array_unique(array_filter(array_map('trim', explode(',', $this->opts['exclude']))));
138 if(!empty($exclude)){
139 $events->whereAddIn('!Events.action', $exclude, 'string');
142 if(!empty($this->opts['only'])){
143 $only= array_unique(array_filter(array_map('trim', explode(',', $this->opts['only']))));
146 $events->whereAddIn('Events.action', $only, 'string');
151 $events->groupBy('Events.action');
152 $events->orderBy('Events.action ASC');
154 $summary = $events->fetchAll('action', 'total');
157 $this->jerror('ERROR-REPORT-' . $this->opts['uid'], 'Nothing to be sent');
162 foreach ($summary as $k => $v){
163 $subject[] = "{$v} {$k}";
166 $subject = implode(', ', $subject);
168 if(!empty($this->opts['subject'])){
169 $subject = "{$this->opts['subject']} $subject";
173 $events = DB_DataObject::factory('Events');
176 $events->selectAdd();
179 Events.event_when AS event_when,
180 Events.action AS action,
181 Events.remarks AS remarks
184 $events->selectAddPersonEmail();
185 $events->whereAdd('Events.id > '. $min);
186 $events->whereAdd("Events.event_when > NOW() - INTERVAL 1 DAY");
188 $exclude = array_unique(array_filter(array_map('trim', explode(',', $this->opts['exclude']))));
190 if(!empty($exclude)){
191 $events->whereAddIn('!Events.action', $exclude, 'string');
194 $events->whereAddIn('Events.action', $only, 'string');
197 if(!$events->count()){ // this is the second count we are doing...
198 $this->jerr('Nothing to be sent');
202 $this->addEvent('ERROR-REPORT-' . $this->opts['uid'], false, $subject);
205 $errors = $events->fetchAll();
207 if(!empty($this->opts['host'])){
208 // reset the mail settings..
209 HTML_FlexyFramework::get()->Mail = array(
210 'host' => $this->opts['host']
214 if(!empty($this->opts['helo'])){
215 HTML_FlexyFramework::get()->Mail['helo'] = $this->opts['helo'];
221 'template' => 'EVENT_ERRORS_REPORT',
224 'subject' => $subject
227 $sent = DB_DataObject::factory('core_email')->send($content);
229 if(!is_object($sent)){
239 $events = DB_DataObject::factory('Events');
240 $events->selectAdd();
242 DISTINCT(Events.action) AS action
244 $events->whereAdd("action != ''");
245 $ar = $events->fetchAll('action');
246 echo implode(",", $ar);