<?php
-
+
require_once 'Pman/Roo.php';
class Pman_Admin_Report_SendEventErrors extends Pman_Roo
'min' => 1,
'max' => 1,
),
-
+ 'uid' => array(
+ 'desc' => 'Unique identifier - eg. FAILREPORT',
+ 'short' => 'U',
+ 'default' => 'STD',
+ 'min' => 1,
+ 'max' => 1,
+ ),
'subject' => array(
'desc' => 'email subject',
'short' => 's',
'default' => '',
'min' => 1,
'max' => 1,
- )
+ ),
+ 'debug' => array(
+ 'desc' => 'Turn on database debugging',
+ 'short' => 'd',
+ 'default' => '',
+ 'min' => 1,
+ 'max' => 1,
+ ),
);
function getAuth()
return true;
}
- function get($args, $opts)
+ function get($args, $opts = Array())
{
$this->opts = $opts;
+ if (!empty($this->opts['debug'])) {
+ DB_DataObject::debugLevel(1);
+ }
if(!empty($this->opts['list'])){
$this->listTypes();
}
$this->jerr('Missing group - try add [-t {group name}]');
}
- $rcpts = DB_DataObject::factory('groups')->lookupMembers("{$this->opts['group']}",'email');
-
-
- if(empty($rcpts)){
- $this->jerr("{$this->opts['group']} does not has any memeber");
- }
- // see the last date of notification to these users...
- $rcpt_ids = DB_DataObject::factory('groups')->lookupMembers("{$this->opts['group']}",'id');
-
- $events = DB_DataObject::factory('Events');
- $events->action = 'ERROR-REPORT';
- $events->whereAddIn('person_id', $rcpt_ids, 'int');
- $events->orderBy('id DESC');
- $events->limit(1);
$min = 0;
- if ($events->find(true)) {
- $min = $events->id;
+
+ if ($this->opts['uid'] != 'STD') {
+ $events = DB_DataObject::factory('Events');
+ $events->action = 'ERROR-REPORT-' . $this->opts['uid'];
+ $events->orderBy('id DESC');
+ $events->limit(1);
+ if ($events->find(true)) {
+ $min = $events->id;
+ }
}
-
$events = DB_DataObject::factory('Events');
$events->selectAdd();
$events->selectAdd("
DISTINCT(Events.action) AS action,
COUNT(Events.id) AS total
");
- $events->whereAdd('id > '. $min);
-
+ $events->whereAdd('Events.id > '. $min);
+ $events->whereAdd("Events.action NOT LIKE 'ERROR-REPORT-%'");
$events->whereAdd("Events.event_when > NOW() - INTERVAL 1 DAY");
if(!empty($this->opts['exclude'])){
$summary = $events->fetchAll('action', 'total');
if(empty($summary)){
- $this->jerror('ERROR-REPORT', 'Nothing to be sent');
+ $this->jerror('ERROR-REPORT-' . $this->opts['uid'], 'Nothing to be sent');
}
$subject = array();
$subject = "{$this->opts['subject']} $subject";
}
+
$events = DB_DataObject::factory('Events');
$events->autoJoin();
");
$events->selectAddPersonEmail();
-
+ $events->whereAdd("Events.action NOT LIKE 'ERROR-REPORT-%'");
+ $events->whereAdd('Events.id > '. $min);
$events->whereAdd("Events.event_when > NOW() - INTERVAL 1 DAY");
$exclude = array_unique(array_filter(array_map('trim', explode(',', $this->opts['exclude']))));
if(!empty($exclude)){
$events->whereAddIn('!Events.action', $exclude, 'string');
}
+ if(!empty($only)){
+ $events->whereAddIn('Events.action', $only, 'string');
+ }
- if(!$events->count()){
+ if(!$events->count()){ // this is the second count we are doing...
$this->jerr('Nothing to be sent');
}
+
+ $this->addEvent('ERROR-REPORT-' . $this->opts['uid'], false, $subject);
+
+
$errors = $events->fetchAll();
if(!empty($this->opts['host'])){
$content = array(
- 'template' => 'EVENT_ERRORS_REPORT',
- 'rcpts' => $rcpts,
+ 'template' => 'FILE_REPORTING_EMAIL',
+ 'rcpts_group' => $this->opts['group'],
'errors' => $errors,
'subject' => $subject
);
function listTypes()
{
- $events = DB_DataObject::factory('Events');
+ $events = DB_DataObject::factory('Events');
$events->selectAdd();
$events->selectAdd("
DISTINCT(Events.action) AS action
}
+ static function test_EVENT_ERRORS_REPORT($pg, $to)
+ {
+ $this->jerr("Not implemented");
+ }
+
}
\ No newline at end of file