Merge branch 'master' of http://git.roojs.com:8081/Pman.Core
[Pman.Core] / Notify.php
index f180791..15bbc7a 100644 (file)
@@ -16,7 +16,13 @@ require_once 'Pman.php';
 class Pman_Core_Notify extends Pman
 {
     
-    static $cli_desc = "Send out notification emails (usually from cron)";
+    static $cli_desc = "Runs the notification queue (usually from cron)
+                        Normally used to sends out emails to anyone in the notification list.
+    
+                        /etc/cron.d/pman-core-notify
+                        * *  * * *     www-data     /usr/bin/php /home/gitlive/web.mtrack/admin.php  Core/Notify > /dev/null
+    
+";
     
     static $cli_opts = array(
         'debug' => array(
@@ -50,6 +56,13 @@ class Pman_Core_Notify extends Pman
             'min' => 0,
             'max' => 0,
         ),
+        'generate' => array(
+            'desc' => 'Generate notifications for a table, eg. cash_invoice',
+            'default' => '',
+            'short' => 'g',
+            'min' => 0,
+            'max' => 1,
+        ),
     );
     
     
@@ -58,7 +71,7 @@ class Pman_Core_Notify extends Pman
     var $target = 'Core/NotifySend';
     var $evtype = ''; // any notification...
                     // this script should only handle EMAIL notifications..
-    
+    var $force = false;
     function getAuth()
     {
         $ff = HTML_FlexyFramework::get();
@@ -96,14 +109,25 @@ class Pman_Core_Notify extends Pman
         if (is_a($w, 'DB_DataObject')) {
             $w->generateNotifications();
         }
-     
+        if (!empty($opts['generate'])) {
+            $w = DB_DataObject::factory($opts['generate']);
+            if (is_a($w, 'DB_DataObject')) {
+                $w->generateNotifications();
+            }
+            exit;
+            
+            
+        }
      
         //DB_DataObject::debugLevel(1);
         $w = DB_DataObject::factory($this->table);
         
         if (!$showold) {
-            $w->whereAdd('act_when > sent'); // eg.. sent is not valid..
             
+            // standard
+            
+            $w->whereAdd('act_when > sent'); // eg.. sent is not valid..
+            $w->whereAdd('act_start > NOW() - INTERVAL 14 DAY'); // ignore the ones stuck in the queue
             if (!$this->force) {
                 $w->whereAdd('act_when < NOW()'); // eg.. not if future..
             }
@@ -203,7 +227,7 @@ class Pman_Core_Notify extends Pman
         if (!empty($this->send_to)) {
             $app .= ' --sent-to='.escapeshellarg($this->send_to);
         }
-        $cmd = $php . ' ' . $app . ' ' . $cmdOpts; //. ' &';
+        $cmd = 'exec ' . $php . ' ' . $app . ' ' . $cmdOpts; //. ' &';
         
        
         $pipe = array();
@@ -238,10 +262,11 @@ class Pman_Core_Notify extends Pman
             
             // update if necessday.
             if ($info['pid']) {
+                echo "CHANING PID FROM " . $p['pid']  .  "  TO ". $info['pid']. "\n";
                 $p['pid'] = $info['pid'];
             }
             
-            echo @file_get_contents('/proc/'. $p['pid'] .'/cmdline');
+            echo @file_get_contents('/proc/'. $p['pid'] .'/cmdline') . "\n";
             
             if ($info['running']) {
             
@@ -305,9 +330,9 @@ class Pman_Core_Notify extends Pman
         return false;
         
     }
+
     function output()
     {
-        die("done\n");
+        die("Done\n");
     }
-
 }
\ No newline at end of file