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
This commit is contained in:
1sonhador committed 2025-10-15 13:33:17 +01:00
1 parent 490d54f41d
commit 3f66fcf984
3 files changed
+42 -67

No files matched your search

@@ -289,6 +289,7 @@ class RedirectsController extends BaseController
"SELECT
r.id,
r.cuid,
r.analytics_slug,
r.name,
r.source_url,
r.target_url,
-67
View File
@@ -1,67 +0,0 @@
<?php
// Script para debug do redirect ID 17
$host = 'localhost';
$port = 3306;
$dbname = 'redirects_moneyflix';
$username = 'redirects_user';
$password = 'mf_redirect_2025';
try {
$pdo = new PDO("mysql:host=$host;port=$port;dbname=$dbname;charset=utf8mb4", $username, $password);
$pdo->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;
}
+41
View File
@@ -0,0 +1,41 @@
<?php
// Script para testar se a API está a retornar analytics_slug
require_once 'config.php';
use App\Modules\Redirects\Models\RedirectModel;
try {
$model = new RedirectModel();
$redirects = $model->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";
}