Skip to content

Commit

Permalink
Fixed issue #16854: Cannot attach PDF to email invitation (email temp…
Browse files Browse the repository at this point in the history
…late 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
  • Loading branch information
gabrieljenik committed Dec 12, 2020
1 parent b43652b commit 4882e9f
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions application/models/SurveyLanguageSetting.php
Expand Up @@ -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'),
);
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4882e9f

Please sign in to comment.