X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=Notify.php;h=15bbc7a28980e0d5c8d64f43183c38b9b8e42350;hb=7e9cdd246cc8bba1ce46a4db263a0f49b7cbc5a0;hp=0946abb7bd9bcd57fab58a9a202e5a35646aa8a2;hpb=25a2f525612231f3dc42352bdf34ea77c103bdb3;p=Pman.Core diff --git a/Notify.php b/Notify.php index 0946abb7..15bbc7a2 100644 --- a/Notify.php +++ b/Notify.php @@ -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( @@ -43,13 +49,20 @@ class Pman_Core_Notify extends Pman 'max' => 0, ), - 'force' => array( + 'force' => array( 'desc' => 'Force redelivery, even if it has been sent before or not queued...', 'default' => 0, 'short' => 'f', '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(); @@ -90,14 +103,31 @@ class Pman_Core_Notify extends Pman if (!empty($opts['send-to'])) { $this->send_to = $opts['send-to']; } + + $w = DB_DataObject::factory('core_notify_recur'); - $w->generateNotifications(); + 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.. } @@ -177,7 +207,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'; @@ -197,7 +227,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(); @@ -232,9 +262,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'])) { @@ -246,7 +279,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; @@ -268,7 +301,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']); } @@ -298,4 +331,8 @@ class Pman_Core_Notify extends Pman } + function output() + { + die("Done\n"); + } } \ No newline at end of file