From 30cf2e7a8ca29c2ee4bd97eae82448bb2389d7b7 Mon Sep 17 00:00:00 2001 From: hamed <15238-genius.ha@users.noreply.drupalcode.org> Date: Wed, 10 Jun 2026 15:09:19 +0330 Subject: [PATCH] feat(clinic): change clinic_logo from JSON array to single URL string --- migrations/Version20260610113711.php | 36 ++++++++++++++++++++++ src/Clinic/Controller/ClinicController.php | 15 ++++++--- src/Clinic/Entity/Clinic.php | 10 +++--- 3 files changed, 52 insertions(+), 9 deletions(-) create mode 100644 migrations/Version20260610113711.php diff --git a/migrations/Version20260610113711.php b/migrations/Version20260610113711.php new file mode 100644 index 00000000..b64bbc14 --- /dev/null +++ b/migrations/Version20260610113711.php @@ -0,0 +1,36 @@ +addSql("ALTER TABLE clinics ADD COLUMN clinic_logo_new VARCHAR(500) DEFAULT NULL"); + $this->addSql("UPDATE clinics SET clinic_logo_new = JSON_UNQUOTE(JSON_EXTRACT(clinic_logo, '$[0].url')) WHERE clinic_logo IS NOT NULL AND JSON_LENGTH(clinic_logo) > 0"); + $this->addSql("ALTER TABLE clinics DROP COLUMN clinic_logo"); + $this->addSql("ALTER TABLE clinics CHANGE clinic_logo_new clinic_logo VARCHAR(500) DEFAULT NULL"); + } + + public function down(Schema $schema): void + { + $this->addSql("ALTER TABLE clinics ADD COLUMN clinic_logo_old LONGTEXT DEFAULT NULL COMMENT '(DC2Type:json)'"); + $this->addSql("UPDATE clinics SET clinic_logo_old = JSON_ARRAY(JSON_OBJECT('url', clinic_logo)) WHERE clinic_logo IS NOT NULL"); + $this->addSql("ALTER TABLE clinics DROP COLUMN clinic_logo"); + $this->addSql("ALTER TABLE clinics CHANGE clinic_logo_old clinic_logo LONGTEXT DEFAULT NULL COMMENT '(DC2Type:json)'"); + } +} diff --git a/src/Clinic/Controller/ClinicController.php b/src/Clinic/Controller/ClinicController.php index 38f095db..c4d0ce7a 100644 --- a/src/Clinic/Controller/ClinicController.php +++ b/src/Clinic/Controller/ClinicController.php @@ -59,7 +59,7 @@ class ClinicController extends BaseController new OA\Property(property: 'state', type: 'array', items: new OA\Items(type: 'integer'), nullable: true), new OA\Property(property: 'city', type: 'array', items: new OA\Items(type: 'integer'), nullable: true), new OA\Property(property: 'image_clinic', type: 'array', items: new OA\Items(type: 'string'), nullable: true), - new OA\Property(property: 'clinic_logo', type: 'array', items: new OA\Items(type: 'string'), nullable: true), + new OA\Property(property: 'clinic_logo', type: 'string', nullable: true), new OA\Property(property: 'doctors', type: 'array', items: new OA\Items(type: 'integer'), nullable: true), new OA\Property(property: 'specialties', type: 'array', items: new OA\Items(type: 'integer'), nullable: true), new OA\Property(property: 'doctor_services', type: 'array', items: new OA\Items(type: 'integer'), nullable: true), @@ -158,7 +158,7 @@ class ClinicController extends BaseController new OA\Property(property: 'state', type: 'array', items: new OA\Items(type: 'integer'), nullable: true), new OA\Property(property: 'city', type: 'array', items: new OA\Items(type: 'integer'), nullable: true), new OA\Property(property: 'image_clinic', type: 'array', items: new OA\Items(type: 'string'), nullable: true), - new OA\Property(property: 'clinic_logo', type: 'array', items: new OA\Items(type: 'string'), nullable: true), + new OA\Property(property: 'clinic_logo', type: 'string', nullable: true), new OA\Property(property: 'doctors', type: 'array', items: new OA\Items(type: 'integer'), nullable: true), new OA\Property(property: 'specialties', type: 'array', items: new OA\Items(type: 'integer'), nullable: true), new OA\Property(property: 'doctor_services', type: 'array', items: new OA\Items(type: 'integer'), nullable: true), @@ -417,8 +417,15 @@ class ClinicController extends BaseController if (array_key_exists('image_clinic', $data) && is_array($data['image_clinic'])) { $clinic->setImagesClinic($data['image_clinic']); } - if (array_key_exists('clinic_logo', $data) && is_array($data['clinic_logo'])) { - $clinic->setClinicLogo($data['clinic_logo']); + if (array_key_exists('clinic_logo', $data)) { + $logo = $data['clinic_logo']; + // Accept either a plain URL string or an upload-response object with 'url' key + if (is_array($logo) && isset($logo['url'])) { + $logo = $logo['url']; + } elseif (is_array($logo) && !empty($logo[0]['url'])) { + $logo = $logo[0]['url']; + } + $clinic->setClinicLogo(is_string($logo) ? $logo : null); } // ManyToMany: doctors diff --git a/src/Clinic/Entity/Clinic.php b/src/Clinic/Entity/Clinic.php index c25b79b4..9750880b 100644 --- a/src/Clinic/Entity/Clinic.php +++ b/src/Clinic/Entity/Clinic.php @@ -67,8 +67,8 @@ class Clinic #[ORM\Column(name: 'images_clinic', type: 'json', nullable: true)] private ?array $imagesClinic = null; - #[ORM\Column(name: 'clinic_logo', type: 'json', nullable: true)] - private ?array $clinicLogo = null; + #[ORM\Column(name: 'clinic_logo', type: 'string', length: 500, nullable: true)] + private ?string $clinicLogo = null; #[ORM\Column(name: 'created_at', type: 'integer')] private int $createdAt; @@ -135,7 +135,7 @@ class Clinic public function getProvinceId(): ?int { return $this->provinceId; } public function getRepresentationId(): ?int { return $this->representationId; } public function getImagesClinic(): ?array { return $this->imagesClinic; } - public function getClinicLogo(): ?array { return $this->clinicLogo; } + public function getClinicLogo(): ?string { return $this->clinicLogo; } public function getCreatedAt(): int { return $this->createdAt; } public function getUpdatedAt(): int { return $this->updatedAt; } public function getDoctors(): Collection { return $this->doctors; } @@ -155,7 +155,7 @@ class Clinic public function setProvinceId(?int $v): self { $this->provinceId = $v; $this->touch(); return $this; } public function setRepresentationId(?int $v): self { $this->representationId = $v; $this->touch(); return $this; } public function setImagesClinic(?array $v): self { $this->imagesClinic = $v; $this->touch(); return $this; } - public function setClinicLogo(?array $v): self { $this->clinicLogo = $v; $this->touch(); return $this; } + public function setClinicLogo(?string $v): self { $this->clinicLogo = $v; $this->touch(); return $this; } private function touch(): void { $this->updatedAt = time(); } @@ -166,7 +166,7 @@ class Clinic 'uuid' => $this->uuid, 'title' => $this->name, 'images_clinic' => $this->imagesClinic ?? [], - 'clinic_logo' => $this->clinicLogo ?? [], + 'clinic_logo' => $this->clinicLogo, 'phone_number' => $this->telephone, 'caption' => $this->info, 'list_bime' => array_map(fn(Insurance $i) => [