From 15da6673a43d9b32ccd4ab7cdd69c85202f880d6 Mon Sep 17 00:00:00 2001 From: James Montalvo Date: Fri, 12 Jun 2020 10:45:05 -0500 Subject: [PATCH] Use DB_MASTER when using query() to avoid error This appears to be a more recent change, that query() causes the following error when used along with DB_REPLICA: Wikimedia\Rdbms\DBReadOnlyRoleError from line 1195 of $MW_INSTALL_PATH/includes/libs/rdbms/database/Database.php: Cannot write; target role is DB_REPLICA While WatchAnalytics was not using query() to write to the database, it is possible to use query() that way, so it makes sense for MW to be more strict with its usage. --- includes/WatchAnalyticsParserFunctions.php | 4 ++-- specials/SpecialClearPendingReviews.php | 3 +-- specials/SpecialWatchAnalytics.php | 6 +++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/includes/WatchAnalyticsParserFunctions.php b/includes/WatchAnalyticsParserFunctions.php index 40b9d47..881267c 100644 --- a/includes/WatchAnalyticsParserFunctions.php +++ b/includes/WatchAnalyticsParserFunctions.php @@ -47,7 +47,7 @@ public static function renderUnderwatchedCategories( &$parser, $frame, $args ) { // $args = self::processArgs( $frame, $args, array(0) ); // $namespace = $args[0]; - $dbr = wfGetDB( DB_REPLICA ); + $dbr = wfGetDB( DB_MASTER ); $query = " SELECT * FROM ( @@ -121,7 +121,7 @@ public static function renderWatchersNeeded( &$parser, $frame, $args ) { $rangeTimestamp = date( 'YmdHis', time() - ( $numDays * 24 * 60 * 60 ) ); - $dbr = wfGetDB( DB_REPLICA ); + $dbr = wfGetDB( DB_MASTER ); if ( class_exists( 'Wiretap' ) && false ) { $query = diff --git a/specials/SpecialClearPendingReviews.php b/specials/SpecialClearPendingReviews.php index dda736b..53847bc 100644 --- a/specials/SpecialClearPendingReviews.php +++ b/specials/SpecialClearPendingReviews.php @@ -104,7 +104,7 @@ public function validateCategory( $categoryField, $allData ) { * @return $results */ public static function doSearchQuery( $data, $clearPages ) { - $dbw = wfGetDB( DB_REPLICA ); + $dbw = wfGetDB( DB_MASTER ); $category = preg_replace( '/\s+/', '_', $data['category'] ); $page = preg_replace( '/\s+/', '_', $data['page'] ); $start = preg_replace( '/\s+/', '', $data['start'] ); @@ -133,7 +133,6 @@ public static function doSearchQuery( $data, $clearPages ) { $results = $dbw->select( $tables, $vars, $conditions, __METHOD__, 'DISTINCT', $join_conds ); if ( $clearPages == true ) { - $dbw = wfGetDB( DB_MASTER ); foreach ( $results as $result ) { $values = [ 'wl_notificationtimestamp' => null ]; diff --git a/specials/SpecialWatchAnalytics.php b/specials/SpecialWatchAnalytics.php index adc2f70..e1f1595 100644 --- a/specials/SpecialWatchAnalytics.php +++ b/specials/SpecialWatchAnalytics.php @@ -74,7 +74,7 @@ public function getPageHeader() { // FROM watchlist // INNER JOIN page ON page.page_namespace = watchlist.wl_namespace AND page.page_title = watchlist.wl_title; $dbr = wfGetDB( DB_SLAVE ); - $dbr = wfGetDB( DB_REPLICA ); + $db = wfGetDB( DB_MASTER ); // $res = $dbr->select( // array( @@ -96,7 +96,7 @@ public function getPageHeader() { // ) // ); - $res = $dbr->query( ' + $res = $db->query( ' SELECT COUNT(*) AS num_watches, SUM( IF(watchlist.wl_notificationtimestamp IS NULL, 0, 1) ) AS num_pending, @@ -105,7 +105,7 @@ public function getPageHeader() { INNER JOIN page ON page.page_namespace = watchlist.wl_namespace AND page.page_title = watchlist.wl_title; ' ); - $allWikiData = $dbr->fetchRow( $res ); + $allWikiData = $db->fetchRow( $res ); list( $watches, $pending, $percent ) = [ $allWikiData['num_watches'],