From 25b9e90ef3b6018f898047be025ad859fcbbd96a Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Wed, 23 Sep 2015 20:59:21 -0400 Subject: Do not check anymore data folder permissions People who are using a remote database (Mysql/Postgresql) and a remote file storage (Aws S3 or similar) don't necessary needs to have a persistent local data folder or to change the permissions. --- app/Controller/File.php | 62 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 21 deletions(-) (limited to 'app/Controller/File.php') diff --git a/app/Controller/File.php b/app/Controller/File.php index 7b7c75ee..1431372f 100644 --- a/app/Controller/File.php +++ b/app/Controller/File.php @@ -2,6 +2,8 @@ namespace Controller; +use Core\ObjectStorage\ObjectStorageException; + /** * File controller * @@ -74,15 +76,21 @@ class File extends Base */ public function download() { - $task = $this->getTask(); - $file = $this->file->getById($this->request->getIntegerParam('file_id')); + try { - if ($file['task_id'] != $task['id']) { - $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); - } + $task = $this->getTask(); + $file = $this->file->getById($this->request->getIntegerParam('file_id')); + + if ($file['task_id'] != $task['id']) { + $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); + } - $this->response->forceDownload($file['name']); - $this->objectStorage->passthru($file['path']); + $this->response->forceDownload($file['name']); + $this->objectStorage->passthru($file['path']); + } + catch (ObjectStorageException $e) { + $this->logger->error($e->getMessage()); + } } /** @@ -110,15 +118,21 @@ class File extends Base */ public function image() { - $task = $this->getTask(); - $file = $this->file->getById($this->request->getIntegerParam('file_id')); + try { - if ($file['task_id'] != $task['id']) { - $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); - } + $task = $this->getTask(); + $file = $this->file->getById($this->request->getIntegerParam('file_id')); - $this->response->contentType($this->file->getImageMimeType($file['name'])); - $this->objectStorage->passthru($file['path']); + if ($file['task_id'] != $task['id']) { + $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); + } + + $this->response->contentType($this->file->getImageMimeType($file['name'])); + $this->objectStorage->passthru($file['path']); + } + catch (ObjectStorageException $e) { + $this->logger->error($e->getMessage()); + } } /** @@ -128,15 +142,21 @@ class File extends Base */ public function thumbnail() { - $task = $this->getTask(); - $file = $this->file->getById($this->request->getIntegerParam('file_id')); + try { - if ($file['task_id'] != $task['id']) { - $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); - } + $task = $this->getTask(); + $file = $this->file->getById($this->request->getIntegerParam('file_id')); + + if ($file['task_id'] != $task['id']) { + $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); + } - $this->response->contentType('image/jpeg'); - $this->objectStorage->passthru($this->file->getThumbnailPath($file['path'])); + $this->response->contentType('image/jpeg'); + $this->objectStorage->passthru($this->file->getThumbnailPath($file['path'])); + } + catch (ObjectStorageException $e) { + $this->logger->error($e->getMessage()); + } } /** -- cgit v1.2.3 From 5be520562997d3898268ed6bb44720ca35e062f1 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Wed, 23 Sep 2015 21:22:03 -0400 Subject: Change interface for objectStorage --- app/Controller/File.php | 6 +++--- app/Core/ObjectStorage/FileStorage.php | 2 +- app/Core/ObjectStorage/ObjectStorageInterface.php | 2 +- tests/units/Model/FileTest.php | 10 +++++++++- 4 files changed, 14 insertions(+), 6 deletions(-) (limited to 'app/Controller/File.php') diff --git a/app/Controller/File.php b/app/Controller/File.php index 1431372f..ef90c55a 100644 --- a/app/Controller/File.php +++ b/app/Controller/File.php @@ -86,7 +86,7 @@ class File extends Base } $this->response->forceDownload($file['name']); - $this->objectStorage->passthru($file['path']); + $this->objectStorage->output($file['path']); } catch (ObjectStorageException $e) { $this->logger->error($e->getMessage()); @@ -128,7 +128,7 @@ class File extends Base } $this->response->contentType($this->file->getImageMimeType($file['name'])); - $this->objectStorage->passthru($file['path']); + $this->objectStorage->output($file['path']); } catch (ObjectStorageException $e) { $this->logger->error($e->getMessage()); @@ -152,7 +152,7 @@ class File extends Base } $this->response->contentType('image/jpeg'); - $this->objectStorage->passthru($this->file->getThumbnailPath($file['path'])); + $this->objectStorage->output($this->file->getThumbnailPath($file['path'])); } catch (ObjectStorageException $e) { $this->logger->error($e->getMessage()); diff --git a/app/Core/ObjectStorage/FileStorage.php b/app/Core/ObjectStorage/FileStorage.php index 96478c3a..fa1efe21 100644 --- a/app/Core/ObjectStorage/FileStorage.php +++ b/app/Core/ObjectStorage/FileStorage.php @@ -70,7 +70,7 @@ class FileStorage implements ObjectStorageInterface * @access public * @param string $key */ - public function passthru($key) + public function output($key) { $filename = $this->path.DIRECTORY_SEPARATOR.$key; diff --git a/app/Core/ObjectStorage/ObjectStorageInterface.php b/app/Core/ObjectStorage/ObjectStorageInterface.php index 5440cf2b..180bdf86 100644 --- a/app/Core/ObjectStorage/ObjectStorageInterface.php +++ b/app/Core/ObjectStorage/ObjectStorageInterface.php @@ -35,7 +35,7 @@ interface ObjectStorageInterface * @access public * @param string $key */ - public function passthru($key); + public function output($key); /** * Move local file to object storage diff --git a/tests/units/Model/FileTest.php b/tests/units/Model/FileTest.php index e7520c89..d1ad7248 100644 --- a/tests/units/Model/FileTest.php +++ b/tests/units/Model/FileTest.php @@ -227,13 +227,21 @@ class FileTest extends Base ->expects($this->at(1)) ->method('remove') ->with( - $this->equalTo('/tmp/foo1') + $this->equalTo('thumbnails//tmp/foo2') ) ->will($this->returnValue(true)); $this->container['objectStorage'] ->expects($this->at(2)) ->method('remove') + ->with( + $this->equalTo('/tmp/foo1') + ) + ->will($this->returnValue(true)); + + $this->container['objectStorage'] + ->expects($this->at(3)) + ->method('remove') ->with( $this->equalTo('/tmp/foo3') ) -- cgit v1.2.3