diff --git a/Layout/default/Preordercampaign/Form.php b/Layout/default/Preordercampaign/Form.php index 145f96444..30479998d 100644 --- a/Layout/default/Preordercampaign/Form.php +++ b/Layout/default/Preordercampaign/Form.php @@ -394,8 +394,9 @@

Emailtemplates

- -
+ +
"> +
@@ -404,7 +405,7 @@
code?>
- "0"]) as $template): ?> @@ -424,10 +425,23 @@
+
+
+
+ +
+
+ - + diff --git a/application/Preorder/Preorder.php b/application/Preorder/Preorder.php index abf3cc4d9..2454c2426 100644 --- a/application/Preorder/Preorder.php +++ b/application/Preorder/Preorder.php @@ -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; } diff --git a/application/Preordercampaign/PreordercampaignController.php b/application/Preordercampaign/PreordercampaignController.php index b2727b3bf..4c606bbcd 100644 --- a/application/Preordercampaign/PreordercampaignController.php +++ b/application/Preordercampaign/PreordercampaignController.php @@ -483,21 +483,40 @@ class PreordercampaignController extends mfBaseController { $status_mailtemplate->delete(); }*/ + //var_dump($r->get());exit; $mailtemplates_delete = []; // Save Status Email Templates - foreach($r->mailtemplates as $status_code => $mailtemplate_id) { - if(!$mailtemplate_id) { + foreach($r->mailtemplates as $status_code => $status_data) { + $mailtemplate_id = $status_data["mailtemplate_id"]; + $allow_on_skip = $status_data["allow_on_skip"]; + $prevent_previous = $status_data["prevent_previous"]; + + /*if($status_code == 920) { + var_dump($status_data);exit; + }*/ + + if(!$mailtemplate_id && !$allow_on_skip && !$prevent_previous) { $mailtemplates_delete[] = $status_code; continue; } - $mailtemplate = new Mailtemplate($mailtemplate_id); - if(!$mailtemplate) continue; + if($status_code == 920) { + //var_dump($status_data, $allow_on_skip, $prevent_previous);exit; + } + + + if($mailtemplate_id) { + // check if Mailtemplate exists + $mailtemplate = new Mailtemplate($mailtemplate_id); + if(!$mailtemplate || !$mailtemplate->id) continue; + } $mt_data = [ "preordercampaign_id" => $campaign->id, "status_code" => $status_code, - "mailtemplate_id" => $mailtemplate_id, + "mailtemplate_id" => ($mailtemplate_id) ? $mailtemplate->id : null, + "allow_on_skip" => ($allow_on_skip) ? 1 : 0, + "prevent_previous" => ($prevent_previous) ? 1 : 0, ]; $statusmailtemplate = PreordercampaignStatusnotificationMailtemplate::getFirst(["preordercampaign_id" => $campaign->id, "status_code" => $status_code]); diff --git a/application/PreordercampaignStatusnotificationMailtemplate/PreordercampaignStatusnotificationMailtemplate.php b/application/PreordercampaignStatusnotificationMailtemplate/PreordercampaignStatusnotificationMailtemplate.php index 83a28e69a..86b7b8756 100644 --- a/application/PreordercampaignStatusnotificationMailtemplate/PreordercampaignStatusnotificationMailtemplate.php +++ b/application/PreordercampaignStatusnotificationMailtemplate/PreordercampaignStatusnotificationMailtemplate.php @@ -46,7 +46,7 @@ class PreordercampaignStatusnotificationMailtemplate extends mfBaseModel { $model = new PreordercampaignStatusnotificationMailtemplate(); $table_fields = [ - "preordercampaign_id", "status_code", "mailtemplate_id", + "preordercampaign_id", "status_code", "mailtemplate_id", "allow_on_skip", "prevent_previous", "result","create_by","edit_by","create","edit" ]; diff --git a/db/migrations/20250203115431_preordercampaign_statusnotification_mailtemplate_add_skip_actions.php b/db/migrations/20250203115431_preordercampaign_statusnotification_mailtemplate_add_skip_actions.php new file mode 100644 index 000000000..6d27f488a --- /dev/null +++ b/db/migrations/20250203115431_preordercampaign_statusnotification_mailtemplate_add_skip_actions.php @@ -0,0 +1,39 @@ +getEnvironment() == "thetool") { + $table = $this->table("PreordercampaignStatusnotificationMailtemplate"); + $table->addColumn("allow_on_skip", "integer", ["null" => false, "default" => 1, "length" => MySqlAdapter::INT_TINY, "after" => "mailtemplate_id"]); + $table->addColumn("prevent_previous", "integer", ["null" => false, "default" => 0, "length" => MySqlAdapter::INT_TINY, "after" => "allow_on_skip"]); + + $table->changeColumn("mailtemplate_id", "integer", ["null" => true, "default" => null]); + + $table->update(); + } + + if($this->getEnvironment() == "addressdb") { + + } + } + + public function down(): void + { + if($this->getEnvironment() == "thetool") { + $this->table("PreordercampaignStatusnotificationMailtemplate") + ->removeColumn("allow_on_skip") + ->removeColumn("prevent_previous") + ->update(); + } + + if($this->getEnvironment() == "addressdb") { + + } + } +}