From 54ab6f080a60526fd9685518c1456bc1b7781187 Mon Sep 17 00:00:00 2001 From: pikanji Date: Tue, 2 Jan 2018 08:04:47 +0900 Subject: [PATCH] Use cms.storage.uploads.disk instead of filesystem.default Fixes #3332. FileUpload widget uploads file to the disk specified by default in config/filesystem.php instead of storage.uploads.disk in config/cms.php, if we use System\Models\File following the instruction in here. Although we can still create another class extending System\Models\File or October\Rain\Database\Attach\File and use it as the model for attachOne/Many relation, System\Models\File seems to be the one that responsible to look at storage.uploads.disk in config/cms.php, because the existing methods are using storage.uploads.*. Credit to @pikanji --- modules/system/models/File.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/modules/system/models/File.php b/modules/system/models/File.php index 582cfd427..40f6a46af 100644 --- a/modules/system/models/File.php +++ b/modules/system/models/File.php @@ -2,6 +2,8 @@ use Url; use Config; +use File as FileHelper; +use Storage; use October\Rain\Database\Attach\File as FileBase; /** @@ -56,4 +58,23 @@ class File extends FileBase return $uploadsFolder . '/protected/'; } } + + /** + * Returns true if storage.uploads.disk in config/cms.php is "local". + * @return bool + */ + protected function isLocalStorage() + { + return Config::get('cms.storage.uploads.disk') == 'local'; + } + + /** + * Copy the local file to Storage + * @return bool True on success, false on failure. + */ + protected function copyLocalToStorage($localPath, $storagePath) + { + $disk = Storage::disk(Config::get('cms.storage.uploads.disk')); + return $disk->put($storagePath, FileHelper::get($localPath), ($this->isPublic()) ? 'public' : null); + } }