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

$domainId = isset($_GET['id']) ? (int)$_GET['id'] : 0;
if ($domainId <= 0) {
    redirect('/admin/domain/list.php?publish_status=missing');
}

try {
    $result = publish_domain_static($domainId);
    $domainName = isset($result['domain']['domain']) ? (string)$result['domain']['domain'] : '';
    $count = isset($result['published_count']) ? (int)$result['published_count'] : 0;
    redirect('/admin/domain/list.php?publish_status=success&published_domain=' . urlencode($domainName) . '&published_count=' . $count);
} catch (Exception $e) {
    redirect('/admin/domain/list.php?publish_status=error&publish_message=' . urlencode($e->getMessage()));
}
