-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_onesignal.php
More file actions
69 lines (61 loc) · 2.67 KB
/
Copy pathdebug_onesignal.php
File metadata and controls
69 lines (61 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once 'includes/db.php';
echo "<h1>OneSignal Debug Status</h1>";
try {
// Check table existence
$stmt = $pdo->query("SHOW TABLES LIKE 'user_devices'");
if (!$stmt->fetch()) {
echo "<p style='color:red'>Table 'user_devices' DOES NOT EXIST!</p>";
echo "<h2>Attempting to create table now...</h2>";
$sql = "CREATE TABLE IF NOT EXISTS user_devices (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NULL,
onesignal_player_id VARCHAR(255) UNIQUE,
device_id VARCHAR(255) NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL
)";
$pdo->exec($sql);
echo "<p style='color:green'>Table created successfully (hopefully).</p>";
} else {
echo "<p style='color:green'>Table 'user_devices' exists.</p>";
}
// Check row count
$stmt = $pdo->query("SELECT COUNT(*) FROM user_devices");
$count = $stmt->fetchColumn();
echo "<p>Total devices registered: <b>$count</b></p>";
if ($count > 0) {
echo "<h2>Latest 10 Devices:</h2>";
echo "<table border='1'><tr><th>ID</th><th>User ID</th><th>Player ID</th><th>Updated</th></tr>";
$stmt = $pdo->query("SELECT * FROM user_devices ORDER BY updated_at DESC LIMIT 10");
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo "<tr>
<td>{$row['id']}</td>
<td>" . ($row['user_id'] ?? 'GUEST') . "</td>
<td>{$row['onesignal_player_id']}</td>
<td>{$row['updated_at']}</td>
</tr>";
}
echo "</table>";
}
// Show Debug Log
echo "<h2>Recent Debug Logs (onesignal_debug.log):</h2>";
$log_file = 'onesignal_debug.log';
if (file_exists($log_file)) {
echo "<pre style='background:#f4f4f4; padding:10px; border:1px solid #ccc; max-height:400px; overflow:auto;'>";
echo htmlspecialchars(file_get_contents($log_file));
echo "</pre>";
} else {
echo "<p>No log file found yet.</p>";
}
} catch (PDOException $e) {
echo "<p style='color:red'>Error: " . $e->getMessage() . "</p>";
}
echo "<h2>Instructions</h2>";
echo "<p>1. Open this page in your browser: <code>http://your-domain/CPT_LEAGUE/debug_onesignal.php</code></p>";
echo "<p>2. If 'Total devices' is 0, then the App is NOT sending IDs correctly.</p>";
echo "<p>3. If IDs exist but no notifications are received, check <code>onesignal_debug.log</code> in the root folder.</p>";
?>