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 @@ +
+ + +
+
+
Analytics Público
+

Partilha este link para permitir acesso público aos analytics deste redirect

+
+ + + + Abrir + +
+
+
+
Edit Redirect Test Redirect @@ -253,6 +278,49 @@ function deleteFilter(filterId) { }); } } + +function copyAnalyticsUrl() { + const analyticsUrl = document.getElementById('analyticsUrl'); + analyticsUrl.select(); + analyticsUrl.setSelectionRange(0, 99999); // For mobile devices + + try { + document.execCommand('copy'); + + // Show success feedback + const button = event.target.closest('button'); + const originalText = button.innerHTML; + button.innerHTML = 'Copiado!'; + button.classList.remove('btn-outline-secondary'); + button.classList.add('btn-success'); + + setTimeout(() => { + button.innerHTML = originalText; + button.classList.remove('btn-success'); + button.classList.add('btn-outline-secondary'); + }, 2000); + + } catch (err) { + // Fallback for modern browsers + if (navigator.clipboard) { + navigator.clipboard.writeText(analyticsUrl.value).then(() => { + const button = event.target.closest('button'); + const originalText = button.innerHTML; + button.innerHTML = 'Copiado!'; + button.classList.remove('btn-outline-secondary'); + button.classList.add('btn-success'); + + setTimeout(() => { + button.innerHTML = originalText; + button.classList.remove('btn-success'); + button.classList.add('btn-outline-secondary'); + }, 2000); + }); + } else { + alert('Não foi possível copiar automaticamente. Por favor, selecione e copie manualmente.'); + } + } +}