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 ) );