Added heartbeat for pingback.
authorCindy Cicalese <cindom@gmail.com>
Wed, 14 Mar 2018 07:31:17 +0000 (07:31 +0000)
committerCindy Cicalese <cindom@gmail.com>
Mon, 26 Mar 2018 15:48:27 +0000 (11:48 -0400)
The current implementation of the pingback feature sends new data on
the first page load after running the update.php maintenance script if
no ping has yet been sent for the wiki's current MediaWiki version.
There is no way by observing the event log to determine if a given wiki
is still operational, since no further pings are sent unless the
MediaWiki version on the wiki changes. Wikis that are created for
testing purposes or that have been decommissioned will continue to live
on in the pingback data.

This patch adds a monthly heartbeat ping. The structure of the heartbeat
ping is identical to the original ping. The heartbeat ping serves not
only to indicate that the wiki is still alive; it will send updated
information, so it will be possible to find out if any of the data, such
as the PHP version or memory limit, has changed since the last ping even
if the MediaWiki version has stayed the same.

Bug: T189785
Change-Id: Ia3077ed02e36eb6ad6ef0ae4d085ecaeb1547a52

RELEASE-NOTES-1.31
includes/Pingback.php

index cd0fd4c..4181a2c 100644 (file)
@@ -71,6 +71,7 @@ production.
 * Wikimedia\Rdbms\IDatabase::doAtomicSection(), non-native ::insertSelect(),
   and non-MySQL ::replace() and ::upsert() no longer roll back the whole
   transaction on failure.
+* (T189785) Added a monthly heartbeat ping to the pingback feature.
 
 === External library changes in 1.31 ===
 
index c3393bc..64b54f1 100644 (file)
@@ -68,14 +68,25 @@ class Pingback {
        }
 
        /**
-        * Has a pingback already been sent for this MediaWiki version?
+        * Has a pingback been sent in the last month for this MediaWiki version?
         * @return bool
         */
        private function checkIfSent() {
                $dbr = wfGetDB( DB_REPLICA );
-               $sent = $dbr->selectField(
-                       'updatelog', '1', [ 'ul_key' => $this->key ], __METHOD__ );
-               return $sent !== false;
+               $timestamp = $dbr->selectField(
+                       'updatelog',
+                       'ul_value',
+                       [ 'ul_key' => $this->key ],
+                       __METHOD__
+               );
+               if ( $timestamp === false ) {
+                       return false;
+               }
+               // send heartbeat ping if last ping was over a month ago
+               if ( time() - (int)$timestamp > 60 * 60 * 24 * 30 ) {
+                       return false;
+               }
+               return true;
        }
 
        /**
@@ -84,8 +95,14 @@ class Pingback {
         */
        private function markSent() {
                $dbw = wfGetDB( DB_MASTER );
-               return $dbw->insert(
-                       'updatelog', [ 'ul_key' => $this->key ], __METHOD__, 'IGNORE' );
+               $timestamp = time();
+               return $dbw->upsert(
+                       'updatelog',
+                       [ 'ul_key' => $this->key, 'ul_value' => $timestamp ],
+                       [ 'ul_key' => $this->key ],
+                       [ 'ul_value' => $timestamp ],
+                       __METHOD__
+               );
        }
 
        /**