DataObjects/core.sql
[Pman.Core] / Notify.php
index b42824c..9cc3896 100644 (file)
@@ -50,6 +50,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,
+        ),
     );
     
     
@@ -91,6 +98,21 @@ class Pman_Core_Notify extends Pman
             $this->send_to = $opts['send-to'];
         }
      
+        
+        $w = DB_DataObject::factory('core_notify_recur');
+        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);
         
@@ -176,7 +198,7 @@ class Pman_Core_Notify extends Pman
         die("DONE\n");
     }
     
-    function run($id, $email)
+    function run($id, $email, $cmdOpts="")
     {
        // phpinfo();exit;
         $tn = tempnam(ini_get('session.save_path'),'stdout') . '.stdout';
@@ -196,7 +218,7 @@ class Pman_Core_Notify extends Pman
         if (!empty($this->send_to)) {
             $app .= ' --sent-to='.escapeshellarg($this->send_to);
         }
-        $cmd = $php . ' ' . $app; //. ' &';
+        $cmd = 'exec ' . $php . ' ' . $app . ' ' . $cmdOpts; //. ' &';
         
        
         $pipe = array();
@@ -231,9 +253,12 @@ 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') . "\n";
+            
             if ($info['running']) {
             
                 //if (file_exists('/proc/'.$p['pid'])) {
@@ -245,7 +270,7 @@ class Pman_Core_Notify extends Pman
                     //fclose($p['pipes'][1]);
                     fclose($p['pipes'][0]);
                     fclose($p['pipes'][2]);
-                    echo "TERMINATING: ({$p['pid']}) " . $p['cmd'] . " : " . file_get_contents($p['out']) . "\n";
+                    echo "\nTERMINATING: ({$p['pid']}) " . $p['cmd'] . " : " . file_get_contents($p['out']) . "\n";
                     @unlink($p['out']);
                     
                     continue;
@@ -267,7 +292,7 @@ class Pman_Core_Notify extends Pman
             //    $pool[] = $p;
             //    continue;
             //}
-            echo "ENDED: ({$p['pid']}) " .  $p['cmd'] . " : " . file_get_contents($p['out']) . "\n";
+            echo "\nENDED: ({$p['pid']}) " .  $p['cmd'] . " : " . file_get_contents($p['out']) . "\n";
             @unlink($p['out']);
             //unlink($p['out']);
         }
@@ -297,4 +322,8 @@ class Pman_Core_Notify extends Pman
         
     }
 
+    function output()
+    {
+        die("Done\n");
+    }
 }
\ No newline at end of file