From 158013615252d5a068bece2833e14bd10f618381 Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Tue, 25 Aug 2015 17:46:15 -0500 Subject: [PATCH] file: Better protection against bad config If the configuration for the file backend is set to something invalid, do a better job of falling back to database-backed attachments. --- include/class.file.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/include/class.file.php b/include/class.file.php index e502ff805..580330b64 100644 --- a/include/class.file.php +++ b/include/class.file.php @@ -531,11 +531,16 @@ class AttachmentFile extends VerySimpleModel { static function getBackendForFile($file) { global $cfg; - if (!$cfg) + $char = null; + if ($cfg) { + $char = $cfg->getDefaultStorageBackendChar(); + } + try { + return FileStorageBackend::lookup($char ?: 'D', $file); + } + catch (Exception $x) { return new AttachmentChunkedData($file); - - $char = $cfg->getDefaultStorageBackendChar(); - return FileStorageBackend::lookup($char, $file); + } } static function lookupByHash($hash) { -- GitLab