diff --git a/includes/EmailBatch.php b/includes/EmailBatch.php index e41ada005..280bb7bce 100644 --- a/includes/EmailBatch.php +++ b/includes/EmailBatch.php @@ -202,10 +202,17 @@ class MWEchoEmailBatch { if ( $this->lastEvent ) { $conds[] = 'eeb_event_id <= ' . intval( $this->lastEvent ); } + $fields = array_merge( EchoEvent::selectFields(), [ + 'eeb_id', + 'eeb_user_id', + 'eeb_event_priority', + 'eeb_event_id', + 'eeb_event_hash', + ] ); $res = $dbr->select( [ 'echo_email_batch', 'echo_event' ], - [ '*' ], + $fields, $conds, __METHOD__, [ diff --git a/includes/mapper/EventMapper.php b/includes/mapper/EventMapper.php index 7259d2481..996653de5 100644 --- a/includes/mapper/EventMapper.php +++ b/includes/mapper/EventMapper.php @@ -42,7 +42,7 @@ class EchoEventMapper extends EchoAbstractMapper { public function fetchById( $id, $fromMaster = false ) { $db = $fromMaster ? $this->dbFactory->getEchoDb( DB_MASTER ) : $this->dbFactory->getEchoDb( DB_REPLICA ); - $row = $db->selectRow( 'echo_event', '*', [ 'event_id' => $id ], __METHOD__ ); + $row = $db->selectRow( 'echo_event', EchoEvent::selectFields(), [ 'event_id' => $id ], __METHOD__ ); // If the row was not found, fall back on the master if it makes sense to do so if ( !$row && !$fromMaster && $this->dbFactory->canRetryMaster() ) { @@ -91,7 +91,7 @@ class EchoEventMapper extends EchoAbstractMapper { $dbr = $this->dbFactory->getEchoDb( DB_REPLICA ); $res = $dbr->select( [ 'echo_event', 'echo_target_page' ], - [ '*' ], + EchoEvent::selectFields(), [ 'etp_page' => $pageId ], @@ -134,10 +134,11 @@ class EchoEventMapper extends EchoAbstractMapper { */ public function fetchUnreadByUserAndPage( User $user, $pageId ) { $dbr = $this->dbFactory->getEchoDb( DB_REPLICA ); + $fields = array_merge( EchoEvent::selectFields(), [ 'notification_timestamp' ] ); $res = $dbr->select( [ 'echo_event', 'echo_notification', 'echo_target_page' ], - '*', + $fields, [ 'event_deleted' => 0, 'notification_user' => $user->getId(), diff --git a/includes/mapper/NotificationMapper.php b/includes/mapper/NotificationMapper.php index f2310327d..a70b906f4 100644 --- a/includes/mapper/NotificationMapper.php +++ b/includes/mapper/NotificationMapper.php @@ -235,7 +235,7 @@ class EchoNotificationMapper extends EchoAbstractMapper { $res = $dbr->select( [ 'echo_notification', 'echo_event' ], - '*', + EchoNotification::selectFields(), $conds, __METHOD__, [ @@ -286,7 +286,7 @@ class EchoNotificationMapper extends EchoAbstractMapper { $row = $dbr->selectRow( [ 'echo_notification', 'echo_event' ], - [ '*' ], + EchoNotification::selectFields(), [ 'notification_user' => $user->getId(), 'notification_bundle_hash' => $bundleHash @@ -316,7 +316,7 @@ class EchoNotificationMapper extends EchoAbstractMapper { $result = $dbr->select( [ 'echo_notification', 'echo_event' ], - '*', + EchoNotification::selectFields(), [ 'notification_user' => $user->getId(), 'notification_event' => $eventIds @@ -350,7 +350,7 @@ class EchoNotificationMapper extends EchoAbstractMapper { $dbr = $this->dbFactory->getEchoDb( DB_REPLICA ); $row = $dbr->selectRow( [ 'echo_notification', 'echo_event' ], - [ '*' ], + EchoNotification::selectFields(), [ 'notification_user' => $user->getId(), 'event_deleted' => 0, diff --git a/includes/model/Notification.php b/includes/model/Notification.php index 282b3386b..43e1e34f0 100644 --- a/includes/model/Notification.php +++ b/includes/model/Notification.php @@ -304,4 +304,21 @@ class EchoNotification extends EchoAbstractEntity implements Bundleable { public function getSortingKey() { return ( $this->isRead() ? '0' : '1' ) . '_' . $this->getTimestamp(); } + + /** + * Return the list of fields that should be selected to create + * a new event with EchoNotification::newFromRow + * @return string[] + */ + public static function selectFields() { + return array_merge( EchoEvent::selectFields(), [ + 'notification_event', + 'notification_user', + 'notification_timestamp', + 'notification_read_timestamp', + 'notification_bundle_base', + 'notification_bundle_hash', + 'notification_bundle_display_hash', + ] ); + } } diff --git a/includes/special/NotificationPager.php b/includes/special/NotificationPager.php index c1eeccc08..480d962a5 100644 --- a/includes/special/NotificationPager.php +++ b/includes/special/NotificationPager.php @@ -24,7 +24,7 @@ class NotificationPager extends ReverseChronologicalPager { return [ 'tables' => [ 'echo_notification', 'echo_event' ], - 'fields' => '*', + 'fields' => EchoNotification::selectFields(), 'conds' => [ 'notification_user' => $this->getUser()->getId(), 'event_type' => $eventTypes, diff --git a/tests/phpunit/TalkPageFunctionalTest.php b/tests/phpunit/TalkPageFunctionalTest.php index f33e50202..789f047f0 100644 --- a/tests/phpunit/TalkPageFunctionalTest.php +++ b/tests/phpunit/TalkPageFunctionalTest.php @@ -83,7 +83,7 @@ class EchoTalkPageFunctionalTest extends ApiTestCase { * @return \stdClass[] All events in db sorted from oldest to newest */ protected function fetchAllEvents() { - $res = $this->dbr->select( 'echo_event', [ '*' ], [], __METHOD__, [ 'ORDER BY' => 'event_id ASC' ] ); + $res = $this->dbr->select( 'echo_event', EchoEvent::selectFields(), [], __METHOD__, [ 'ORDER BY' => 'event_id ASC' ] ); return iterator_to_array( $res ); }