Skip to content

Commit cb23642

Browse files
Merge pull request #13 from punktDeForks/task/improve-update-command
TASK: catch exception, when trying to get the original asset, collect and show errors at the end
2 parents 3f7b733 + be1c91f commit cb23642

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

Classes/Command/AssetUsageCommandController.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ static function ($carry, EntityUsageInterface $assetUsage) {
113113

114114
$rowsAdded = [];
115115

116+
$errors = [];
117+
116118
$this->output->progressStart($this->nodeDataRepository->countAll());
117119

118120
/** @var NodeData $nodeData */
@@ -147,7 +149,16 @@ static function ($carry, EntityUsageInterface $assetUsage) {
147149
foreach ($assetIds as $assetId) {
148150
if ($assetId instanceof AssetInterface) {
149151
if ($assetId instanceof AssetVariantInterface) {
150-
$assetId = $assetId->getOriginalAsset();
152+
try {
153+
$assetId = $assetId->getOriginalAsset();
154+
} catch (\Exception $e) {
155+
$errors[] = [
156+
'node identifier' => $nodeData->getIdentifier(),
157+
'property' => $assetPropertyName,
158+
'exception message' => $e->getMessage(),
159+
];
160+
continue;
161+
}
151162
}
152163
$assetId = $this->persistenceManager->getIdentifierByObject($assetId);
153164
}
@@ -245,6 +256,15 @@ static function ($carry, EntityUsageInterface $assetUsage) {
245256
$this->outputLine('No usages were removed');
246257
}
247258

259+
if ($errors) {
260+
$this->outputLine('Some asset reference errors occured. Please check the asset references in the database.');
261+
$this->output->outputTable($errors, [
262+
'NodeIdentifier',
263+
'Property',
264+
'Exception message',
265+
]);
266+
}
267+
248268
$this->assetUsageLogger->info(sprintf('Finished updating asset usage index. Added %d usages. Removed %d usages.', count($rowsAdded), count($rowsRemoved)));
249269
}
250270
}

0 commit comments

Comments
 (0)