From dec0785d744f66e2ec0c8ab99a9cfb97b34bb589 Mon Sep 17 00:00:00 2001 From: Greg Rundlett Date: Thu, 16 Jan 2025 10:29:59 -0500 Subject: [PATCH] make database access forward-compatible wfGetDB() was deprecated as of REL1_39 and is being removed in REL1_44 Fixes Issue #253 --- src/AppFactory.php | 6 +++++- src/PropertyAnnotators/ApprovedDatePropertyAnnotator.php | 9 +++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/AppFactory.php b/src/AppFactory.php index fd9d701..12ad1b2 100644 --- a/src/AppFactory.php +++ b/src/AppFactory.php @@ -72,7 +72,11 @@ public function setConnection( Database $connection ) { */ public function getConnection() { if ( $this->connection === null ) { - $this->connection = wfGetDB( DB_REPLICA ); + if ( version_compare( MW_VERSION, '1.42', '>=' ) ) { + $this->connection = MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase(); + } else { + $this->connection = MediaWikiServices::getInstance()->getDBLoadBalancer()->getConnection( DB_REPLICA ); + } } return $this->connection; diff --git a/src/PropertyAnnotators/ApprovedDatePropertyAnnotator.php b/src/PropertyAnnotators/ApprovedDatePropertyAnnotator.php index e10c050..7acb4d8 100644 --- a/src/PropertyAnnotators/ApprovedDatePropertyAnnotator.php +++ b/src/PropertyAnnotators/ApprovedDatePropertyAnnotator.php @@ -63,8 +63,13 @@ public function addAnnotation( DIProperty $property, SemanticData $semanticData // ApprovedRevs does not provide a function to get the approval date, // so fetch it here from the ApprovedRevs table $pageID = $semanticData->getSubject()->getTitle()->getArticleID(); - $dbr = wfGetDB( DB_REPLICA ); - $approval_date = $dbr->selectField( 'approved_revs', 'approval_date', [ 'page_id' => $pageID ] ); + $dbr = $this->appFactory->getConnection(); + if ( $dbr ) { + $approval_date = $dbr->selectField( 'approved_revs', 'approval_date', [ 'page_id' => $pageID ] ); + } else { + // Handle the error appropriately, e.g., log an error or throw an exception + throw new \RuntimeException( 'Database connection failed.' ); + } if ( $approval_date ) { $this->approvedDate = new MWTimestamp( wfTimestamp( TS_MW, $approval_date ) );