Added skip options to mailtemplates in Preordercampaigns
This commit is contained in:
@@ -185,8 +185,10 @@ class Preorder extends mfBaseModel {
|
||||
$trigger = new $classname($this, $new_status);
|
||||
$trigger->run();
|
||||
|
||||
/*
|
||||
// deprecated, replaced by PreordercampaignStatusnotifictionMailtemplate
|
||||
//var_dump($status["action"]);
|
||||
if (array_key_exists("action", $status) && is_array($status)) {
|
||||
if(is_array($status) && array_key_exists("action", $status)) {
|
||||
foreach ($status["action"] as $type => $action) {
|
||||
if (!array_key_exists($type, $actions)) {
|
||||
$actions[$type] = [];
|
||||
@@ -194,7 +196,7 @@ class Preorder extends mfBaseModel {
|
||||
$action["status_code"] = $intermediate_code;
|
||||
$actions[$type][] = $action;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
} else {
|
||||
$this->log->debug(__METHOD__ . ": $classname not found");
|
||||
}
|
||||
@@ -215,13 +217,18 @@ class Preorder extends mfBaseModel {
|
||||
"template" => $mailtemplate->code,
|
||||
"from" => "campaign",
|
||||
"data" => "preorder, adb_hausnummer, adb_wohneinheit",
|
||||
"status_code" => $intermediate_code
|
||||
"status_code" => $intermediate_code,
|
||||
"allow_on_skip" => $status_mail->allow_on_skip
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($actions);exit;
|
||||
|
||||
|
||||
|
||||
$this->log->debug(print_r($actions, true));
|
||||
//var_dump($actions);exit;
|
||||
// run last email action
|
||||
if(array_key_exists("email", $actions) && is_array($actions["email"]) && count($actions["email"])) {
|
||||
// get last email action, ignore previous status'
|
||||
@@ -237,6 +244,23 @@ class Preorder extends mfBaseModel {
|
||||
}
|
||||
}
|
||||
|
||||
if($new_status->code != $email_action["status_code"]) {
|
||||
// check if curent status allows sending previous status' notifications
|
||||
$current_status_mt = PreordercampaignStatusnotificationMailtemplate::getFirst(["preordercampaign_id" => $this->preordercampaign_id, "status_code" => $new_status->code]);
|
||||
if($current_status_mt && $current_status_mt->prevent_previous) {
|
||||
$send_email = false;
|
||||
$this->log->debug(__METHOD__.": Sending disallowed by current status");
|
||||
}
|
||||
|
||||
// check if email action allows sending if skipped over it
|
||||
if(!$email_action["allow_on_skip"]) {
|
||||
$send_email = false;
|
||||
$this->log->debug(__METHOD__.": Sending disallowed by previous status");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if($send_email) {
|
||||
$this->log->debug(__METHOD__.": Sending Email Action for Status ".$email_action["status_code"]);
|
||||
$email_to = $this->runTriggerEmailAction($email_action);
|
||||
@@ -252,7 +276,7 @@ class Preorder extends mfBaseModel {
|
||||
$psn_log->save();
|
||||
}
|
||||
} else {
|
||||
$this->log->warning(__METHOD__.": Not sending status (".$email_action["status_code"].") email because same or higher status email was sent already (Preorder ".$this->id.")");
|
||||
$this->log->warning(__METHOD__.": Not sending status (".$email_action["status_code"].") email because disallowed by current status or same or higher status email was sent already (Preorder ".$this->id.")");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -341,14 +365,20 @@ class Preorder extends mfBaseModel {
|
||||
$email->setHeader("X-".ucfirst(MFAPPNAME)."-pid", $this->id);
|
||||
$email->setHeader("X-".ucfirst(MFAPPNAME)."-ps", $this->getProperty("status")->code);
|
||||
// add attachments
|
||||
foreach($mailtemplate->files as $file) {
|
||||
if(!$file->filename || !$file->file_id || !$file->file->store_filename) continue;
|
||||
$this->log->debug($file->file->getFullPath());
|
||||
$email->addAttachment($file->file->getFullPath(), null, $file->filename, $file->file->mimetype ?: null);
|
||||
try {
|
||||
foreach ($mailtemplate->files as $file) {
|
||||
if (!$file->filename || !$file->file_id || !$file->file->store_filename) continue;
|
||||
$this->log->debug($file->file->getFullPath());
|
||||
$email->addAttachment($file->file->getFullPath(), null, $file->filename, $file->file->mimetype ?: null);
|
||||
}
|
||||
$email->send();
|
||||
} catch (Exception $e) {
|
||||
$this->log->warning(__METHOD__.": ".$e->getMessage());
|
||||
}
|
||||
$email->send();
|
||||
|
||||
$this->log->info(__METHOD__.": Sending StatusTrigger Email to $to");
|
||||
|
||||
|
||||
return $to;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user