diff --git a/app/api/module/Api/src/Service/File/ContentStoreFileUploader.php b/app/api/module/Api/src/Service/File/ContentStoreFileUploader.php index 5069a4a1c7..e74179e365 100644 --- a/app/api/module/Api/src/Service/File/ContentStoreFileUploader.php +++ b/app/api/module/Api/src/Service/File/ContentStoreFileUploader.php @@ -5,6 +5,7 @@ use Dvsa\Olcs\DocumentShare\Data\Object\File as ContentStoreFile; use Dvsa\Olcs\DocumentShare\Service\DocumentStoreInterface; use Laminas\Http\Response; +use Laminas\Log\Logger; use Laminas\ServiceManager\Factory\FactoryInterface; use Psr\Container\ContainerInterface; @@ -16,13 +17,18 @@ */ class ContentStoreFileUploader implements FileUploaderInterface, FactoryInterface { - public const ERR_UNABLE_UPLOAD = 'Unable to store uploaded file: %s'; + public const ERR_UNABLE_UPLOAD = 'Unable to store uploaded file: %s (HTTP status code: %s)'; /** * @var DocumentStoreInterface */ private $contentStoreClient; + /** + * @var Logger + */ + private $logger; + /** * Upload file to remote storage * @@ -37,8 +43,12 @@ public function upload($identifier, ContentStoreFile $file) { $file->setIdentifier($identifier); + $this->logger->debug(__METHOD__, ['identifier' => $identifier, 'file' => $file]); + $response = $this->write($identifier, $file); + $this->logger->debug(__METHOD__, ['response' => $response]); + if ($response->isSuccess()) { return $file; } @@ -47,7 +57,7 @@ public function upload($identifier, ContentStoreFile $file) throw new MimeNotAllowedException(); } - throw new Exception(sprintf(self::ERR_UNABLE_UPLOAD, $response->getBody())); + throw new Exception(sprintf(self::ERR_UNABLE_UPLOAD, $response->getBody(), $response->getStatusCode())); } /** @@ -89,6 +99,7 @@ private function write($identifier, ContentStoreFile $file) public function __invoke(ContainerInterface $container, $requestedName, array $options = null) { $this->contentStoreClient = $container->get('ContentStore'); + $this->logger = $container->get('Logger'); return $this; } } diff --git a/app/api/test/module/Api/src/Service/File/ContentStoreFileUploaderTest.php b/app/api/test/module/Api/src/Service/File/ContentStoreFileUploaderTest.php index b8adf0e538..a5b519086d 100644 --- a/app/api/test/module/Api/src/Service/File/ContentStoreFileUploaderTest.php +++ b/app/api/test/module/Api/src/Service/File/ContentStoreFileUploaderTest.php @@ -8,6 +8,7 @@ use Dvsa\Olcs\DocumentShare\Data\Object\File as DsFile; use Dvsa\Olcs\DocumentShare\Service\WebDavClient as ContentStoreClient; use Laminas\Http\Response; +use Laminas\Log\Logger; use Laminas\ServiceManager\ServiceManager; use Mockery as m; use Mockery\Adapter\Phpunit\MockeryTestCase; @@ -43,6 +44,7 @@ function ($alias, $service) use ($sm) { ); $sm->setService('ContentStore', $this->mockContentStoreCli); + $sm->setService('Logger', $this->createMock(Logger::class)); static::assertSame($this->sut, $this->sut->__invoke($sm, null)); } @@ -97,12 +99,12 @@ public function testUploadFail() $respBody = 'unit_RespBody'; $this->expectException(Exception::class); - $this->expectExceptionMessage(sprintf(ContentStoreFileUploader::ERR_UNABLE_UPLOAD, $respBody)); + $this->expectExceptionMessage(sprintf(ContentStoreFileUploader::ERR_UNABLE_UPLOAD, $respBody, 500)); $response = m::mock(Response::class); $response ->shouldReceive('isSuccess')->once()->andReturn(false) - ->shouldReceive('getStatusCode')->once()->andReturn(Response::STATUS_CODE_500) + ->shouldReceive('getStatusCode')->andReturn(Response::STATUS_CODE_500) ->shouldReceive('getBody')->once()->andReturn($respBody); $this->mockContentStoreCli->shouldReceive('write')