Skip to content

implement newer database access method #254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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