Merge "Add various read-only mode checks"

This commit is contained in:
jenkins-bot 2018-02-22 20:33:05 +00:00 committed by Gerrit Code Review
commit e0d634689d
4 changed files with 15 additions and 2 deletions

View file

@ -1,5 +1,6 @@
<?php
use MediaWiki\MediaWikiServices;
use Wikimedia\Rdbms\LoadBalancer;
/**
* Database factory class, this will determine whether to use the main database
@ -41,6 +42,13 @@ class MWEchoDbFactory {
return new self( $wgEchoCluster, $wgEchoSharedTrackingDB, $wgEchoSharedTrackingCluster );
}
/**
* @return bool
*/
public function isReadOnly() {
return ( $this->getLB()->getReadOnlyReason() !== false );
}
/**
* Get the database load balancer
* @return LoadBalancer
@ -111,7 +119,7 @@ class MWEchoDbFactory {
// Use the external db defined for Echo
if ( $wgEchoCluster ) {
$lb = $services->getDBLoadBalancerFactory()->getExternalLB( $wgEchoCluster, $wiki );
$lb = $services->getDBLoadBalancerFactory()->getExternalLB( $wgEchoCluster );
} else {
if ( $wiki === false ) {
$lb = $services->getDBLoadBalancer();

View file

@ -103,7 +103,7 @@ class EchoUnreadWikis {
*/
public function updateCount( $wiki, $alertCount, $alertTime, $msgCount, $msgTime ) {
$dbw = $this->getDB( DB_MASTER );
if ( $dbw === false ) {
if ( $dbw === false || $dbw->isReadOnly() ) {
return;
}

View file

@ -9,6 +9,8 @@ class ApiEchoMarkRead extends ApiBase {
$user = $this->getUser();
if ( $user->isAnon() ) {
$this->dieWithError( 'apierror-mustbeloggedin-generic', 'login-required' );
} elseif ( MWEchoDbFactory::newFromDefault()->isReadOnly() ) {
$this->dieReadOnly();
}
$notifUser = MWEchoNotifUser::newFromUser( $user );

View file

@ -52,6 +52,9 @@ class EchoUserNotificationGateway {
}
$dbw = $this->dbFactory->getEchoDb( DB_MASTER );
if ( $dbw->isReadOnly() ) {
return false;
}
return $dbw->update(
self::$notificationTable,