From fbba5dae54e0396d859a7e32872d60e9909213a9 Mon Sep 17 00:00:00 2001 From: Cindy Cicalese Date: Wed, 14 Mar 2018 07:31:17 +0000 Subject: [PATCH] Added heartbeat for pingback. 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 | 1 + includes/Pingback.php | 29 +++++++++++++++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/RELEASE-NOTES-1.31 b/RELEASE-NOTES-1.31 index cd0fd4cdc5..4181a2c82b 100644 --- a/RELEASE-NOTES-1.31 +++ b/RELEASE-NOTES-1.31 @@ -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 === diff --git a/includes/Pingback.php b/includes/Pingback.php index c3393bcc1c..64b54f1e4b 100644 --- a/includes/Pingback.php +++ b/includes/Pingback.php @@ -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__ + ); } /** -- 2.20.1