Skip to content

Commit

Permalink
fix #4036 【メール】送信情報をデータベースに保存しない場合にファイルを添付すると送信に失敗する
Browse files Browse the repository at this point in the history
  • Loading branch information
seto1 committed Dec 19, 2024
1 parent b75f280 commit ff541af
Showing 1 changed file with 6 additions and 23 deletions.
29 changes: 6 additions & 23 deletions lib/Baser/Plugin/Mail/Controller/MailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,13 +367,7 @@ public function submit($id = null)
// データの入力チェックを行う
if ($this->MailMessage->validates()) {

// 送信データを保存するか確認
if ($this->dbDatas['mailContent']['MailContent']['save_info']) {
// validation OK
$result = $this->MailMessage->save(null, false);
} else {
$result = $this->MailMessage->data;
}
$result = $this->MailMessage->save(null, false);

if ($result) {

Expand Down Expand Up @@ -409,22 +403,7 @@ public function submit($id = null)
// メール送信
if ($this->_sendEmail($sendEmailOptions)) {
if (!$this->dbDatas['mailContent']['MailContent']['save_info']) {
$fileRecords = [];
foreach($this->dbDatas['mailFields'] as $key => $field) {
if ($field['MailField']['type'] !== 'file') {
continue;
}
// 削除フラグをセット
$field_name = $field['MailField']['field_name'];
$fileRecords['MailMessage'] = [
$field_name => $this->request->data['MailMessage'][$field_name],
$field_name . '_delete' => true,
];
// BcUploadBehavior::deleteFiles() はデータベースのデータを削除する前提となっているため、
// Model->data['MailMessage']['field_name'] に、配列ではなく、文字列がセットされている状態を想定しているので状態を模倣する
$this->MailMessage->data['MailMessage'][$field_name] = $this->request->data['MailMessage'][$field_name];
}
$this->MailMessage->deleteFiles($fileRecords);
$this->MailMessage->delete($result['MailMessage']['id']);
}

$this->Session->delete('Mail.valid');
Expand All @@ -434,6 +413,10 @@ public function submit($id = null)
'data' => $this->request->data
]);
} else {
if (!$this->dbDatas['mailContent']['MailContent']['save_info']) {
$this->MailMessage->delete($result['MailMessage']['id']);
}

$this->BcMessage->setError(
__('エラー : 送信中にエラーが発生しました。しばらくたってから再度送信お願いします。')
);
Expand Down

0 comments on commit ff541af

Please sign in to comment.