<?php

/**
 * Install Cron Logs Table
 * Run this script to create the cron logs table
 */

require_once dirname(__DIR__) . '/init.php';

echo "Installing Cron Logs Table...\n";

// Read the SQL file
$sqlFile = __DIR__ . '/create_cron_logs_table.sql';
if (!file_exists($sqlFile)) {
    echo "Error: SQL file not found: $sqlFile\n";
    exit(1);
}

$sql = file_get_contents($sqlFile);

// Execute the SQL
try {
    ORM::raw_execute($sql);
    echo "✓ Cron logs table created successfully!\n";
    
    // Test the table
    $test = ORM::for_table('tbl_cron_logs')->count();
    echo "✓ Table test successful - found $test records\n";
    
    echo "\nCron logs system is now ready!\n";
    echo "You can view logs at: " . APP_URL . "/settings/cron-logs\n";
    
} catch (Exception $e) {
    echo "✗ Error creating table: " . $e->getMessage() . "\n";
    exit(1);
}

echo "\nInstallation completed successfully!\n";
