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
115 $events->whereAdd("Events.event_when > NOW() - INTERVAL 1 DAY");
117 if(!empty($this->opts['exclude'])){
118 $exclude = array_unique(array_filter(array_map('trim', explode(',', $this->opts['exclude']))));
120 if(!empty($exclude)){
121 $events->whereAddIn('!Events.action', $exclude, 'string');
125 $events->groupBy('Events.action');
126 $events->orderBy('Events.action ASC');
128 $summary = $events->fetchAll('action', 'total');
131 $this->jerr('Nothing to be sent');
136 foreach ($summary as $k => $v){
137 $subject[] = "{$v} {$k}";
140 $subject = implode(', ', $subject);
142 if(!empty($this->opts['subject'])){
143 $subject = "{$this->opts['subject']} $subject";
146 $events = DB_DataObject::factory('Events');
149 $events->selectAdd();
152 Events.event_when AS event_when,
153 Events.action AS action,
154 Events.remarks AS remarks
157 $events->selectAddPersonEmail();
159 $events->whereAdd("Events.event_when > NOW() - INTERVAL 1 DAY");
161 $exclude = array_unique(array_filter(array_map('trim', explode(',', $this->opts['exclude']))));
163 if(!empty($exclude)){
164 $events->whereAddIn('!Events.action', $exclude, 'string');
167 if(!$events->count()){
168 $this->jerr('Nothing to be sent');
171 $errors = $events->fetchAll();
173 if(!empty($this->opts['host'])){
174 // reset the mail settings..
175 HTML_FlexyFramework::get()->Mail = array(
176 'host' => $this->opts['host']
180 if(!empty($this->opts['helo'])){
181 HTML_FlexyFramework::get()->Mail['helo'] = $this->opts['helo'];
187 'template' => 'EVENT_ERRORS_REPORT',
190 'subject' => $subject
193 $sent = DB_DataObject::factory('core_email')->send($content);
195 if(!is_object($sent)){
205 $events = DB_DataObject::factory('Events');
206 $events->selectAdd();
208 DISTINCT(Events.action) AS action
210 $events->whereAdd("action != ''");
211 $ar = $events->fetchAll('action');
212 echo implode(",", $ar);