diff options
author | Frederic Guillot <fred@kanboard.net> | 2017-02-12 13:34:56 -0500 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2017-02-12 13:34:56 -0500 |
commit | 991f7426e8ec2a566ad82043b22ce844a5a1cfa1 (patch) | |
tree | a0ff32313ad511ebdd9ea71180c86aa5b0002204 /app/ServiceProvider | |
parent | a172e3ad8d25e9b77616107ce8a622175ab0d698 (diff) |
Improve error reporting when file upload is not configured properly
Diffstat (limited to 'app/ServiceProvider')
-rw-r--r-- | app/ServiceProvider/ClassProvider.php | 5 | ||||
-rw-r--r-- | app/ServiceProvider/ObjectStorageProvider.php | 51 |
2 files changed, 51 insertions, 5 deletions
diff --git a/app/ServiceProvider/ClassProvider.php b/app/ServiceProvider/ClassProvider.php index 50ce531f..d66794df 100644 --- a/app/ServiceProvider/ClassProvider.php +++ b/app/ServiceProvider/ClassProvider.php @@ -4,7 +4,6 @@ namespace Kanboard\ServiceProvider; use Pimple\Container; use Pimple\ServiceProviderInterface; -use Kanboard\Core\ObjectStorage\FileStorage; use Kanboard\Core\Paginator; use Kanboard\Core\Http\OAuth2; use Kanboard\Core\Tool; @@ -178,10 +177,6 @@ class ClassProvider implements ServiceProviderInterface return new HttpClient($c); }; - $container['objectStorage'] = function () { - return new FileStorage(FILES_DIR); - }; - $container['cspRules'] = array( 'default-src' => "'self'", 'style-src' => "'self' 'unsafe-inline'", diff --git a/app/ServiceProvider/ObjectStorageProvider.php b/app/ServiceProvider/ObjectStorageProvider.php new file mode 100644 index 00000000..a108345f --- /dev/null +++ b/app/ServiceProvider/ObjectStorageProvider.php @@ -0,0 +1,51 @@ +<?php + +namespace Kanboard\ServiceProvider; + +use Kanboard\Core\ObjectStorage\FileStorage; +use LogicException; +use Pimple\Container; +use Pimple\ServiceProviderInterface; + +/** + * Class ObjectStorageProvider + * + * @package Kanboard\ServiceProvider + * @author Frederic Guillot + */ +class ObjectStorageProvider implements ServiceProviderInterface +{ + public function register(Container $container) + { + $container['objectStorage'] = function () { + if (file_exists(FILES_DIR)) { + if (! is_writable(FILES_DIR)) { + $stat = stat(FILES_DIR); + + throw new LogicException(sprintf( + 'The folder to store uploaded files is not writeable by your webserver user (file=%s; mode=%o; uid=%d; gid=%d)', + FILES_DIR, + $stat['mode'], + $stat['uid'], + $stat['gid'] + )); + } + } elseif (! @mkdir(FILES_DIR)) { + $folder = dirname(FILES_DIR); + $stat = stat($folder); + + throw new LogicException(sprintf( + 'Unable to create folder to store uploaded files, check the permissions of the parent directory (file=%s; mode=%o; uid=%d; gid=%d)', + $folder, + $stat['mode'], + $stat['uid'], + $stat['gid'] + )); + } + + return new FileStorage(FILES_DIR); + }; + + return $container; + } +}
\ No newline at end of file |