<?php
require_once __DIR__ . '/../config.php';

try {
    $stmt = $pdo->prepare("
        UPDATE posts
        SET 
            status = 'published',
            scheduled_at = NULL,
            updated_at = NOW()
        WHERE status = 'scheduled'
        AND scheduled_at IS NOT NULL
        AND scheduled_at <= NOW()
    ");

    $stmt->execute();

    echo 'Published scheduled posts: ' . $stmt->rowCount();

} catch (PDOException $e) {
    error_log('Scheduled post publish failed: ' . $e->getMessage());
    http_response_code(500);
    echo 'Scheduled post publish failed.';
}