From c407600e44c9c8b4827c8e9ea04bb6f5e301861e Mon Sep 17 00:00:00 2001 From: Jose Andres Tejerina Date: Wed, 21 Jan 2026 15:58:21 -0300 Subject: [PATCH] fix: refactor for presentation formatter --- .../BasePresentationAuditLogFormatter.php | 53 ++----------------- .../PresentationEventApiAuditLogFormatter.php | 21 ++------ ...resentationSubmissionAuditLogFormatter.php | 8 +-- 3 files changed, 13 insertions(+), 69 deletions(-) diff --git a/app/Audit/ConcreteFormatters/PresentationFormatters/BasePresentationAuditLogFormatter.php b/app/Audit/ConcreteFormatters/PresentationFormatters/BasePresentationAuditLogFormatter.php index 339b6bdf2..2a388e326 100644 --- a/app/Audit/ConcreteFormatters/PresentationFormatters/BasePresentationAuditLogFormatter.php +++ b/app/Audit/ConcreteFormatters/PresentationFormatters/BasePresentationAuditLogFormatter.php @@ -22,52 +22,9 @@ abstract class BasePresentationAuditLogFormatter extends AbstractAuditLogFormatter { - protected string $event_type; - public function __construct(string $event_type) { - $this->event_type = $event_type; - } - - protected function extractChangedFields(array $change_set): array - { - $changed_fields = []; - $old_status = null; - $new_status = null; - - if (isset($change_set['Title'])) { - $changed_fields[] = "title"; - } - if (isset($change_set['Abstract'])) { - $changed_fields[] = "abstract"; - } - if (isset($change_set['ProblemAddressed'])) { - $changed_fields[] = "problem_addressed"; - } - if (isset($change_set['AttendeesExpectedLearnt'])) { - $changed_fields[] = "attendees_expected_learnt"; - } - - if (isset($change_set['Status'])) { - $changed_fields[] = "status"; - $old_status = $change_set['Status'][0] ?? null; - $new_status = $change_set['Status'][1] ?? null; - } - if (isset($change_set['CategoryID']) || isset($change_set['category'])) { - $changed_fields[] = "track"; - } - if (isset($change_set['Published'])) { - $changed_fields[] = "published"; - } - if (isset($change_set['SelectionPlanID'])) { - $changed_fields[] = "selection_plan"; - } - - return [ - 'fields' => !empty($changed_fields) ? implode(', ', $changed_fields) : 'properties', - 'old_status' => $old_status, - 'new_status' => $new_status, - ]; + parent::__construct($event_type); } protected function getPresentationData(Presentation $subject): array @@ -91,7 +48,7 @@ protected function getPresentationData(Presentation $subject): array ]; } - public function format($subject, array $change_set): ?string + public function format(mixed $subject, array $change_set): ?string { if (!$subject instanceof Presentation) { return null; @@ -105,9 +62,7 @@ public function format($subject, array $change_set): ?string return $this->formatCreation($data); case IAuditStrategy::EVENT_ENTITY_UPDATE: - $extracted = $this->extractChangedFields($change_set); - $extracted['change_set'] = $change_set; - return $this->formatUpdate($data, $extracted); + return $this->formatUpdate($data, $change_set); case IAuditStrategy::EVENT_ENTITY_DELETION: return $this->formatDeletion($data); @@ -121,7 +76,7 @@ public function format($subject, array $change_set): ?string abstract protected function formatCreation(array $data): string; - abstract protected function formatUpdate(array $data, array $extracted): string; + abstract protected function formatUpdate(array $data, array $change_set): string; abstract protected function formatDeletion(array $data): string; } diff --git a/app/Audit/ConcreteFormatters/PresentationFormatters/PresentationEventApiAuditLogFormatter.php b/app/Audit/ConcreteFormatters/PresentationFormatters/PresentationEventApiAuditLogFormatter.php index 78cf0c3e2..70efffb60 100644 --- a/app/Audit/ConcreteFormatters/PresentationFormatters/PresentationEventApiAuditLogFormatter.php +++ b/app/Audit/ConcreteFormatters/PresentationFormatters/PresentationEventApiAuditLogFormatter.php @@ -30,25 +30,13 @@ protected function formatCreation(array $data): string ); } - protected function formatUpdate(array $data, array $extracted): string + protected function formatUpdate(array $data, array $change_set): string { - if ($extracted['old_status'] && $extracted['new_status']) { - return sprintf( - "Presentation '%s' (%s) status changed: %s → %s (%s changed) by user %s", - $data['title'], - $data['id'], - strtoupper($extracted['old_status']), - strtoupper($extracted['new_status']), - $extracted['fields'], - $this->getUserInfo() - ); - } - return sprintf( - "Presentation '%s' (%s) modified (%s changed) by user %s", + "Presentation '%s' (%s) updated: %s by user %s", $data['title'], $data['id'], - $extracted['fields'], + $this->buildChangeDetails($change_set), $this->getUserInfo() ); } @@ -56,11 +44,12 @@ protected function formatUpdate(array $data, array $extracted): string protected function formatDeletion(array $data): string { return sprintf( - "Presentation '%s' (%s) created by '%s' under track '%s' was removed by user %s", + "Presentation '%s' (%s) created by '%s' under track '%s' (Plan: %s) was removed by user %s", $data['title'], $data['id'], $data['creator_name'], $data['category_name'], + $data['plan_name'], $this->getUserInfo() ); } diff --git a/app/Audit/ConcreteFormatters/PresentationFormatters/PresentationSubmissionAuditLogFormatter.php b/app/Audit/ConcreteFormatters/PresentationFormatters/PresentationSubmissionAuditLogFormatter.php index 3e4795d20..813dcb48a 100644 --- a/app/Audit/ConcreteFormatters/PresentationFormatters/PresentationSubmissionAuditLogFormatter.php +++ b/app/Audit/ConcreteFormatters/PresentationFormatters/PresentationSubmissionAuditLogFormatter.php @@ -30,14 +30,13 @@ protected function formatCreation(array $data): string ); } - protected function formatUpdate(array $data, array $extracted): string + protected function formatUpdate(array $data, array $change_set): string { - $change_details = $this->buildChangeDetails($extracted['change_set']); return sprintf( "Presentation '%s' (%s) updated: %s by user %s", $data['title'], $data['id'], - $change_details, + $this->buildChangeDetails($change_set), $this->getUserInfo() ); } @@ -45,11 +44,12 @@ protected function formatUpdate(array $data, array $extracted): string protected function formatDeletion(array $data): string { return sprintf( - "Presentation '%s' (%s) submitted by '%s' to track '%s' was deleted by user %s", + "Presentation '%s' (%s) submitted by '%s' to track '%s' (Plan: %s) was deleted by user %s", $data['title'], $data['id'], $data['creator_name'], $data['category_name'], + $data['plan_name'], $this->getUserInfo() ); }