mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-12 09:26:05 +00:00
Merge "Add various read-only mode checks"
This commit is contained in:
commit
e0d634689d
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -52,6 +52,9 @@ class EchoUserNotificationGateway {
|
|||
}
|
||||
|
||||
$dbw = $this->dbFactory->getEchoDb( DB_MASTER );
|
||||
if ( $dbw->isReadOnly() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $dbw->update(
|
||||
self::$notificationTable,
|
||||
|
|
Loading…
Reference in a new issue