Skip to content

Commit

Permalink
Merge pull request #13 from punktDeForks/task/improve-update-command
Browse files Browse the repository at this point in the history
TASK: catch exception, when trying to get the original asset, collect and show errors at the end
  • Loading branch information
daniellienert authored Oct 17, 2024
2 parents 3f7b733 + be1c91f commit cb23642
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion Classes/Command/AssetUsageCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ static function ($carry, EntityUsageInterface $assetUsage) {

$rowsAdded = [];

$errors = [];

$this->output->progressStart($this->nodeDataRepository->countAll());

/** @var NodeData $nodeData */
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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)));
}
}

0 comments on commit cb23642

Please sign in to comment.