Skip to content

Commit a4612a7

Browse files
committed
TASK: Do not fail if the resource could not be fetched
# Conflicts: # Classes/AssetExtraction/IngestAttachmentAssetExtractor.php
1 parent 3c90dc6 commit a4612a7

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

Classes/AssetExtraction/IngestAttachmentAssetExtractor.php

+21-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
* source code.
1414
*/
1515

16-
use Neos\Flow\Annotations as FLow;
16+
use Neos\Flow\Annotations as Flow;
1717
use Neos\ContentRepository\Search\AssetExtraction\AssetExtractorInterface;
1818
use Neos\ContentRepository\Search\Dto\AssetContent;
1919
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\ElasticSearchClient;
20+
use Neos\Flow\Log\ThrowableStorageInterface;
2021
use Neos\Flow\Log\Utility\LogEnvironment;
2122
use Neos\Media\Domain\Model\AssetInterface;
2223
use Neos\Utility\Arrays;
@@ -33,6 +34,12 @@ class IngestAttachmentAssetExtractor implements AssetExtractorInterface
3334
*/
3435
protected $elasticsearchClient;
3536

37+
/**
38+
* @Flow\Inject
39+
* @var ThrowableStorageInterface
40+
*/
41+
protected $throwableStorage;
42+
3643
/**
3744
* @Flow\Inject
3845
* @var LoggerInterface
@@ -100,7 +107,19 @@ public function extract(AssetInterface $asset): AssetContent
100107
*/
101108
protected function getAssetContent(AssetInterface $asset): ?string
102109
{
103-
$stream = $asset->getResource()->getStream();
110+
try {
111+
$stream = $asset->getResource()->getStream();
112+
} catch (\Exception $e) {
113+
$message = $this->throwableStorage->logThrowable($e);
114+
$this->logger->error(sprintf('An exception occured while fetching resource with sha1 %s of asset %s. %s', $asset->getResource()->getSha1(), $asset->getResource()->getFilename(), $message), LogEnvironment::fromMethodName(__METHOD__));
115+
return '';
116+
}
117+
118+
if ($stream === false) {
119+
$this->logger->error(sprintf('Could not get the file stream of resource with sha1 %s of asset %s.', $asset->getResource()->getSha1(), $asset->getResource()->getFilename()), LogEnvironment::fromMethodName(__METHOD__));
120+
return '';
121+
}
122+
104123
stream_filter_append($stream, 'convert.base64-encode');
105124
$result = stream_get_contents($stream);
106125
return $result !== false ? $result : null;

0 commit comments

Comments
 (0)