summaryrefslogtreecommitdiff
path: root/healthcheck.php
blob: ed4191659df78f94e2c4c618b3f39b23df72ba97 (plain)
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
<?php
function communievents_healthcheck() {
    global $wpdb;

    $tablename = $wpdb->prefix . 'communievents_events';

    $evcount = $wpdb->get_var("SELECT COUNT(id) FROM $tablename", 0, 0);
    $lastsync = $wpdb->get_var("SELECT MAX(lastsync) FROM $tablename", 0, 0);
    $nextsync = wp_next_scheduled('communievents_cron_hook');

    if ($lastsync) {
        $lastsync_dt = new DateTime("@$lastsync");
        $lastsync_str = $lastsync_dt->format('Y-m-d H:i:s');
    } else {
        $lastsync_str = "NEVER";
    }

    if ($nextsync) {
        $nextsync_dt = new DateTime("@$nextsync");
        $nextsync_str = $nextsync_dt->format('Y-m-d H:i:s');
    } else {
        $nextsync_str = "NEVER";
    }

    $now_dt = new DateTime('now');
    $now_str = $now_dt->format('Y-m-d H:i:s');

    return "<table border><caption>CommuniEvents Health</caption>" .
        "<tr><td>Event Count:<td>$evcount" .
        "<tr><td>Last Sync:<td>$lastsync_str" .
        "<tr><td>Next Sync:<td>$nextsync_str" .
        "<tr><td>Now:<td>$now_str" .
        "</table>";
}

function communievents_setup_healthcheck() {
    add_shortcode('communievents-healthcheck', 'communievents_healthcheck');
}