From 07101267a71feb344c6d2fbae2cb3cdc92e37b1a Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Wed, 15 Apr 2026 12:13:37 +0200 Subject: [PATCH] refs #2944. New datasize column in Imange entity --- migrations/Version20260415120000.php | 26 +++++++++++++++++++ .../OgRepository/Image/GetAction.php | 18 +++++++++++++ src/Dto/Output/ImageImageRepositoryOutput.php | 12 +++++++-- src/Entity/ImageImageRepository.php | 15 +++++++++++ 4 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 migrations/Version20260415120000.php diff --git a/migrations/Version20260415120000.php b/migrations/Version20260415120000.php new file mode 100644 index 0000000..42170bb --- /dev/null +++ b/migrations/Version20260415120000.php @@ -0,0 +1,26 @@ +addSql('ALTER TABLE image_image_repository ADD size VARCHAR(255) DEFAULT NULL'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE image_image_repository DROP COLUMN size'); + } +} diff --git a/src/Controller/OgRepository/Image/GetAction.php b/src/Controller/OgRepository/Image/GetAction.php index da01c99..85b01dd 100644 --- a/src/Controller/OgRepository/Image/GetAction.php +++ b/src/Controller/OgRepository/Image/GetAction.php @@ -36,6 +36,24 @@ class GetAction extends AbstractOgRepositoryController throw new BadRequestHttpException('An error occurred while fetching the image: ' . $content['details']); } + $datasize = $content['details']['images'][0]['datasize'] ?? null; + $size = $content['details']['images'][0]['size'] ?? null; + $changed = false; + + if ($datasize !== null && $data->getDatasize() !== (string) $datasize) { + $data->setDatasize((string) $datasize); + $changed = true; + } + + if ($size !== null && $data->getSize() !== (string) $size) { + $data->setSize((string) $size); + $changed = true; + } + + if ($changed) { + $this->entityManager->flush(); + } + return new JsonResponse(data: $content, status: Response::HTTP_OK); } } \ No newline at end of file diff --git a/src/Dto/Output/ImageImageRepositoryOutput.php b/src/Dto/Output/ImageImageRepositoryOutput.php index d4cf4e9..6cfe2d8 100644 --- a/src/Dto/Output/ImageImageRepositoryOutput.php +++ b/src/Dto/Output/ImageImageRepositoryOutput.php @@ -54,11 +54,18 @@ class ImageImageRepositoryOutput extends AbstractOutput #[Groups(['image-image-repository:read', 'image:read'])] #[ApiProperty( - description: 'El tamaño de los datos en bytes', - example: '10737418240' + description: 'El tamaño de los datos sin comprimir en bytes', + example: '12902400000' )] public ?string $datasize = null; + #[Groups(['image-image-repository:read', 'image:read'])] + #[ApiProperty( + description: 'El tamaño de la imagen comprimida en bytes', + example: '3795024506' + )] + public ?string $size = null; + #[Groups(['image-image-repository:read', 'image:read'])] #[ApiProperty( description: 'La descripción de la imagen', @@ -107,6 +114,7 @@ class ImageImageRepositoryOutput extends AbstractOutput $this->status = $imageImageRepository->getStatus(); $this->imageFullsum = $imageImageRepository->getImageFullsum(); $this->datasize = $imageImageRepository->getDatasize(); + $this->size = $imageImageRepository->getSize(); $this->description = $imageImageRepository->getDescription(); $this->createdAt = $imageImageRepository->getCreatedAt(); $this->createdBy = $imageImageRepository->getCreatedBy(); diff --git a/src/Entity/ImageImageRepository.php b/src/Entity/ImageImageRepository.php index 69c9116..fc9fd55 100644 --- a/src/Entity/ImageImageRepository.php +++ b/src/Entity/ImageImageRepository.php @@ -32,6 +32,9 @@ class ImageImageRepository extends AbstractEntity #[ORM\Column(length: 255, nullable: true)] private ?string $datasize = null; + #[ORM\Column(length: 255, nullable: true)] + private ?string $size = null; + #[ORM\Column(nullable: true)] private ?int $version = null; @@ -125,6 +128,18 @@ class ImageImageRepository extends AbstractEntity return $this; } + public function getSize(): ?string + { + return $this->size; + } + + public function setSize(?string $size): static + { + $this->size = $size; + + return $this; + } + public function getVersion(): ?int { return $this->version;