![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/.cursor-server/data/User/History/-3d687056/ |
<?php
// Database Connection Test Script
// This script tests the database connection and verifies the credit system tables
echo "š§ Testing Database Connection and Credit System Setup...\n\n";
try {
// Test database connection
require_once 'config/database.php';
$pdo = getDBConnection();
echo "ā
Database connection successful!\n\n";
// Test users table structure
echo "š Checking users table structure...\n";
$stmt = $pdo->query("DESCRIBE users");
$columns = $stmt->fetchAll(PDO::FETCH_COLUMN);
$required_columns = ['credits', 'subscription_expires', 'commercial_rights_expires', 'expiration_warning_sent'];
$missing_columns = [];
foreach ($required_columns as $column) {
if (!in_array($column, $columns)) {
$missing_columns[] = $column;
}
}
if (empty($missing_columns)) {
echo "ā
Users table has all required credit columns\n";
} else {
echo "ā Missing columns in users table: " . implode(', ', $missing_columns) . "\n";
echo " Run the database_updates.sql script to add these columns\n";
}
// Test credit-related tables
$tables_to_check = [
'credit_purchases' => 'Credit purchases tracking',
'credit_transactions' => 'Credit transaction history',
'track_purchases' => 'Track purchase records',
'user_follows' => 'User following relationships',
'music_tracks' => 'Music tracks storage'
];
echo "\nš Checking credit system tables...\n";
foreach ($tables_to_check as $table => $description) {
try {
$stmt = $pdo->query("SELECT COUNT(*) FROM $table LIMIT 1");
echo "ā
$table table exists ($description)\n";
} catch (Exception $e) {
echo "ā $table table missing ($description)\n";
}
}
// Test log files
echo "\nš Checking log files...\n";
$log_files = [
'logs/credit_expirations.log' => 'Credit expiration events',
'logs/user_credits.log' => 'User credit operations',
'logs/stripe_actions.log' => 'Stripe webhook events',
'logs/track_purchases.log' => 'Track purchase events',
'logs/track_purchase_errors.log' => 'Track purchase errors'
];
foreach ($log_files as $file => $description) {
if (file_exists($file) && is_writable($file)) {
echo "ā
$file exists and writable ($description)\n";
} else {
echo "ā $file missing or not writable ($description)\n";
}
}
// Test cron script
echo "\nš Checking cron script...\n";
if (file_exists('cron/expire_credits.php')) {
echo "ā
Cron script exists (cron/expire_credits.php)\n";
} else {
echo "ā Cron script missing (cron/expire_credits.php)\n";
}
// Test webhook script
echo "\nš Checking webhook script...\n";
if (file_exists('webhooks/stripe.php')) {
echo "ā
Webhook script exists (webhooks/stripe.php)\n";
} else {
echo "ā Webhook script missing (webhooks/stripe.php)\n";
}
// Sample data test
echo "\nš Testing sample data operations...\n";
// Test user credit update
try {
$stmt = $pdo->prepare("UPDATE users SET credits = 10 WHERE id = 1 LIMIT 1");
$stmt->execute();
echo "ā
User credit update test successful\n";
} catch (Exception $e) {
echo "ā User credit update test failed: " . $e->getMessage() . "\n";
}
// Test credit transaction insert
try {
$stmt = $pdo->prepare("INSERT INTO credit_transactions (user_id, amount, type, description) VALUES (1, 10, 'purchase', 'Test transaction')");
$stmt->execute();
echo "ā
Credit transaction insert test successful\n";
// Clean up test data
$stmt = $pdo->prepare("DELETE FROM credit_transactions WHERE description = 'Test transaction'");
$stmt->execute();
} catch (Exception $e) {
echo "ā Credit transaction insert test failed: " . $e->getMessage() . "\n";
}
echo "\nš Database and credit system setup test complete!\n";
echo "\nš Next steps:\n";
echo "1. Run database_updates.sql if any tables/columns are missing\n";
echo "2. Run ./setup_cron.sh to set up the cron job\n";
echo "3. Test the cron job manually: php cron/expire_credits.php\n";
echo "4. Monitor logs for any issues\n";
} catch (Exception $e) {
echo "ā Database connection failed: " . $e->getMessage() . "\n";
echo "\nš§ Please check your database configuration in config/database.php\n";
}
?>