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' => 'email subject',
35 $ff = HTML_FlexyFramework::get();
44 function get($args, $opts)
46 $mailOptions = PEAR::getStaticProperty('Mail','options');
49 HTML_FlexyFramework::get()->Mail['helo'] = 'test';
51 $pg = HTML_FlexyFramework::get()->Mail;
56 if(empty($this->opts['group'])){
57 $this->jerr('Missing group - try add [-t {group name}]');
60 $rcpts = DB_DataObject::factory('groups')->lookupMembers("{$this->opts['group']}",'email');
63 $this->jerr("{$this->opts['group']} does not has any memeber");
66 $events = DB_DataObject::factory('Events');
69 DISTINCT(Events.action) AS action,
70 COUNT(Events.id) AS total
73 $events->whereAdd("Events.event_when > NOW() - INTERVAL 1 DAY");
75 if(!empty($this->opts['exclude'])){
76 $exclude = array_unique(array_filter(array_map('trim', explode(',', $this->opts['exclude']))));
79 $events->whereAddIn('!Events.action', $exclude, 'string');
83 $events->groupBy('Events.action');
84 $events->orderBy('Events.action ASC');
86 $summary = $events->fetchAll('action', 'total');
89 $this->jerr('Nothing to be sent');
94 foreach ($summary as $k => $v){
95 $subject[] = "{$v} {$k}";
98 $subject = implode(', ', $subject);
100 if(!empty($this->opts['subject'])){
101 $subject = "{$this->opts['subject']} $subject";
104 $events = DB_DataObject::factory('Events');
107 $events->selectAdd();
110 Events.event_when AS event_when,
111 Events.action AS action,
112 Events.remarks AS remarks,
113 CASE WHEN Events.person_id != 0 THEN
114 join_person_id_id.email
115 WHEN Events.hydra_person_id != 0 THEN
116 join_hydra_person_id_id.email
122 $events->whereAdd("Events.event_when > NOW() - INTERVAL 1 DAY");
124 $exclude = array_unique(array_filter(array_map('trim', explode(',', $this->opts['exclude']))));
126 if(!empty($exclude)){
127 $events->whereAddIn('!Events.action', $exclude, 'string');
130 if(!$events->count()){
131 $this->jerr('Nothing to be sent');
134 $errors = $events->fetchAll();
137 'template' => 'EVENT_ERRORS_REPORT',
140 'subject' => $subject
143 $sent = DB_DataObject::factory('core_email')->send($content);
145 if(!is_object($sent)){