<?php
// Blocks member accounts that did not activate within 2 hours.
// Run every 15 minutes from cron:
// php /path/to/walkly/cron/block_unactivated_members.php

require __DIR__ . '/../api/bootstrap.php';

use App\Core\Database;

try {
    $pdo = Database::connection();
    $stmt = $pdo->prepare('UPDATE users u JOIN roles r ON r.id = u.role_id SET u.status = "blocked", u.blocked_at = NOW(), u.blocked_reason = "Activation link expired after 2 hours", u.updated_at = NOW() WHERE r.name = "member" AND u.status = "inactive" AND u.email_verified_at IS NULL AND u.activation_expires_at IS NOT NULL AND u.activation_expires_at < NOW()');
    $stmt->execute();
    echo '[' . date('c') . '] Blocked unactivated accounts: ' . $stmt->rowCount() . PHP_EOL;
} catch (Throwable $e) {
    echo '[' . date('c') . '] Failed: ' . $e->getMessage() . PHP_EOL;
    exit(1);
}
