Skip to content

Commit

Permalink
Merge pull request #254 from freephile/fix253-wfGetDB
Browse files Browse the repository at this point in the history
implement newer database access method
  • Loading branch information
paladox authored Jan 16, 2025
2 parents cc90709 + dec0785 commit 96c6840
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/AppFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 7 additions & 2 deletions src/PropertyAnnotators/ApprovedDatePropertyAnnotator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
Expand Down

0 comments on commit 96c6840

Please sign in to comment.