IReadableDatabase::select cannot return false

Remove check for false from IDatabase::select as this is not possible
A DBQueryError is thrown (documented since efda8cd3 / I056b7148)

Change-Id: I465a9158aa6430e7ff8a5a83fe55c5944315aa40
This commit is contained in:
Umherirrender 2024-04-18 21:54:01 +02:00
parent a180cf3623
commit 2feece8bad
7 changed files with 19 additions and 64 deletions

View file

@ -108,13 +108,6 @@ class ApiEchoUnreadNotificationPages extends ApiQueryBase {
[ 'echo_notification' => [ 'INNER JOIN', 'notification_event = event_id' ] ]
);
if ( $rows === false ) {
return [
'pages' => [],
'totalCount' => 0,
];
}
$nullCount = 0;
$pageCounts = [];
foreach ( $rows as $row ) {

View file

@ -221,10 +221,8 @@ class UserNotificationGateway {
);
$eventIds = [];
if ( $res ) {
foreach ( $res as $row ) {
$eventIds[$row->notification_event] = $row->notification_event;
}
foreach ( $res as $row ) {
$eventIds[$row->notification_event] = $row->notification_event;
}
return $eventIds;

View file

@ -101,12 +101,10 @@ class EventMapper extends AbstractMapper {
[ 'event_page_id' => $pageId ],
__METHOD__
);
if ( $res ) {
foreach ( $res as $row ) {
$event = Event::newFromRow( $row );
$events[] = $event;
$seenEventIds[] = $event->getId();
}
foreach ( $res as $row ) {
$event = Event::newFromRow( $row );
$events[] = $event;
$seenEventIds[] = $event->getId();
}
// From echo_target_page
@ -124,10 +122,8 @@ class EventMapper extends AbstractMapper {
[ 'DISTINCT' ],
[ 'echo_target_page' => [ 'INNER JOIN', 'event_id=etp_event' ] ]
);
if ( $res ) {
foreach ( $res as $row ) {
$events[] = Event::newFromRow( $row );
}
foreach ( $res as $row ) {
$events[] = Event::newFromRow( $row );
}
return $events;

View file

@ -265,11 +265,6 @@ class NotificationMapper extends AbstractMapper {
]
);
// query failure of some sort
if ( !$res ) {
return [];
}
/** @var Notification[] $allNotifications */
$allNotifications = [];
foreach ( $res as $row ) {
@ -298,7 +293,7 @@ class NotificationMapper extends AbstractMapper {
*
* @param UserIdentity $userIdentity
* @param int[] $eventIds
* @return Notification[]|false
* @return Notification[]
*/
public function fetchByUserEvents( UserIdentity $userIdentity, array $eventIds ) {
$dbr = $this->dbFactory->getEchoDb( DB_REPLICA );
@ -317,15 +312,11 @@ class NotificationMapper extends AbstractMapper {
]
);
if ( $result ) {
$notifications = [];
foreach ( $result as $row ) {
$notifications[] = Notification::newFromRow( $row );
}
return $notifications;
} else {
return false;
$notifications = [];
foreach ( $result as $row ) {
$notifications[] = Notification::newFromRow( $row );
}
return $notifications;
}
/**
@ -418,7 +409,7 @@ class NotificationMapper extends AbstractMapper {
* Fetch ids of users that have notifications for certain events
*
* @param int[] $eventIds
* @return int[]|false
* @return int[]
*/
public function fetchUsersWithNotificationsForEvents( array $eventIds ) {
$dbr = $this->dbFactory->getEchoDb( DB_REPLICA );
@ -432,15 +423,11 @@ class NotificationMapper extends AbstractMapper {
__METHOD__
);
if ( $res ) {
$userIds = [];
foreach ( $res as $row ) {
$userIds[] = $row->userId;
}
return $userIds;
} else {
return false;
$userIds = [];
foreach ( $res as $row ) {
$userIds[] = $row->userId;
}
return $userIds;
}
}

View file

@ -76,7 +76,7 @@ class UserMergeHooks implements
],
$method,
[ 'ORDER BY' => 'notification_timestamp ASC' ]
) ?: [];
);
foreach ( $thankYouRows as $row ) {
$event = Event::newFromRow( $row );
$editCount = $event ? $event->getExtraParam( 'editCount' ) : null;

View file

@ -20,12 +20,6 @@ class NotificationMapperTest extends MediaWikiIntegrationTestCase {
}
public function fetchUnreadByUser( User $user, $limit, array $eventTypes = [] ) {
// Unsuccessful select
$notifMapper = new NotificationMapper( $this->mockDbFactory( [ 'select' => false ] ) );
$res = $notifMapper->fetchUnreadByUser( $this->mockUser(), 10, null, '' );
$this->assertSame( [], $res );
// Successful select
$dbResult = [
(object)[
'event_id' => 1,
@ -55,12 +49,6 @@ class NotificationMapperTest extends MediaWikiIntegrationTestCase {
}
public function testFetchByUser() {
// Unsuccessful select
$notifMapper = new NotificationMapper( $this->mockDbFactory( [ 'select' => false ] ) );
$res = $notifMapper->fetchByUser( $this->mockUser(), 10, '' );
$this->assertSame( [], $res );
// Successful select
$notifDbResult = [
(object)[
'event_id' => 1,

View file

@ -91,13 +91,6 @@ class UserNotificationGatewayTest extends MediaWikiUnitTestCase {
}
public function testGetUnreadNotifications() {
$gateway = new UserNotificationGateway(
$this->mockUser(),
$this->mockDbFactory( [ 'select' => false ] ),
$this->mockConfig()
);
$this->assertSame( [], $gateway->getUnreadNotifications( 'user_talk' ) );
$dbResult = [
(object)[ 'notification_event' => 1 ],
(object)[ 'notification_event' => 2 ],