From 3f66fcf98491c55d32d2546cba2ed8a82107bd3a Mon Sep 17 00:00:00 2001 From: 1sonhador <1sonhador@gmail.com> Date: Wed, 15 Oct 2025 13:33:17 +0100 Subject: [PATCH] fix: Add analytics_slug to API redirects endpoint - Include analytics_slug in apiRedirects() query - Fix missing analytics_slug in Vue.js data - Ensure analytics links appear in redirects list --- .../Controllers/RedirectsController.php | 1 + crm/debug_redirect_17.php | 67 ------------------- crm/test_api.php | 41 ++++++++++++ 3 files changed, 42 insertions(+), 67 deletions(-) delete mode 100644 crm/debug_redirect_17.php create mode 100644 crm/test_api.php diff --git a/crm/Redirects/Controllers/RedirectsController.php b/crm/Redirects/Controllers/RedirectsController.php index 67f38f0..b8fd9f2 100644 --- a/crm/Redirects/Controllers/RedirectsController.php +++ b/crm/Redirects/Controllers/RedirectsController.php @@ -289,6 +289,7 @@ class RedirectsController extends BaseController "SELECT r.id, r.cuid, + r.analytics_slug, r.name, r.source_url, r.target_url, diff --git a/crm/debug_redirect_17.php b/crm/debug_redirect_17.php deleted file mode 100644 index be6b5a4..0000000 --- a/crm/debug_redirect_17.php +++ /dev/null @@ -1,67 +0,0 @@ -setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - - echo "🔍 Debug do Redirect ID 17...\n\n"; - - // Buscar redirect ID 17 - $stmt = $pdo->prepare(" - SELECT id, name, cuid, analytics_slug, status, created_at - FROM redirects - WHERE id = 17 - "); - $stmt->execute(); - $redirect = $stmt->fetch(PDO::FETCH_ASSOC); - - if ($redirect) { - echo "📋 Redirect encontrado:\n"; - echo "ID: {$redirect['id']}\n"; - echo "Nome: {$redirect['name']}\n"; - echo "CUID: {$redirect['cuid']}\n"; - echo "Analytics Slug: " . ($redirect['analytics_slug'] ?: 'NULL/VAZIO') . "\n"; - echo "Status: {$redirect['status']}\n"; - echo "Criado: {$redirect['created_at']}\n"; - - if (empty($redirect['analytics_slug'])) { - echo "\n⚠️ PROBLEMA: analytics_slug está vazio!\n"; - echo "Vou gerar um novo analytics_slug...\n"; - - $newSlug = generateCuid2(); - $updateStmt = $pdo->prepare("UPDATE redirects SET analytics_slug = ? WHERE id = ?"); - $result = $updateStmt->execute([$newSlug, 17]); - - if ($result) { - echo "✅ Analytics slug atualizado: {$newSlug}\n"; - } else { - echo "❌ Falha ao atualizar analytics slug\n"; - } - } else { - echo "\n✅ Analytics slug está presente: {$redirect['analytics_slug']}\n"; - } - } else { - echo "❌ Redirect ID 17 não encontrado!\n"; - } - -} catch (Exception $e) { - echo "❌ Erro: " . $e->getMessage() . "\n"; -} - -function generateCuid2(): string -{ - $characters = 'abcdefghijklmnopqrstuvwxyz0123456789'; - $cuid = ''; - - for ($i = 0; $i < 25; $i++) { - $cuid .= $characters[random_int(0, strlen($characters) - 1)]; - } - - return $cuid; -} diff --git a/crm/test_api.php b/crm/test_api.php new file mode 100644 index 0000000..cc6ccfd --- /dev/null +++ b/crm/test_api.php @@ -0,0 +1,41 @@ +getAll(); + + echo "🔍 Testando API de redirects...\n\n"; + echo "📊 Total de redirects: " . count($redirects) . "\n\n"; + + if (!empty($redirects)) { + $first = $redirects[0]; + echo "📋 Primeiro redirect:\n"; + echo "ID: {$first['id']}\n"; + echo "Nome: {$first['name']}\n"; + echo "CUID: {$first['cuid']}\n"; + echo "Analytics Slug: " . ($first['analytics_slug'] ?? 'NULL') . "\n"; + + // Verificar se todos têm analytics_slug + $withoutSlug = 0; + foreach ($redirects as $redirect) { + if (empty($redirect['analytics_slug'])) { + $withoutSlug++; + } + } + + echo "\n📈 Redirects sem analytics_slug: {$withoutSlug}\n"; + + if ($withoutSlug > 0) { + echo "⚠️ PROBLEMA: Alguns redirects não têm analytics_slug!\n"; + } else { + echo "✅ Todos os redirects têm analytics_slug!\n"; + } + } + +} catch (Exception $e) { + echo "❌ Erro: " . $e->getMessage() . "\n"; +}