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',
33 'desc' => 'email subject',
40 'desc' => 'mail helo to use',
47 'desc' => 'mail host to use',
55 'desc' => 'list the current actions in the database',
65 $ff = HTML_FlexyFramework::get();
74 function get($args, $opts)
79 if(!empty($this->opts['list'])){
83 if(empty($this->opts['group'])){
84 $this->jerr('Missing group - try add [-t {group name}]');
87 $rcpts = DB_DataObject::factory('groups')->lookupMembers("{$this->opts['group']}",'email');
91 $this->jerr("{$this->opts['group']} does not has any memeber");
93 // see the last date of notification to these users...
94 $rcpt_ids = DB_DataObject::factory('groups')->lookupMembers("{$this->opts['group']}",'id');
96 $events = DB_DataObject::factory('Events');
97 $events->action = 'ERROR-REPORT';
98 $events->whereAddIn('person_id', $rcpt_ids, 'int');
99 $events->orderBy('id DESC');
102 if ($events->find(true)) {
108 $events = DB_DataObject::factory('Events');
109 $events->selectAdd();
111 DISTINCT(Events.action) AS action,
112 COUNT(Events.id) AS total
114 $events->whereAdd('id > '. $min);
116 $events->whereAdd("Events.event_when > NOW() - INTERVAL 1 DAY");
118 if(!empty($this->opts['exclude'])){
119 $exclude = array_unique(array_filter(array_map('trim', explode(',', $this->opts['exclude']))));
121 if(!empty($exclude)){
122 $events->whereAddIn('!Events.action', $exclude, 'string');
125 if(!empty($this->opts['only'])){
126 $only= array_unique(array_filter(array_map('trim', explode(',', $this->opts['only']))));
129 $events->whereAddIn('Events.action', $only, 'string');
134 $events->groupBy('Events.action');
135 $events->orderBy('Events.action ASC');
137 $summary = $events->fetchAll('action', 'total');
140 $this->jerr('Nothing to be sent');
145 foreach ($summary as $k => $v){
146 $subject[] = "{$v} {$k}";
149 $subject = implode(', ', $subject);
151 if(!empty($this->opts['subject'])){
152 $subject = "{$this->opts['subject']} $subject";
155 $events = DB_DataObject::factory('Events');
158 $events->selectAdd();
161 Events.event_when AS event_when,
162 Events.action AS action,
163 Events.remarks AS remarks
166 $events->selectAddPersonEmail();
168 $events->whereAdd("Events.event_when > NOW() - INTERVAL 1 DAY");
170 $exclude = array_unique(array_filter(array_map('trim', explode(',', $this->opts['exclude']))));
172 if(!empty($exclude)){
173 $events->whereAddIn('!Events.action', $exclude, 'string');
176 if(!$events->count()){
177 $this->jerr('Nothing to be sent');
180 $errors = $events->fetchAll();
182 if(!empty($this->opts['host'])){
183 // reset the mail settings..
184 HTML_FlexyFramework::get()->Mail = array(
185 'host' => $this->opts['host']
189 if(!empty($this->opts['helo'])){
190 HTML_FlexyFramework::get()->Mail['helo'] = $this->opts['helo'];
196 'template' => 'EVENT_ERRORS_REPORT',
199 'subject' => $subject
202 $sent = DB_DataObject::factory('core_email')->send($content);
204 if(!is_object($sent)){
214 $events = DB_DataObject::factory('Events');
215 $events->selectAdd();
217 DISTINCT(Events.action) AS action
219 $events->whereAdd("action != ''");
220 $ar = $events->fetchAll('action');
221 echo implode(",", $ar);