From be1c91f93f426cd79e52f5441efac2319c734a4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Hoffmann?= Date: Mon, 23 Sep 2024 08:35:54 +0200 Subject: [PATCH] TASK: catch exception, when trying to get the original asset, collect and show errors at the end --- .../Command/AssetUsageCommandController.php | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Classes/Command/AssetUsageCommandController.php b/Classes/Command/AssetUsageCommandController.php index 8c6a909..2da376b 100644 --- a/Classes/Command/AssetUsageCommandController.php +++ b/Classes/Command/AssetUsageCommandController.php @@ -113,6 +113,8 @@ static function ($carry, EntityUsageInterface $assetUsage) { $rowsAdded = []; + $errors = []; + $this->output->progressStart($this->nodeDataRepository->countAll()); /** @var NodeData $nodeData */ @@ -147,7 +149,16 @@ static function ($carry, EntityUsageInterface $assetUsage) { foreach ($assetIds as $assetId) { if ($assetId instanceof AssetInterface) { if ($assetId instanceof AssetVariantInterface) { - $assetId = $assetId->getOriginalAsset(); + try { + $assetId = $assetId->getOriginalAsset(); + } catch (\Exception $e) { + $errors[] = [ + 'node identifier' => $nodeData->getIdentifier(), + 'property' => $assetPropertyName, + 'exception message' => $e->getMessage(), + ]; + continue; + } } $assetId = $this->persistenceManager->getIdentifierByObject($assetId); } @@ -245,6 +256,15 @@ static function ($carry, EntityUsageInterface $assetUsage) { $this->outputLine('No usages were removed'); } + if ($errors) { + $this->outputLine('Some asset reference errors occured. Please check the asset references in the database.'); + $this->output->outputTable($errors, [ + 'NodeIdentifier', + 'Property', + 'Exception message', + ]); + } + $this->assetUsageLogger->info(sprintf('Finished updating asset usage index. Added %d usages. Removed %d usages.', count($rowsAdded), count($rowsRemoved))); } }