From 0697a5b141e66e2a500200039a9aed65674878ba Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Thu, 28 May 2015 14:34:24 -0500
Subject: [PATCH] oops: Fix installation of canned responses

---
 include/class.attachment.php | 4 +++-
 include/class.i18n.php       | 6 +++---
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/include/class.attachment.php b/include/class.attachment.php
index b787ee250..6a9040154 100644
--- a/include/class.attachment.php
+++ b/include/class.attachment.php
@@ -128,7 +128,9 @@ extends InstrumentedList {
                 $fileId = $file;
             elseif (is_array($file) && isset($file['id']))
                 $fileId = $file['id'];
-            elseif ($F = AttachmentFile::upload($file))
+            elseif (isset($file['tmp_name']) && ($F = AttachmentFile::upload($file)))
+                $fileId = $F->getId();
+            elseif ($F = AttachmentFile::create($file))
                 $fileId = $F->getId();
             else
                 continue;
diff --git a/include/class.i18n.php b/include/class.i18n.php
index 02ec028f2..f68be50e6 100644
--- a/include/class.i18n.php
+++ b/include/class.i18n.php
@@ -142,10 +142,10 @@ class Internationalization {
         if (($tpl = $this->getTemplate('templates/premade.yaml'))
                 && ($canned = $tpl->getData())) {
             foreach ($canned as $c) {
-                if (($premade = Canned::create($c))
-                        && isset($c['attachments'])) {
+                if (!($premade = Canned::create($c)) || !$premade->save())
+                    continue;
+                if (isset($c['attachments'])) {
                     $premade->attachments->upload($c['attachments']);
-                    $premade->save();
                 }
             }
         }
-- 
GitLab