feat(clinic): change clinic_logo from JSON array to single URL string

This commit is contained in:
hamed
2026-06-10 15:09:19 +03:30
parent 28dbfa67e2
commit 30cf2e7a8c
3 changed files with 52 additions and 9 deletions
+36
View File
@@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20260610113711 extends AbstractMigration
{
public function getDescription(): string
{
return 'Change clinic_logo from JSON array to single URL string';
}
public function up(Schema $schema): void
{
// Extract first URL from JSON array into a plain temp column
$this->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)'");
}
}
+11 -4
View File
@@ -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
+5 -5
View File
@@ -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) => [