From 4ba0dec1ea1322a3df0d9ea9f27b777ef6ed48da Mon Sep 17 00:00:00 2001 From: Tomas Hermanek Date: Wed, 23 Oct 2024 14:31:16 +0200 Subject: [PATCH] Single use. --- src/DataFixtures/ImageFixtures.php | 1 + .../AssetMetadata/AssetMetadataBulkFacade.php | 5 ++ .../IndexFactory/AssetIndexFactory.php | 1 + .../QueryFactory/AssetQueryFactory.php | 3 + .../SearchDto/AssetAdmSearchDto.php | 59 ++++++++++++------- src/Model/Dto/Asset/AssetAdmListDto.php | 6 ++ .../FormProvidableMetadataBulkUpdateDto.php | 15 +++++ src/Resources/config/elasticsearch/asset.php | 3 + 8 files changed, 71 insertions(+), 22 deletions(-) diff --git a/src/DataFixtures/ImageFixtures.php b/src/DataFixtures/ImageFixtures.php index 8b286bd3..9a0c4511 100644 --- a/src/DataFixtures/ImageFixtures.php +++ b/src/DataFixtures/ImageFixtures.php @@ -79,6 +79,7 @@ private function getData(): Generator $image->getAssetAttributes()->setStatus(AssetFileProcessStatus::Uploaded); $this->facadeProvider->getStatusFacade($image)->storeAndProcess($image, $file); $image->getAsset()->getAssetFlags()->setDescribed(true); + $image->getFlags()->setSingleUse(true); yield $image; diff --git a/src/Domain/AssetMetadata/AssetMetadataBulkFacade.php b/src/Domain/AssetMetadata/AssetMetadataBulkFacade.php index fa455871..07612b2f 100644 --- a/src/Domain/AssetMetadata/AssetMetadataBulkFacade.php +++ b/src/Domain/AssetMetadata/AssetMetadataBulkFacade.php @@ -8,6 +8,7 @@ use AnzuSystems\CommonBundle\Traits\ValidatorAwareTrait; use AnzuSystems\CoreDamBundle\Domain\Asset\AssetManager; use AnzuSystems\CoreDamBundle\Domain\Configuration\ConfigurationProvider; +use AnzuSystems\CoreDamBundle\Entity\AssetFile; use AnzuSystems\CoreDamBundle\Exception\ForbiddenOperationException; use AnzuSystems\CoreDamBundle\Model\Dto\Asset\FormProvidableMetadataBulkUpdateDto; use AnzuSystems\CoreDamBundle\Security\AccessDenier; @@ -55,6 +56,10 @@ public function bulkUpdate(Collection $list): Collection if ($updateDto->isDescribed()) { $this->assetMetadataManager->removeSuggestions($updateDto->getAsset()->getMetadata(), false); } + $mainFile = $asset->getMainFile(); + if ($mainFile instanceof AssetFile) { + $mainFile->getFlags()->setSingleUse($updateDto->isMainFileSingleUse()); + } } $this->assetManager->flush(); diff --git a/src/Elasticsearch/IndexFactory/AssetIndexFactory.php b/src/Elasticsearch/IndexFactory/AssetIndexFactory.php index f1447016..7ca375d9 100644 --- a/src/Elasticsearch/IndexFactory/AssetIndexFactory.php +++ b/src/Elasticsearch/IndexFactory/AssetIndexFactory.php @@ -70,6 +70,7 @@ public function buildFromEntity(ExtSystemIndexableInterface $entity): array 'pixelSize' => $entity->getAssetFileProperties()->getWidth() * $entity->getAssetFileProperties()->getHeight(), 'width' => $entity->getAssetFileProperties()->getWidth(), 'height' => $entity->getAssetFileProperties()->getHeight(), + 'mainFileSingleUse' => $entity->getMainFile()?->getFlags()->isSingleUse(), 'ratioWidth' => App::ZERO < $gcd ? (int) ($entity->getAssetFileProperties()->getWidth() / $gcd) : App::ZERO, 'ratioHeight' => App::ZERO < $gcd ? (int) ($entity->getAssetFileProperties()->getHeight() / $gcd) : App::ZERO, ...$this->assetMetadataCustomData->buildFromEntity($entity), diff --git a/src/Elasticsearch/QueryFactory/AssetQueryFactory.php b/src/Elasticsearch/QueryFactory/AssetQueryFactory.php index 1ffaa9ce..07f9427f 100644 --- a/src/Elasticsearch/QueryFactory/AssetQueryFactory.php +++ b/src/Elasticsearch/QueryFactory/AssetQueryFactory.php @@ -140,6 +140,9 @@ protected function getFilter(SearchDtoInterface $searchDto): array if (false === empty($searchDto->getCreatedByIds())) { $filter[] = ['terms' => ['createdById' => $searchDto->getCreatedByIds()]]; } + if (is_bool($searchDto->isMainFileSingleUse())) { + $filter[] = ['term' => ['mainFileSingleUse' => $searchDto->isMainFileSingleUse()]]; + } $this->applyRangeFilter($filter, 'pixelSize', $searchDto->getPixelSizeFrom(), $searchDto->getPixelSizeUntil()); $this->applyRangeFilter($filter, 'ratioWidth', $searchDto->getRatioWidthFrom(), $searchDto->getRatioWidthUntil()); diff --git a/src/Elasticsearch/SearchDto/AssetAdmSearchDto.php b/src/Elasticsearch/SearchDto/AssetAdmSearchDto.php index 9567631a..b22cc815 100644 --- a/src/Elasticsearch/SearchDto/AssetAdmSearchDto.php +++ b/src/Elasticsearch/SearchDto/AssetAdmSearchDto.php @@ -115,72 +115,75 @@ class AssetAdmSearchDto extends AbstractSearchDto protected Collection $licences; #[Serialize] - private ?int $shortestDimensionFrom = null; + protected ?int $shortestDimensionFrom = null; #[Serialize] - private ?int $shortestDimensionUntil = null; + protected ?int $shortestDimensionUntil = null; #[Serialize] - private ?int $pixelSizeFrom = null; + protected ?int $pixelSizeFrom = null; #[Serialize] - private ?int $pixelSizeUntil = null; + protected ?int $pixelSizeUntil = null; #[Serialize] - private ?int $widthFrom = null; + protected ?int $widthFrom = null; #[Serialize] - private ?int $widthUntil = null; + protected ?int $widthUntil = null; #[Serialize] - private ?int $heightFrom = null; + protected ?int $heightFrom = null; #[Serialize] - private ?int $heightUntil = null; + protected ?int $heightUntil = null; #[Serialize] - private ?int $ratioWidthFrom = null; + protected ?int $ratioWidthFrom = null; #[Serialize] - private ?int $ratioWidthUntil = null; + protected ?int $ratioWidthUntil = null; #[Serialize] - private ?int $ratioHeightFrom = null; + protected ?int $ratioHeightFrom = null; #[Serialize] - private ?int $ratioHeightUntil = null; + protected ?int $ratioHeightUntil = null; #[Serialize] #[Assert\Range(notInRangeMessage: ValidationException::ERROR_FIELD_INVALID, min: 0, max: 360)] - private ?int $rotationFrom = null; + protected ?int $rotationFrom = null; #[Serialize] #[Assert\Range(notInRangeMessage: ValidationException::ERROR_FIELD_INVALID, min: 0, max: 360)] - private ?int $rotationUntil = null; + protected ?int $rotationUntil = null; #[Serialize] - private ?int $durationFrom = null; + protected ?int $durationFrom = null; #[Serialize] - private ?int $durationUntil = null; + protected ?int $durationUntil = null; #[Serialize] - private ?int $bitrateFrom = null; + protected ?int $bitrateFrom = null; #[Serialize] - private ?int $bitrateUntil = null; + protected ?int $bitrateUntil = null; #[Serialize] - private ?int $slotsCountFrom = null; + protected ?int $slotsCountFrom = null; #[Serialize] - private ?int $slotsCountUntil = null; + protected ?int $slotsCountUntil = null; #[Serialize] - private ?DateTimeImmutable $createdAtFrom = null; + protected ?DateTimeImmutable $createdAtFrom = null; #[Serialize] - private ?DateTimeImmutable $createdAtUntil = null; + protected ?DateTimeImmutable $createdAtUntil = null; + + #[Serialize] + protected ?bool $mainFileSingleUse = null; private ?string $idInText = null; private bool $resolvedIdInText = false; @@ -713,6 +716,18 @@ public function getIdInText(): ?string return $this->idInText; } + public function isMainFileSingleUse(): ?bool + { + return $this->mainFileSingleUse; + } + + public function setMainFileSingleUse(?bool $mainFileSingleUse): self + { + $this->mainFileSingleUse = $mainFileSingleUse; + + return $this; + } + private function resolveIdFromText(): ?string { if (UuidHelper::isUuid($this->getText())) { diff --git a/src/Model/Dto/Asset/AssetAdmListDto.php b/src/Model/Dto/Asset/AssetAdmListDto.php index 3f757dcb..edc6bbbd 100644 --- a/src/Model/Dto/Asset/AssetAdmListDto.php +++ b/src/Model/Dto/Asset/AssetAdmListDto.php @@ -112,4 +112,10 @@ public function getLicence(): AssetLicence { return $this->getAsset()->getLicence(); } + + #[Serialize] + public function isMainFileSingleUse(): ?bool + { + return $this->asset->getMainFile()?->getFlags()->isSingleUse(); + } } diff --git a/src/Model/Dto/Asset/FormProvidableMetadataBulkUpdateDto.php b/src/Model/Dto/Asset/FormProvidableMetadataBulkUpdateDto.php index 01592aae..728edd18 100644 --- a/src/Model/Dto/Asset/FormProvidableMetadataBulkUpdateDto.php +++ b/src/Model/Dto/Asset/FormProvidableMetadataBulkUpdateDto.php @@ -27,6 +27,9 @@ final class FormProvidableMetadataBulkUpdateDto implements AssetCustomFormProvid #[Serialize] private bool $described = false; + #[Serialize] + private bool $mainFileSingleUse = false; + #[Serialize(strategy: Serialize::KEYS_VALUES)] private array $customData = []; @@ -136,4 +139,16 @@ public function getExtSystem(): ExtSystem { return $this->getAsset()->getExtSystem(); } + + public function isMainFileSingleUse(): bool + { + return $this->mainFileSingleUse; + } + + public function setMainFileSingleUse(bool $mainFileSingleUse): self + { + $this->mainFileSingleUse = $mainFileSingleUse; + + return $this; + } } diff --git a/src/Resources/config/elasticsearch/asset.php b/src/Resources/config/elasticsearch/asset.php index 9224e09c..7d3ab7ca 100644 --- a/src/Resources/config/elasticsearch/asset.php +++ b/src/Resources/config/elasticsearch/asset.php @@ -52,6 +52,9 @@ 'withProcessedFile' => [ 'type' => 'boolean', ], + 'mainFileSingleUse' => [ + 'type' => 'boolean', + ], 'described' => [ 'type' => 'boolean', ],