MailtemplateDispatch finished
This commit is contained in:
@@ -10,11 +10,18 @@ class MailtemplateDispatch extends mfBaseModel {
|
||||
|
||||
|
||||
public function sendToRecipients($test_to_email = false) {
|
||||
$emails = [];
|
||||
|
||||
if(!$test_to_email) {
|
||||
$emails = $this->getRecipients();
|
||||
if(!$emails) return true;
|
||||
if(!$this->tosend_date || $this->tosend_date > date('U')) return false;
|
||||
if($this->send_lock) return false;
|
||||
if(!$emails) {
|
||||
$this->log->debug(__METHOD__.": No recipient emails (".$this->id.")");
|
||||
return true;
|
||||
}
|
||||
if(!$this->tosend_date || $this->tosend_date > date('U')) {
|
||||
$this->log->debug(__METHOD__.": No tosend date or in future (".$this->id.")");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if($test_to_email) {
|
||||
@@ -28,9 +35,14 @@ class MailtemplateDispatch extends mfBaseModel {
|
||||
$template = $this->getProperty("mailtemplate");
|
||||
if(!$template) return false;
|
||||
|
||||
$body = "<html><head></head><body>";
|
||||
$body .= $template->renderBody();
|
||||
$body .= "</body></html>\n"; // explicitly add new line, or some mail clients wont show attachment
|
||||
if($template->body_html) {
|
||||
$body = "<html><head></head><body>";
|
||||
$body .= $template->renderBody();
|
||||
$body .= "</body></html>\n"; // explicitly add new line, or some mail clients wont show attachment
|
||||
} else {
|
||||
$body = $template->renderBody();
|
||||
}
|
||||
|
||||
|
||||
$subject = $this->subject;
|
||||
|
||||
@@ -38,7 +50,7 @@ class MailtemplateDispatch extends mfBaseModel {
|
||||
$from_name = $this->sender_name;
|
||||
|
||||
$attachments = [];
|
||||
foreach($this->getProperty("mailtemplate")->files as $file) {
|
||||
foreach($template->files as $file) {
|
||||
$att = [];
|
||||
$att["path"] = MFUPLOAD_FILE_SAVE_PATH."/".$file->file->subfolder."/".$file->file->store_filename;
|
||||
$att["filename"] = $file->filename;
|
||||
@@ -50,23 +62,19 @@ class MailtemplateDispatch extends mfBaseModel {
|
||||
$to = $email;
|
||||
|
||||
// check for NotificationLog
|
||||
/*$mnlog = MaintenanceNotificationLog::getFirst(["maintenancenotification_id" => $this->id, "email" => $to]);
|
||||
if($mnlog) {
|
||||
$mtdlog = MailtemplateDispatchLog::getFirst(["mailtemplatedispatch_id" => $this->id, "email" => $to]);
|
||||
if($mtdlog) {
|
||||
// was sent already
|
||||
continue;
|
||||
}*/
|
||||
/*fwrite(STDERR, "Subject: $subject\n\n");
|
||||
fwrite(STDERR, "$body\n\n");
|
||||
exit;*/
|
||||
}
|
||||
|
||||
$email = new Emailnotification();
|
||||
$email->setSubject($subject);
|
||||
if($this->getProperty("mailtemplate")->body_html) {
|
||||
if($template->body_html) {
|
||||
$email->setHtmlBody($body);
|
||||
} else {
|
||||
$email->setBody($body);
|
||||
}
|
||||
|
||||
$email->setFrom($from_email, $from_name);
|
||||
$email->setTo($to);
|
||||
$email->setHeader("X-".ucfirst(MFAPPNAME)."-mtdid", $this->id);
|
||||
@@ -82,24 +90,16 @@ class MailtemplateDispatch extends mfBaseModel {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*$mnlog = MaintenanceNotificationLog::create([
|
||||
"maintenancenotification_id" => $this->id,
|
||||
$mtdlog = MailtemplateDispatchLog::create([
|
||||
"mailtemplatedispatch_id" => $this->id,
|
||||
"email" => $to,
|
||||
"sent" => date("U"),
|
||||
]);
|
||||
|
||||
$mnlog->save();
|
||||
*/
|
||||
$mtdlog->save();
|
||||
|
||||
sleep(1); // wait a second
|
||||
}
|
||||
|
||||
//$this->sent = date("U");
|
||||
//$this->save();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function getRecipients($list_recipients = false, $return_recipients = false) {
|
||||
@@ -463,6 +463,19 @@ class MailtemplateDispatch extends mfBaseModel {
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("send_finish", $filter)) {
|
||||
$send_finish = $filter['send_finish'];
|
||||
if($send_finish === null) {
|
||||
$where .= " AND send_finish IS NULL";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("send_lock", $filter)) {
|
||||
$send_lock = $filter['send_lock'];
|
||||
if($send_lock === null) {
|
||||
$where .= " AND send_lock IS NULL";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("add-where", $filter)) {
|
||||
$where .= " ".$filter['add-where'];
|
||||
|
||||
Reference in New Issue
Block a user