From 151bac0e20da1ad0fa4e7dbb2ac3061ff4d48bcc Mon Sep 17 00:00:00 2001 From: 1sonhador <1sonhador@gmail.com> Date: Wed, 15 Oct 2025 13:28:07 +0100 Subject: [PATCH] fix: Add analytics URL copy functionality and fix delete redirect error - Add analytics public URL input with copy button in redirect view - Fix deleteCreativeByRedirectId to handle missing creatives gracefully - Add copyAnalyticsUrl JavaScript function with visual feedback - Improve error handling in redirect deletion process --- .../Services/RedirectCreativeService.php | 27 +++-- crm/Redirects/Views/redirects/view.php | 68 ++++++++++++ crm/check_tables.php | 45 ++++++++ crm/populate_analytics_slugs.php | 84 -------------- crm/populate_simple.php | 104 ------------------ crm/test_analytics_slug.php | 48 ++++++++ 6 files changed, 178 insertions(+), 198 deletions(-) create mode 100644 crm/check_tables.php delete mode 100644 crm/populate_analytics_slugs.php delete mode 100644 crm/populate_simple.php create mode 100644 crm/test_analytics_slug.php diff --git a/crm/Redirects/Services/RedirectCreativeService.php b/crm/Redirects/Services/RedirectCreativeService.php index a6e1997..1482647 100644 --- a/crm/Redirects/Services/RedirectCreativeService.php +++ b/crm/Redirects/Services/RedirectCreativeService.php @@ -162,17 +162,24 @@ class RedirectCreativeService */ public function deleteCreativeByRedirectId(int $redirectId): bool { - $creative = $this->getCreativeByRedirectId($redirectId); - if (!$creative) { - return false; + try { + $creative = $this->getCreativeByRedirectId($redirectId); + if (!$creative) { + // Se não existe creative associado, consideramos sucesso + return true; + } + + $sql = "UPDATE advertising_creatives SET + is_active = 0, + deleted_at = CURRENT_TIMESTAMP + WHERE id = ?"; + + return $this->db->query($sql, [$creative['id']]) > 0; + } catch (\Exception $e) { + // Log do erro mas não falha a operação + error_log("Error deleting creative for redirect {$redirectId}: " . $e->getMessage()); + return true; // Consideramos sucesso para não bloquear a eliminação do redirect } - - $sql = "UPDATE advertising_creatives SET - is_active = 0, - deleted_at = CURRENT_TIMESTAMP - WHERE id = ?"; - - return $this->db->query($sql, [$creative['id']]) > 0; } /** diff --git a/crm/Redirects/Views/redirects/view.php b/crm/Redirects/Views/redirects/view.php index 64eb1d6..9f5a69e 100644 --- a/crm/Redirects/Views/redirects/view.php +++ b/crm/Redirects/Views/redirects/view.php @@ -63,6 +63,31 @@ +
Partilha este link para permitir acesso público aos analytics deste redirect
+