Skip to content
Snippets Groups Projects
Commit 2133c29f authored by Jared Hancock's avatar Jared Hancock
Browse files

canned: Fix crash editing canned responses with attachments

parent 149fe025
No related branches found
No related tags found
No related merge requests found
......@@ -110,8 +110,7 @@ class Canned {
'attachments__type'=>'C',
'attachments__object_id'=>$this->getId(),
'attachments__inline' => $inlines,
))
->all();
));
}
function getNumFilters() {
......
......@@ -2241,6 +2241,10 @@ class FileUploadField extends FormField {
return $this->attachments ? $this->attachments->getAll() : array();
}
function setAttachments(GenericAttachments $att) {
$this->attachments = $att;
}
function getConfiguration() {
$config = parent::getConfiguration();
$_types = self::getFileTypes();
......
......@@ -93,11 +93,12 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
</div>
<?php
$attachments = $canned_form->getField('attachments');
if ($canned && ($files=$canned->getAttachedFiles())) {
$ids = array();
foreach ($files as $f)
$ids[] = $f->id;
$attachments->value = $ids;
if ($canned) {
$attachments->setAttachments($canned->attachments);
if ($files = $canned->getAttachedFiles()) {
$ids = $files->values_flat('id')->all();
$attachments->value = $ids;
}
}
print $attachments->render(); ?>
<br/>
......
......@@ -50,8 +50,8 @@ if ($_POST) {
$keepers = $canned_form->getField('attachments')->getClean();
$attachments = $canned->attachments->getSeparates(); //current list of attachments.
foreach($attachments as $k=>$file) {
if($file['id'] && !in_array($file['id'], $keepers)) {
$canned->attachments->delete($file['id']);
if(isset($file->id) && !in_array($file->id, $keepers)) {
$canned->attachments->delete($file->id);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment