From e2b4791f5dd15bd9380a4afef85d3f13dd1182cb Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Fri, 21 Feb 2014 11:15:20 -0600 Subject: [PATCH] file: Use the database to save files as a failsafe --- include/class.file.php | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/include/class.file.php b/include/class.file.php index 048b6f4fa..87d22eb3d 100644 --- a/include/class.file.php +++ b/include/class.file.php @@ -354,13 +354,26 @@ class AttachmentFile { // Note that this is preferred over $f->open() because the file does // not have a valid backend configured yet. ::getBackendForFile() // will consider the system configuration for storing the file - $bk = self::getBackendForFile($f); - if (isset($file['tmp_name'])) { - if (!$bk->upload($file['tmp_name'])) - return false; + $bks = array(self::getBackendForFile($f)); + if (!$bks[0]->getBkChar() !== 'D') + $bks[] = new AttachmentChunkedData($f); + + // Consider the selected backen first and then save to database + // otherwise. + $succeeded = false; + foreach ($bks as $bk) { + if (isset($file['tmp_name'])) { + if ($bk->upload($file['tmp_name'])) { + $succeeded = true; break; + } + } + elseif ($bk->write($file['data']) && $bk->flush()) { + $succeeded = true; break; + } + // Fallthrough to default backend if different? } - elseif (!$bk->write($file['data']) || !$bk->flush()) { - // XXX: Fallthrough to default backend if different? + if (!$succeeded) { + // Unable to save data (weird) return false; } -- GitLab