}
/**
- * 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_SLAVE );
- $sent = $dbr->selectField(
- 'updatelog', '1', [ 'ul_key' => $this->key ], __METHOD__ );
- return $sent !== false;
+ $dbr = wfGetDB( DB_REPLICA );
+ $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;
}
/**
*/
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__
+ );
}
/**
*/
private function getOrCreatePingbackId() {
if ( !$this->id ) {
- $id = wfGetDB( DB_SLAVE )->selectField(
+ $id = wfGetDB( DB_REPLICA )->selectField(
'updatelog', 'ul_value', [ 'ul_key' => 'PingBack' ] );
if ( $id == false ) {
*
* The schema for the data is located at:
* <https://meta.wikimedia.org/wiki/Schema:MediaWikiPingback>
+ * @return bool
*/
public function sendPingback() {
if ( !$this->acquireLock() ) {