Skip to content

Commit

Permalink
EZP-27551 Proper handling of missing images (#2036)
Browse files Browse the repository at this point in the history
* EZP-27551 Proper handling of missing images

* EZP-27551 removing double method call

* EZP-27551 adding missing arguments
  • Loading branch information
tomaszmadeyski authored and andrerom committed Jul 4, 2017
1 parent af2bd58 commit 924b630
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 8 additions & 1 deletion eZ/Publish/Core/FieldType/Image/IO/Legacy.php
Expand Up @@ -12,6 +12,7 @@
use eZ\Publish\Core\IO\IOServiceInterface;
use eZ\Publish\Core\IO\Values\BinaryFile;
use eZ\Publish\Core\IO\Values\BinaryFileCreateStruct;
use eZ\Publish\Core\IO\Values\MissingBinaryFile;

/**
* Legacy Image IOService.
Expand Down Expand Up @@ -149,7 +150,13 @@ public function loadBinaryFile($binaryFileId)
public function loadBinaryFileByUri($binaryFileUri)
{
try {
return $this->publishedIOService->loadBinaryFileByUri($binaryFileUri);
$image = $this->publishedIOService->loadBinaryFileByUri($binaryFileUri);

if ($image instanceof MissingBinaryFile) {
throw new InvalidArgumentException('binaryFileUri', sprintf("Can't find file with url {0}", $binaryFileUri));
}

return $image;
} catch (InvalidArgumentException $prefixException) {
// InvalidArgumentException means that the prefix didn't match, NotFound can pass through
try {
Expand Down
8 changes: 6 additions & 2 deletions eZ/Publish/Core/IO/TolerantIOService.php
Expand Up @@ -98,12 +98,16 @@ public function loadBinaryFile($binaryFileId)

public function loadBinaryFileByUri($binaryFileUri)
{
$binaryFileId = $this->binarydataHandler->getIdFromUri($binaryFileUri);
try {
$binaryFileId = $this->removeUriPrefix($this->binarydataHandler->getIdFromUri($binaryFileUri));
$binaryFileId = $this->removeUriPrefix($binaryFileId);
} catch (InvalidArgumentException $e) {
$this->logMissingFile($binaryFileUri);

return new MissingBinaryFile(['uri' => $binaryFileUri]);
return new MissingBinaryFile([
'id' => $binaryFileId,
'uri' => $binaryFileUri,
]);
}

try {
Expand Down

0 comments on commit 924b630

Please sign in to comment.