Report/SendEventErrors.php
[Pman.Admin] / Report / SendEventErrors.php
1 <?php
2
3 require_once 'Pman/Roo.php';
4
5 class Pman_Admin_Report_SendEventErrors extends Pman_Roo
6 {
7     static $cli_desc = "Send event errors occured in the last 24 hours";
8     
9     static $cli_opts = array(
10         'group' => array(
11             'desc' => 'group to send to',
12             'short' => 't',
13             'default' => '',
14             'min' => 1,
15             'max' => 1,
16         ),
17     );
18     
19     function getAuth()
20     {
21         $ff = HTML_FlexyFramework::get();
22         
23         if (!$ff->cli) {
24             die("cli only");
25         }
26         
27         return true;
28     }
29     
30     function get($args, $opts)
31     {
32         $this->opts = $opts;
33         
34         $this->transObj = DB_DataObject::Factory('core_enum');
35         
36         $this->transObj->query('BEGIN');
37         
38         PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'onPearError'));
39         
40         if(empty($this->opts['group'])){
41             $this->jerr('Missing group - try add [-t {group name}]');
42         }
43         
44         $rcpts = DB_DataObject::factory('groups')->lookupMembers("{$this->opts['group']}",'email');
45         
46         if(empty($rcpts)){
47             $this->jerr("{$this->opts['group']} does not has any memeber");
48         }
49         
50         $events = DB_DataObject::factory('Events');
51         $events->selectAdd();
52         $events->selectAdd("
53             DISTINCT(Events.action) AS action,
54             COUNT(Events.id) AS total
55         ");
56         
57         $events->whereAdd("Events.event_when > NOW() - INTERVAL 1 DAY");
58         
59         $events->groupBy('Events.action');
60         $events->orderBy('Events.action ASC');
61         
62         print_r($events->fetchAll('action', 'total'));exit;
63         
64         $this->jok("Done");
65         
66     }
67     
68     
69 }