DataObjects/Core_event_audit.php
[Pman.Core] / Notify.php
index b458400..dc3558c 100644 (file)
@@ -38,11 +38,18 @@ class Pman_Core_Notify extends Pman
         'old' => array(
             'desc' => 'Show old messages..',
             'default' => 0,
-            'short' => 'l',
+            'short' => 'o',
             'min' => 0,
             'max' => 0,
             
-        )
+        ),
+         'force' => array(
+            'desc' => 'Force redelivery, even if it has been sent before or not queued...',
+            'default' => 0,
+            'short' => 'f',
+            'min' => 0,
+            'max' => 0,
+        ),
     );
     
     
@@ -73,23 +80,39 @@ class Pman_Core_Notify extends Pman
         }
         //date_default_timezone_set('UTC');
        // phpinfo();exit;
-       $showold = 
+        $showold = !empty($opts['old']);
         if (!empty($opts['old'])) {
             $opts['list'] = 1; // force listing..
         }
         
+        $this->force = empty($opts['force']) ? 0 : 1;
+     
+        if (!empty($opts['send-to'])) {
+            $this->send_to = $opts['send-to'];
+        }
+     
         
         $w = DB_DataObject::factory($this->table);
-        $w->whereAdd('act_when > sent'); // eg.. sent is not valid..
-        $w->whereAdd('act_when < NOW()'); // eg.. not if future..
-
-        $w->orderBy('act_when ASC'); // oldest first.
+        
+        if (!$showold) {
+            $w->whereAdd('act_when > sent'); // eg.. sent is not valid..
+            
+            if (!$this->force) {
+                $w->whereAdd('act_when < NOW()'); // eg.. not if future..
+            }
+    
+            $w->orderBy('act_when ASC'); // oldest first.
+            $w->limit(1000); // we can run 1000 ...
+        } else {
+            $w->orderBy('act_when DESC'); // latest first
+            $w->limit(50); // we can run 1000 ...
+        }
         if (!empty($this->evtype)) {
             $w->evtype = $this->evtype;
         }
         
         $w->autoJoin();
-        $w->limit(1000); // we can run 1000 ...
+        
         
         $ar = $w->fetchAll();
         
@@ -99,7 +122,10 @@ class Pman_Core_Notify extends Pman
             }
             foreach($ar as $w) {
                 $o = $w->object();
-                echo "$e->id : $w->person_id_email email    : ". $o->toEventString()."\n";
+                
+                
+                echo "$w->id : $w->person_id_email email    : ".
+                        $o->toEventString()."    ". $w->status() . "\n";
             }
             exit;
         }
@@ -149,7 +175,14 @@ class Pman_Core_Notify extends Pman
         
         $cwd = $sn[0] == '/' ? dirname($sn) : dirname(realpath(getcwd() . $sn)); // same as run on.. (so script should end up being same relatively..)
         $app = $cwd . '/' . basename($_SERVER["SCRIPT_NAME"]) . '  ' . $this->target . '/'. $id;
+        if ($this->force) {
+            $app .= ' -f';
+        }
+        if (!empty($this->send_to)) {
+            $app .= ' --sent-to='.escapeshellarg($this->send_to);
+        }
         $cmd = $php . ' ' . $app. ' &';
+        
         echo $cmd . "\n";
         $pipe = array();
         $p = proc_open($cmd, $descriptorspec, $pipes, $cwd );