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");
94 $rcpt_ids = DB_DataObject::factory('groups')->lookupMembers("{$this->opts['group']}",'id');
96 // see the last date of notification to these users...
100 $events = DB_DataObject::factory('Events');
101 $events->selectAdd();
103 DISTINCT(Events.action) AS action,
104 COUNT(Events.id) AS total
107 $events->whereAdd("Events.event_when > NOW() - INTERVAL 1 DAY");
109 if(!empty($this->opts['exclude'])){
110 $exclude = array_unique(array_filter(array_map('trim', explode(',', $this->opts['exclude']))));
112 if(!empty($exclude)){
113 $events->whereAddIn('!Events.action', $exclude, 'string');
117 $events->groupBy('Events.action');
118 $events->orderBy('Events.action ASC');
120 $summary = $events->fetchAll('action', 'total');
123 $this->jerr('Nothing to be sent');
128 foreach ($summary as $k => $v){
129 $subject[] = "{$v} {$k}";
132 $subject = implode(', ', $subject);
134 if(!empty($this->opts['subject'])){
135 $subject = "{$this->opts['subject']} $subject";
138 $events = DB_DataObject::factory('Events');
141 $events->selectAdd();
144 Events.event_when AS event_when,
145 Events.action AS action,
146 Events.remarks AS remarks
149 $events->selectAddPersonEmail();
151 $events->whereAdd("Events.event_when > NOW() - INTERVAL 1 DAY");
153 $exclude = array_unique(array_filter(array_map('trim', explode(',', $this->opts['exclude']))));
155 if(!empty($exclude)){
156 $events->whereAddIn('!Events.action', $exclude, 'string');
159 if(!$events->count()){
160 $this->jerr('Nothing to be sent');
163 $errors = $events->fetchAll();
165 if(!empty($this->opts['host'])){
166 // reset the mail settings..
167 HTML_FlexyFramework::get()->Mail = array(
168 'host' => $this->opts['host']
172 if(!empty($this->opts['helo'])){
173 HTML_FlexyFramework::get()->Mail['helo'] = $this->opts['helo'];
179 'template' => 'EVENT_ERRORS_REPORT',
182 'subject' => $subject
185 $sent = DB_DataObject::factory('core_email')->send($content);
187 if(!is_object($sent)){
197 $events = DB_DataObject::factory('Events');
198 $events->selectAdd();
200 DISTINCT(Events.action) AS action
202 $events->whereAdd("action != ''");
203 $ar = $events->fetchAll('action');
204 echo implode(",", $ar);