Report/SendEventErrors.php
[Pman.Admin] / Report / SendEventErrors.php
index 5005ffb..2c3b4a0 100644 (file)
@@ -31,7 +31,7 @@ class Pman_Admin_Report_SendEventErrors extends Pman_Roo
         'uid' => array(
             'desc' => 'Unique identifier - eg. FAILREPORT',
             'short' => 'U',
-            'default' => '',
+            'default' => 'STD',
             'min' => 1,
             'max' => 1,
         ),
@@ -100,16 +100,15 @@ class Pman_Admin_Report_SendEventErrors extends Pman_Roo
         $rcpt_ids = DB_DataObject::factory('groups')->lookupMembers("{$this->opts['group']}",'id');
         
         $min = 0;
-        if (!empty($this->opts['uid'])) {}
-            $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->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');
@@ -144,14 +143,9 @@ class Pman_Admin_Report_SendEventErrors extends Pman_Roo
         $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');
         }
         
-        $e = DB_DataObject::factory('Events');
-        $e->init('ERROR-REPORT',false,"Sending");
-        $e->event_when = date('Y-m-d H:i:s');
-        $eid = $e->insert();
-        
         $subject = array();
         
         foreach ($summary as $k => $v){
@@ -164,6 +158,7 @@ class Pman_Admin_Report_SendEventErrors extends Pman_Roo
             $subject = "{$this->opts['subject']} $subject";
         }
         
+        
         $events = DB_DataObject::factory('Events');
         $events->autoJoin();
         
@@ -176,7 +171,7 @@ class Pman_Admin_Report_SendEventErrors extends Pman_Roo
             
         ");
         $events->selectAddPersonEmail();
-        
+        $events->whereAdd('id > '. $min);
         $events->whereAdd("Events.event_when > NOW() - INTERVAL 1 DAY");
         
         $exclude = array_unique(array_filter(array_map('trim', explode(',', $this->opts['exclude']))));
@@ -184,11 +179,18 @@ class Pman_Admin_Report_SendEventErrors extends Pman_Roo
         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'])){