Skip to content

Commit

Permalink
[stacked 11] cleaner approach of the pipe execution. (#2375)
Browse files Browse the repository at this point in the history
  • Loading branch information
ildyria authored Apr 11, 2024
1 parent 92909da commit 9838839
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
37 changes: 19 additions & 18 deletions app/Actions/Photo/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,22 +157,7 @@ private function handleStandalone(InitDTO $initDTO): Photo
Standalone\CreateSizeVariants::class,
];

try {
return app(Pipeline::class)
->send($dto)
->through($pipes)
->thenReturn()
->getPhoto();
} catch (LycheeException $e) {
// If source file could not be put into final destination, remove
// freshly created photo from DB to avoid having "zombie" entries.
try {
$dto->getPhoto()->delete();
} catch (\Throwable) {
// Sic! If anything goes wrong here, we still throw the original exception
}
throw $e;
}
return $this->executePipeOnDTO($pipes, $dto)->getPhoto();
}

private function handleVideoLivePartner(InitDTO $initDTO): Photo
Expand All @@ -186,12 +171,28 @@ private function handleVideoLivePartner(InitDTO $initDTO): Photo
Shared\Save::class,
];

return $this->executePipeOnDTO($pipes, $dto)->getPhoto();
}

/**
* Execute the pipes on the DTO.
*
* @template T of VideoPartnerDTO|StandaloneDTO
*
* @param array $pipes
* @param T $dto
*
* @return T
*
* @throws LycheeException
*/
private function executePipeOnDTO(array $pipes, VideoPartnerDTO|StandaloneDTO $dto): VideoPartnerDTO|StandaloneDTO
{
try {
return app(Pipeline::class)
->send($dto)
->through($pipes)
->thenReturn()
->getPhoto();
->thenReturn();
} catch (LycheeException $e) {
// If source file could not be put into final destination, remove
// freshly created photo from DB to avoid having "zombie" entries.
Expand Down
10 changes: 5 additions & 5 deletions app/DTO/PhotoCreate/StandaloneDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ public function __construct(
) {
}

public function getPhoto(): Photo
{
return $this->photo;
}

public static function ofInit(InitDTO $initDTO): StandaloneDTO
{
return new StandaloneDTO(
Expand All @@ -57,4 +52,9 @@ public static function ofInit(InitDTO $initDTO): StandaloneDTO
shallDeleteImported: $initDTO->importMode->shallDeleteImported,
);
}

public function getPhoto(): Photo
{
return $this->photo;
}
}

0 comments on commit 9838839

Please sign in to comment.