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');
48 print_R($mailOptions);exit;
52 if(empty($this->opts['group'])){
53 $this->jerr('Missing group - try add [-t {group name}]');
56 $rcpts = DB_DataObject::factory('groups')->lookupMembers("{$this->opts['group']}",'email');
59 $this->jerr("{$this->opts['group']} does not has any memeber");
62 $events = DB_DataObject::factory('Events');
65 DISTINCT(Events.action) AS action,
66 COUNT(Events.id) AS total
69 $events->whereAdd("Events.event_when > NOW() - INTERVAL 1 DAY");
71 if(!empty($this->opts['exclude'])){
72 $exclude = array_unique(array_filter(array_map('trim', explode(',', $this->opts['exclude']))));
75 $events->whereAddIn('!Events.action', $exclude, 'string');
79 $events->groupBy('Events.action');
80 $events->orderBy('Events.action ASC');
82 $summary = $events->fetchAll('action', 'total');
85 $this->jerr('Nothing to be sent');
90 foreach ($summary as $k => $v){
91 $subject[] = "{$v} {$k}";
94 $subject = implode(', ', $subject);
96 if(!empty($this->opts['subject'])){
97 $subject = "{$this->opts['subject']} $subject";
100 $events = DB_DataObject::factory('Events');
103 $events->selectAdd();
106 Events.event_when AS event_when,
107 Events.action AS action,
108 Events.remarks AS remarks,
109 CASE WHEN Events.person_id != 0 THEN
110 join_person_id_id.email
111 WHEN Events.hydra_person_id != 0 THEN
112 join_hydra_person_id_id.email
118 $events->whereAdd("Events.event_when > NOW() - INTERVAL 1 DAY");
120 $exclude = array_unique(array_filter(array_map('trim', explode(',', $this->opts['exclude']))));
122 if(!empty($exclude)){
123 $events->whereAddIn('!Events.action', $exclude, 'string');
126 if(!$events->count()){
127 $this->jerr('Nothing to be sent');
130 $errors = $events->fetchAll();
133 'template' => 'EVENT_ERRORS_REPORT',
136 'subject' => $subject
139 $sent = DB_DataObject::factory('core_email')->send($content);
141 if(!is_object($sent)){