Fix #6436 - email test support via notify code
authorAlan Knowles <alan@roojs.com>
Thu, 24 Sep 2020 06:18:11 +0000 (14:18 +0800)
committerAlan Knowles <alan@roojs.com>
Thu, 24 Sep 2020 06:18:11 +0000 (14:18 +0800)
DataObjects/Core_email.php
DataObjects/Core_notify.php
MessagePreview.php

index 03b9072..cbaba21 100644 (file)
@@ -675,5 +675,38 @@ Content-Transfer-Encoding: 7bit
     }
     
     
-    
+    function testData($person, $dt , $core_notify)
+    {
+        
+       // should return the formated email???
+       $pg = HTML_FlexyFramework::get()->page;
+       
+        
+       
+       
+        if(empty($this->test_class)){
+            $pg->jerr("[{$this->name}] does not has test class");
+        }
+        
+        require_once "{$this->test_class}.php";
+        
+        $cls = str_replace('/', '_', $this->test_class);
+        
+        $x = new $cls;
+        
+        $method = "test_{$this->name}";
+        
+        if(!method_exists($x, $method)){
+            $pg->jerr("{$method} does not exists in {$cls}");
+        }
+        
+        $content = $x->{$method}($this, $person);
+        $content['to'] = $person->getEmailFrom();
+
+        $content['bcc'] = array();
+       $data = $this->toMailerData($content);
+       return $data;
+        
+           
+    }
 }
index dbf012b..6cc632a 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /**
  *
- * Table is designed to be used with a mailer to notify or issue
+ * Table iend designed to be used with a mailer to notify or issue
  * emails (or maybe others later??)
  *
  *
@@ -316,13 +316,18 @@ class Pman_Core_DataObjects_Core_notify extends DB_DataObject
         
     }
     
-    function sendManual()
+    function sendManual($debug=false)
     {   
         require_once 'Pman/Core/NotifySend.php';
         
         $send = new Pman_Core_NotifySend();
         $send->error_handler = 'exception';
         
+        if ($debug) {
+            $send->get($this->id, array());
+            return true;
+        }
+        
         try {
             $send->get($this->id, array());
         } catch (Exception $e) {
index e12a031..ec8cf6c 100644 (file)
@@ -111,10 +111,37 @@ class Pman_Core_MessagePreview extends Pman
         if(!method_exists($x, $method)){
             $this->jerr("{$method} does not exists in {$cls}");
         }
-
+        /*
         $content = $x->{$method}($this, $this->authUser);
         
         $content['bcc'] = array();
+        */
+        
+        
+        $cn = DB_DataObject::factory('core_notify');
+        $cn->setFrom(array(
+            'evtype'        => 'Core_email::testData',
+            'onid'          => $_REQUEST['_id'],
+            'ontable'       => $_REQUEST['_table'],
+            'person_id'     => $this->authUser->id,
+            'person_table'  => 'Person',
+            'act_when'      => $cn->sqlValue("NOW()"),
+            'act_start'     => $cn->sqlValue("NOW()")
+        ));
+        
+        $cn->insert();
+        
+        $sent = $cn->sendManual();
+        
+        if(get_class($sent) != 'Pman_Core_NotifySend_Exception_Success'){
+            $this->jerr($sent->getMessage());
+        }
+        
+        $this->jok("SUCCESS");
+        
+        
+        
+        
         
         $sent = $core_email->send($content);