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)
48 $this->transObj = DB_DataObject::Factory('core_enum');
50 $this->transObj->query('BEGIN');
52 PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'onPearError'));
54 if(empty($this->opts['group'])){
55 $this->jerr('Missing group - try add [-t {group name}]');
58 $rcpts = DB_DataObject::factory('groups')->lookupMembers("{$this->opts['group']}",'email');
61 $this->jerr("{$this->opts['group']} does not has any memeber");
64 $events = DB_DataObject::factory('Events');
67 DISTINCT(Events.action) AS action,
68 COUNT(Events.id) AS total
71 $events->whereAdd("Events.event_when > NOW() - INTERVAL 1 DAY");
73 if(!empty($this->opts['exclude'])){
74 $exclude = array_unique(array_filter(array_map('trim', explode(',', $this->opts['exclude']))));
77 $events->whereAddIn('!Events.action', $exclude, 'string');
81 $events->groupBy('Events.action');
82 $events->orderBy('Events.action ASC');
84 $totals = $events->fetchAll('action', 'total');
87 $this->jerr('Nothing to be sent');
92 // if(!empty($this->opts['subject'])){
93 // $subject[] = $this->opts['subject'];
96 foreach ($totals as $k => $v){
97 $subject[] = "{$v} {$k}";