summaryrefslogtreecommitdiff
path: root/healthcheck.php
diff options
context:
space:
mode:
authorJonas Kümmerlin <jonas@kuemmerlin.eu>2024-01-27 13:05:41 +0100
committerJonas Kümmerlin <jonas@kuemmerlin.eu>2024-01-27 13:05:41 +0100
commit907f39db4ab00de43016646660d9d1ca9c73d1f9 (patch)
tree49642a7e9ab374c3eab2ae91b12a24fdf4a21f62 /healthcheck.php
initial commitHEADmaster
Diffstat (limited to 'healthcheck.php')
-rw-r--r--healthcheck.php38
1 files changed, 38 insertions, 0 deletions
diff --git a/healthcheck.php b/healthcheck.php
new file mode 100644
index 0000000..ed41916
--- /dev/null
+++ b/healthcheck.php
@@ -0,0 +1,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');
+}