From f9bff29440c670d29916f34cb6039099bbef2a33 Mon Sep 17 00:00:00 2001 From: Tomas Hermanek Date: Tue, 22 Oct 2024 16:34:22 +0200 Subject: [PATCH] Wip --- src/Domain/Asset/AssetCopyBuilder.php | 2 -- src/Domain/AssetFile/AssetFileStatusManager.php | 4 ++-- src/Domain/Image/ImageCopyFacade.php | 15 ++++++++++++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Domain/Asset/AssetCopyBuilder.php b/src/Domain/Asset/AssetCopyBuilder.php index 670d1b7..8597d00 100644 --- a/src/Domain/Asset/AssetCopyBuilder.php +++ b/src/Domain/Asset/AssetCopyBuilder.php @@ -24,8 +24,6 @@ public function __construct( public function buildDraftAssetCopy(Asset $asset, AssetLicence $assetLicence, bool $flush = true): Asset { - // todo NOTIF! - // todo setup main file $assetCopy = $asset->__copy(); $assetCopy->getAttributes()->setStatus(AssetStatus::Draft); $this->trackCreation($assetCopy); diff --git a/src/Domain/AssetFile/AssetFileStatusManager.php b/src/Domain/AssetFile/AssetFileStatusManager.php index d93c7fc..cb4d5de 100644 --- a/src/Domain/AssetFile/AssetFileStatusManager.php +++ b/src/Domain/AssetFile/AssetFileStatusManager.php @@ -78,7 +78,7 @@ public function toProcessed(AssetFile $assetFile): AssetFile /** * @throws SerializerException */ - public function toFailed(AssetFile $assetFile, AssetFileFailedType $failedType, Throwable $throwable): AssetFile + public function toFailed(AssetFile $assetFile, AssetFileFailedType $failedType, ?Throwable $throwable = null): AssetFile { $this->changeTransition($assetFile, AssetFileProcessStatus::Failed, $failedType); @@ -88,7 +88,7 @@ public function toFailed(AssetFile $assetFile, AssetFileFailedType $failedType, 'Asset file (%s) process failed reason (%s). (%s', (string) $assetFile->getId(), $failedType->toString(), - $throwable->getMessage() + $throwable?->getMessage() ), exception: $throwable ); diff --git a/src/Domain/Image/ImageCopyFacade.php b/src/Domain/Image/ImageCopyFacade.php index 0cf5192..26b3576 100644 --- a/src/Domain/Image/ImageCopyFacade.php +++ b/src/Domain/Image/ImageCopyFacade.php @@ -9,15 +9,18 @@ use AnzuSystems\CoreDamBundle\Domain\Asset\AssetManager; use AnzuSystems\CoreDamBundle\Domain\Asset\AssetPropertiesRefresher; use AnzuSystems\CoreDamBundle\Domain\AssetFile\AssetFileCopyBuilder; +use AnzuSystems\CoreDamBundle\Domain\AssetFile\AssetFileStatusManager; use AnzuSystems\CoreDamBundle\Domain\AssetFile\FileProcessor\AssetFileStorageOperator; use AnzuSystems\CoreDamBundle\Domain\ImageFileOptimalResize\ImageFileOptimalResizeCopyBuilder; use AnzuSystems\CoreDamBundle\Entity\Asset; use AnzuSystems\CoreDamBundle\Entity\AssetSlot; +use AnzuSystems\CoreDamBundle\Event\Dispatcher\AssetFileEventDispatcher; use AnzuSystems\CoreDamBundle\Exception\ForbiddenOperationException; use AnzuSystems\CoreDamBundle\Messenger\Message\CopyAssetFileMessage; use AnzuSystems\CoreDamBundle\Model\Dto\Image\AssetFileCopyResultDto; use AnzuSystems\CoreDamBundle\Model\Dto\Image\ImageCopyDto; use AnzuSystems\CoreDamBundle\Model\Enum\AssetFileCopyResult; +use AnzuSystems\CoreDamBundle\Model\Enum\AssetFileFailedType; use AnzuSystems\CoreDamBundle\Repository\ImageFileRepository; use AnzuSystems\CoreDamBundle\Traits\IndexManagerAwareTrait; use AnzuSystems\CoreDamBundle\Traits\MessageBusAwareTrait; @@ -42,6 +45,8 @@ public function __construct( private readonly AssetFileCopyBuilder $assetFileCopyBuilder, private readonly AssetPropertiesRefresher $refresher, private readonly AssetManager $assetManager, + private readonly AssetFileEventDispatcher $assetFileEventDispatcher, + private readonly AssetFileStatusManager $assetFileStatusManager, ) { } @@ -107,8 +112,9 @@ public function copyAssetFiles(Asset $asset, Asset $copyAsset): void throw $exception; } - // todo send notification - // todo if copied dispatch message/mark as with file + foreach ($copyAsset->getSlots() as $slot) { + $this->assetFileEventDispatcher->dispatchAssetFileChanged($slot->getAssetFile()); + } } private function prepareCopy(ImageCopyDto $copyDto): AssetFileCopyResultDto @@ -173,7 +179,10 @@ private function copyAssetSlots(Asset $asset, Asset $copyAsset): void continue; } - // todo failed ... not found! + $this->assetFileStatusManager->toFailed( + $targetSlot->getAssetFile(), + AssetFileFailedType::Unknown + ); } }