From 92909da6da6ce2bbb9fa5bd49a2351df7501fe8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Viguier?= Date: Thu, 11 Apr 2024 14:05:50 +0200 Subject: [PATCH] [stacked 10] DTO more flexible on their creation process. (#2374) --- app/Actions/Photo/Create.php | 6 +-- app/DTO/PhotoCreate/DuplicateDTO.php | 47 ++++++++++--------- app/DTO/PhotoCreate/StandaloneDTO.php | 61 ++++++++++++------------- app/DTO/PhotoCreate/VideoPartnerDTO.php | 31 +++++++------ 4 files changed, 75 insertions(+), 70 deletions(-) diff --git a/app/Actions/Photo/Create.php b/app/Actions/Photo/Create.php index 60861239257..1e2f8c3cfe8 100644 --- a/app/Actions/Photo/Create.php +++ b/app/Actions/Photo/Create.php @@ -110,7 +110,7 @@ public function add(NativeLocalFile $sourceFile, ?AbstractAlbum $album, ?int $fi */ private function handleDuplicate(InitDTO $initDTO): Photo { - $dto = new DuplicateDTO($initDTO); + $dto = DuplicateDTO::ofInit($initDTO); $pipes = []; if ($dto->shallResyncMetadata) { @@ -138,7 +138,7 @@ private function handleDuplicate(InitDTO $initDTO): Photo private function handleStandalone(InitDTO $initDTO): Photo { - $dto = new StandaloneDTO($initDTO); + $dto = StandaloneDTO::ofInit($initDTO); $pipes = [ Standalone\FixTimeStamps::class, @@ -177,7 +177,7 @@ private function handleStandalone(InitDTO $initDTO): Photo private function handleVideoLivePartner(InitDTO $initDTO): Photo { - $dto = new VideoPartnerDTO($initDTO); + $dto = VideoPartnerDTO::ofInit($initDTO); $pipes = [ VideoPartner\GetVideoPath::class, diff --git a/app/DTO/PhotoCreate/DuplicateDTO.php b/app/DTO/PhotoCreate/DuplicateDTO.php index 4452d405c7a..db14eddf68e 100644 --- a/app/DTO/PhotoCreate/DuplicateDTO.php +++ b/app/DTO/PhotoCreate/DuplicateDTO.php @@ -13,36 +13,39 @@ */ class DuplicateDTO implements PhotoDTO { - public readonly bool $shallResyncMetadata; - public readonly bool $shallSkipDuplicates; - public bool $hasBeenReSynced; - // Indicates the intended owner of the image. - public readonly int $intendedOwnerId; + public function __construct( + public readonly bool $shallResyncMetadata, + public readonly bool $shallSkipDuplicates, + // Indicates the intended owner of the image. + public readonly int $intendedOwnerId, - // Indicates whether the new photo shall be starred. - public readonly bool $is_starred; + // Indicates whether the new photo shall be starred. + public readonly bool $is_starred, - // The extracted EXIF information (populated during init phase). - public readonly Extractor $exifInfo; + // The extracted EXIF information (populated during init phase). + public readonly Extractor $exifInfo, - // The intended parent album - public readonly ?AbstractAlbum $album; + // The intended parent album + public readonly ?AbstractAlbum $album, - // During initial steps if liveParner is found, it will be placed here. - public Photo $photo; + // During initial steps if duplicate is found, it will be placed here. + public Photo $photo, + ) { + } - public function __construct(InitDTO $initDTO) + public static function ofInit(InitDTO $initDTO): DuplicateDTO { - $this->shallResyncMetadata = $initDTO->importMode->shallResyncMetadata; - $this->shallSkipDuplicates = $initDTO->importMode->shallSkipDuplicates; - - $this->photo = $initDTO->duplicate; - $this->exifInfo = $initDTO->exifInfo; - $this->album = $initDTO->album; - $this->is_starred = $initDTO->is_starred; - $this->intendedOwnerId = $initDTO->intendedOwnerId; + return new DuplicateDTO( + shallResyncMetadata: $initDTO->importMode->shallResyncMetadata, + shallSkipDuplicates: $initDTO->importMode->shallSkipDuplicates, + intendedOwnerId: $initDTO->intendedOwnerId, + is_starred: $initDTO->is_starred, + exifInfo: $initDTO->exifInfo, + album: $initDTO->album, + photo: $initDTO->duplicate, + ); } public function getPhoto(): Photo diff --git a/app/DTO/PhotoCreate/StandaloneDTO.php b/app/DTO/PhotoCreate/StandaloneDTO.php index d74921b3cbe..62954574225 100644 --- a/app/DTO/PhotoCreate/StandaloneDTO.php +++ b/app/DTO/PhotoCreate/StandaloneDTO.php @@ -15,47 +15,46 @@ class StandaloneDTO implements PhotoDTO { - public readonly bool $shallImportViaSymlink; - public readonly bool $shallDeleteImported; - - // The resulting photo - public Photo $photo; - - // Indicates the intended owner of the image. - public readonly int $intendedOwnerId; - - // Indicates whether the new photo shall be starred. - public readonly bool $is_starred; - - // The intended parent album - public readonly ?AbstractAlbum $album; - - // The original photo source file that is imported. - public readonly NativeLocalFile $sourceFile; - - // The extracted EXIF information (populated during init phase). - public readonly Extractor $exifInfo; - public ImageHandlerInterface|null $sourceImage = null; public AbstractSizeVariantNamingStrategy $namingStrategy; public TemporaryLocalFile|null $tmpVideoFile = null; public FlysystemFile $targetFile; public StreamStats|null $streamStat; - public function __construct(InitDTO $initDTO) - { - $this->photo = new Photo(); - $this->sourceFile = $initDTO->sourceFile; - $this->is_starred = $initDTO->is_starred; - $this->exifInfo = $initDTO->exifInfo; - $this->album = $initDTO->album; - $this->intendedOwnerId = $initDTO->intendedOwnerId; - $this->shallImportViaSymlink = $initDTO->importMode->shallImportViaSymlink; - $this->shallDeleteImported = $initDTO->importMode->shallDeleteImported; + public function __construct( + // The resulting photo + public Photo $photo, + // The original photo source file that is imported. + public readonly NativeLocalFile $sourceFile, + // Indicates whether the new photo shall be starred. + public readonly bool $is_starred, + // The extracted EXIF information (populated during init phase). + public readonly Extractor $exifInfo, + // The intended parent album + public readonly ?AbstractAlbum $album, + // Indicates the intended owner of the image. + public readonly int $intendedOwnerId, + public readonly bool $shallImportViaSymlink, + public readonly bool $shallDeleteImported, + ) { } public function getPhoto(): Photo { return $this->photo; } + + public static function ofInit(InitDTO $initDTO): StandaloneDTO + { + return new StandaloneDTO( + photo: new Photo(), + sourceFile: $initDTO->sourceFile, + is_starred: $initDTO->is_starred, + exifInfo: $initDTO->exifInfo, + album: $initDTO->album, + intendedOwnerId: $initDTO->intendedOwnerId, + shallImportViaSymlink: $initDTO->importMode->shallImportViaSymlink, + shallDeleteImported: $initDTO->importMode->shallDeleteImported, + ); + } } diff --git a/app/DTO/PhotoCreate/VideoPartnerDTO.php b/app/DTO/PhotoCreate/VideoPartnerDTO.php index 52f229f68f5..f093280f21f 100644 --- a/app/DTO/PhotoCreate/VideoPartnerDTO.php +++ b/app/DTO/PhotoCreate/VideoPartnerDTO.php @@ -9,27 +9,30 @@ class VideoPartnerDTO implements PhotoDTO { - public readonly bool $shallImportViaSymlink; - public readonly bool $shallDeleteImported; - - // The resulting photo - public readonly Photo $photo; - public StreamStats|null $streamStat; - public string $videoPath; - public readonly BaseMediaFile $videoFile; - public function __construct(InitDTO $initDTO) - { - $this->videoFile = $initDTO->sourceFile; - $this->photo = $initDTO->livePartner; - $this->shallImportViaSymlink = $initDTO->importMode->shallImportViaSymlink; - $this->shallDeleteImported = $initDTO->importMode->shallDeleteImported; + public function __construct( + public readonly BaseMediaFile $videoFile, + // The resulting photo + public readonly Photo $photo, + public readonly bool $shallImportViaSymlink, + public readonly bool $shallDeleteImported, + ) { } public function getPhoto(): Photo { return $this->photo; } + + public static function ofInit(InitDTO $initDTO): VideoPartnerDTO + { + return new VideoPartnerDTO( + videoFile: $initDTO->sourceFile, + photo: $initDTO->livePartner, + shallImportViaSymlink: $initDTO->importMode->shallImportViaSymlink, + shallDeleteImported: $initDTO->importMode->shallDeleteImported, + ); + } }