From 0f3bf68fddf04a2e4ece0aa4c7b0f74f592fa476 Mon Sep 17 00:00:00 2001 From: hamed <15238-genius.ha@users.noreply.drupalcode.org> Date: Fri, 19 Jun 2026 00:35:07 +0330 Subject: [PATCH] feat(blog): refactor author data retrieval to handle potential missing authors --- config/packages/security.yaml | 2 +- src/Blog/Entity/Blog.php | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/config/packages/security.yaml b/config/packages/security.yaml index c0386bc6..2d9bac6f 100644 --- a/config/packages/security.yaml +++ b/config/packages/security.yaml @@ -33,7 +33,7 @@ security: provider: api_doc_provider public_endpoints: - pattern: ^/(api/v1/user/(send-code|verify-code|register|otp-login|reset-password)|oauth/token$|session/token|api/v1/categorys/|api/v1/doctors$|api/v1/clinics$|api/v1/clinic/doctor-list/|api/v1/clinic/[^/]+/addresses$|api/v1/clinic-pro/doctor-addresses/|api/v1/appointment-slots|api/v1/appointment-settings/month-availability/|api/v1/comments/|api/v1/rate/[^/]+$|api/v1/specialties|api/v1/blogs$|api/v1/clinic-invitation/|api/v1/pre-registration$) + pattern: ^/(api/v1/user/(send-code|verify-code|register|otp-login|reset-password)|oauth/token$|session/token|api/v1/categorys/|api/v1/doctors$|api/v1/clinics$|api/v1/clinic/doctor-list/|api/v1/clinic/[^/]+/addresses$|api/v1/clinic-pro/doctor-addresses/|api/v1/appointment-slots|api/v1/appointment-settings/month-availability/|api/v1/comments/|api/v1/rate/[^/]+$|api/v1/specialties|api/v1/blogs$|api/v1/tags$|api/v1/clinic-invitation/|api/v1/pre-registration$) stateless: true security: false diff --git a/src/Blog/Entity/Blog.php b/src/Blog/Entity/Blog.php index 0f59671e..b5650ef8 100644 --- a/src/Blog/Entity/Blog.php +++ b/src/Blog/Entity/Blog.php @@ -110,15 +110,29 @@ class Blog 'image_url' => $this->imageUrl, 'tags' => $this->tags, 'status' => $this->status, - 'author' => [ - 'uuid' => $this->author->getUuid(), - 'name' => $this->author->getRealName(), - ], + 'author' => $this->authorToArray(), 'created_at' => $this->createdAt, 'updated_at' => $this->updatedAt, ]; } + private function authorToArray(): ?array + { + if ($this->author === null) { + return null; + } + // The referenced user may have been deleted; a lazy proxy then throws + // EntityNotFoundException on access. Treat a missing author as null. + try { + return [ + 'uuid' => $this->author->getUuid(), + 'name' => $this->author->getRealName(), + ]; + } catch (\Doctrine\ORM\EntityNotFoundException) { + return null; + } + } + public function toListArray(): array { return [