From 4882e9f48cb93d6797d54e9cc451714958f74381 Mon Sep 17 00:00:00 2001 From: Gabriel Jenik Date: Sat, 12 Dec 2020 11:08:40 -0300 Subject: [PATCH] Fixed issue #16854: Cannot attach PDF to email invitation (email template for surveys) (#1679) * Fixed issue #16854: Cannot attach PDF to email invitation (email template for surveys) Previously, at emailtemplates controller's 'update' method, the settings were saved directly using updateAll. After commit '2c8ccdd5', in order to apply the model's validation, the settings are saved using 'setAttributes($attributes)' and 'save()'. The setAttributes method, by default, only assigns 'safe' attributes (attributes that have a validation rule). That excludes the 'attachments' attribute. Passing 'false' as second parameter solves the issue. * Fixed issue #16854: Cannot attach PDF to email invitation (email template for surveys) Adding validation to attachments as to make them a safe attribute --- application/models/SurveyLanguageSetting.php | 26 ++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/application/models/SurveyLanguageSetting.php b/application/models/SurveyLanguageSetting.php index 74b5337a8cf..7f1ece52625 100644 --- a/application/models/SurveyLanguageSetting.php +++ b/application/models/SurveyLanguageSetting.php @@ -135,6 +135,8 @@ public function rules() array('surveyls_dateformat', 'numerical', 'integerOnly'=>true, 'min'=>'1', 'max'=>'12', 'allowEmpty'=>true), array('surveyls_numberformat', 'numerical', 'integerOnly'=>true, 'min'=>'0', 'max'=>'1', 'allowEmpty'=>true), + + array('attachments', 'attachmentsInfo'), ); } @@ -183,6 +185,30 @@ public function lsdefault($attribute) } } + /** + * Defines the customs validation rule attachmentsInfo + * + * @param mixed $attribute + */ + public function attachmentsInfo($attribute) + { + if (empty($this->$attribute)) return; + + $value = []; + $attachmentsByType = unserialize($this->$attribute); + if (is_array($attachmentsByType)) { + foreach ($attachmentsByType as $type => $attachments) { + if (is_array($attachments)) { + foreach ($attachments as $key => $attachment) { + if (isset($attachment['url']) && isset($attachment['size']) && isset($attachment['relevance'])) { + $value[$type][$key] = $attachment; + } + } + } + } + } + return serialize($value); + } /** * Returns the token's captions