DataObjects/Core_template.php
[Pman.Core] / NotifySend.php
index ac62779..caa6ec4 100644 (file)
@@ -85,7 +85,7 @@ class Pman_Core_NotifySend extends Pman
    
     function get($id,$opts=array())
     {
-        
+
         //print_r($opts);
         if (!empty($opts['DB_DataObject-debug'])) {
             DB_DataObject::debugLevel($opts['DB_DataObject-debug']);
@@ -101,7 +101,8 @@ class Pman_Core_NotifySend extends Pman
         if (!$w->get($id)) {
             $this->errorHandler("invalid id\n");
         }
-        if (!$force && strtotime($w->act_when) < strtotime($w->sent)) {
+
+        if (!$force && !empty($w->sent) && strtotime($w->act_when) < strtotime($w->sent)) {
             
             
             $this->errorHandler("send repeat to early\n");
@@ -169,9 +170,11 @@ class Pman_Core_NotifySend extends Pman
                 'onid' => $w->onid,
         );
         // only newer version of the database us this..
-        $personid_col = strtolower($w->person_table).'_id';
-        if (isset($w->{$personid_col})) {
-            $lar[$personid_col] = $w->{$personid_col};
+        if (isset($w->person_table)) {
+            $personid_col = strtolower($w->person_table).'_id';
+            if (isset($w->{$personid_col})) {
+                $lar[$personid_col] = $w->{$personid_col};
+            }
         }
         
         
@@ -227,7 +230,7 @@ class Pman_Core_NotifySend extends Pman
          
         if ($email === false || isset($email['error']) || empty($p)) {
             // object returned 'false' - it does not know how to send it..
-            $ev = $this->addEvent('NOTIFY', $w, isset($email['error'])  ?
+            $ev = $this->addEvent('NOTIFYFAIL', $w, isset($email['error'])  ?
                             $email['error'] : "INTERNAL ERROR  - We can not handle " . $w->ontable); 
             $ww = clone($w);
             $w->sent = (!$w->sent || $w->sent == '0000-00-00 00:00:00') ? $w->sqlValue('NOW()') : $w->sent; // do not update if sent.....
@@ -276,7 +279,7 @@ class Pman_Core_NotifySend extends Pman
         
         require_once 'Validate.php';
         if (!Validate::email($p->email, true)) {
-            $ev = $this->addEvent('NOTIFY', $w, "INVALID ADDRESS: " . $p->email);
+            $ev = $this->addEvent('NOTIFYFAIL', $w, "INVALID ADDRESS: " . $p->email);
             $ww = clone($w);
             $w->sent = (!$w->sent || $w->sent == '0000-00-00 00:00:00') ? $w->sqlValue('NOW()') : $w->sent; // do not update if sent.....
             $w->msgid = '';
@@ -324,7 +327,7 @@ class Pman_Core_NotifySend extends Pman
                 $this->errorHandler(date('Y-m-d h:i:s') . " - MX LOOKUP FAILED\n");
             }
             
-            $ev = $this->addEvent('NOTIFY', $w, "BAD ADDRESS - BAD DOMAIN - ". $p->email );
+            $ev = $this->addEvent('NOTIFYFAIL', $w, "BAD ADDRESS - BAD DOMAIN - ". $p->email );
             $w->sent = (!$w->sent || $w->sent == '0000-00-00 00:00:00') ? $w->sqlValue('NOW()') : $w->sent; // do not update if sent.....
             $w->msgid = '';
             $w->event_id = $ev->id;
@@ -338,7 +341,7 @@ class Pman_Core_NotifySend extends Pman
         
         
         if (!$force && strtotime($w->act_start) <  strtotime('NOW - 14 DAY')) {
-            $ev = $this->addEvent('NOTIFY', $w, "BAD ADDRESS - GIVE UP - ". $p->email );
+            $ev = $this->addEvent('NOTIFYFAIL', $w, "BAD ADDRESS - GIVE UP - ". $p->email );
             $w->sent = (!$w->sent || $w->sent == '0000-00-00 00:00:00') ? $w->sqlValue('NOW()') :$w->sent; // do not update if sent.....
             $w->msgid = '';
             $w->event_id = $ev->id;
@@ -415,7 +418,7 @@ class Pman_Core_NotifySend extends Pman
                     $core_notify = DB_DataObject::factory($this->table);
                     $core_notify->domain_id = $core_domain->id;
                     $core_notify->whereAdd("
-                        sent >= NOW() - INTERVAL $seconds SECONDS
+                        sent >= NOW() - INTERVAL $seconds SECOND
                     ");
                     
                     if($core_notify->count()){
@@ -428,12 +431,15 @@ class Pman_Core_NotifySend extends Pman
                     
                     
                     $mailer->host = $server;
-                    $mailer->auth = true;
-                    $mailer->username = $settings['username'];;
-                    $mailer->password = $settings['password'];        
+                    $mailer->auth = isset($settings['auth']) ? $settings['auth'] : true;
+                    $mailer->username = $settings['username'];
+                    $mailer->password = $settings['password'];
+                    if (isset($settings['port'])) {
+                        $mailer->port = $settings['port'];
+                    }
                     if (isset($settings['socket_options'])) {
                         $mailer->socket_options = $settings['socket_options'];
-                        $mailer->port = $settings['port'];
+                        
                     }
                     
                     
@@ -528,7 +534,7 @@ class Pman_Core_NotifySend extends Pman
                 $errmsg=  $res->userinfo['smtpcode'] . ':' . $res->userinfo['smtptext'];
             }
             
-            $ev = $this->addEvent('NOTIFY', $w, ($fail ? "FAILED - " : "RETRY TIME EXCEEDED - ") .
+            $ev = $this->addEvent('NOTIFYFAIL', $w, ($fail ? "FAILED - " : "RETRY TIME EXCEEDED - ") .
                        $errmsg);
             $w->sent = (!$w->sent || $w->sent == '0000-00-00 00:00:00') ? $w->sqlValue('NOW()') : $w->sent; // do not update if sent.....
             $w->msgid = '';
@@ -540,7 +546,7 @@ class Pman_Core_NotifySend extends Pman
         
         // handle no host availalbe forever...
         if (strtotime($w->act_start) < strtotime('NOW - 3 DAYS')) {
-            $ev = $this->addEvent('NOTIFY', $w, "RETRY TIME EXCEEDED - ". $p->email);
+            $ev = $this->addEvent('NOTIFYFAIL', $w, "RETRY TIME EXCEEDED - ". $p->email);
             $w->sent = (!$w->sent || $w->sent == '0000-00-00 00:00:00') ? $w->sqlValue('NOW()') : $w->sent; // do not update if sent.....
             $w->msgid = '';
             $w->event_id = $ev->id;
@@ -644,6 +650,7 @@ class Pman_Core_NotifySend extends Pman
     {
         $this->debug_str .= strlen($this->debug_str) ? "\n" : '';
         $this->debug_str .= $message;
+        //echo $message ."\n";
     }
     
     function errorHandler($msg, $success = false)