<?php
require __DIR__ . '/../../app/bootstrap.php';
require __DIR__ . '/../../app/database.php';
require_login();

$domainId = isset($_GET['domain_id']) ? (int)$_GET['domain_id'] : 0;
$force = isset($_GET['force']) && (string)$_GET['force'] === '1';

try {
    $result = rebuild_tag_slugs($domainId, $force);
    redirect('/content.php?tag_slug_status=success&tag_slug_total=' . urlencode((string)(isset($result['total_count']) ? (int)$result['total_count'] : 0)) . '&tag_slug_updated=' . urlencode((string)(isset($result['updated_count']) ? (int)$result['updated_count'] : 0)) . '&tag_slug_skipped=' . urlencode((string)(isset($result['skipped_count']) ? (int)$result['skipped_count'] : 0)));
} catch (Exception $e) {
    redirect('/content.php?tag_slug_status=error&tag_slug_message=' . urlencode($e->getMessage()));
}
