From 5611662f06626fb6ecb97160ee0550182979360e Mon Sep 17 00:00:00 2001 From: Reedy Date: Wed, 2 Nov 2022 15:34:17 -0600 Subject: [PATCH] Namespace Model Depends-On: Id28792658de950b99a8786f881563476def59eba Change-Id: Ib57ea2db947285946f31fa9912b37181044df9d3 --- extension.json | 9 ++- includes/Api/ApiEchoArticleReminder.php | 4 +- includes/Api/ApiEchoNotifications.php | 10 +-- .../Controller/NotificationController.php | 44 ++++++------- includes/DataOutputFormatter.php | 15 +++-- includes/DeferredMarkAsDeletedUpdate.php | 15 ++--- includes/DiscussionParser.php | 9 +-- includes/EmailBatch.php | 9 +-- .../EchoEditUserTalkPresentationModel.php | 4 +- .../Formatters/EchoEventDigestFormatter.php | 4 +- includes/Formatters/EchoEventFormatter.php | 6 +- .../Formatters/EchoEventPresentationModel.php | 20 +++--- .../EchoMentionPresentationModel.php | 4 +- .../EchoMentionStatusPresentationModel.php | 6 +- .../EchoPageLinkedPresentationModel.php | 6 +- .../EchoPresentationModelSection.php | 8 +-- includes/Hooks.php | 32 +++++----- includes/Mapper/EventMapper.php | 36 +++++------ includes/Mapper/NotificationMapper.php | 36 +++++------ includes/Mapper/TargetPageMapper.php | 12 ++-- includes/{model => Model}/AbstractEntity.php | 4 +- includes/{model => Model}/Event.php | 63 ++++++++++--------- includes/{model => Model}/Notification.php | 51 +++++++++------ includes/{model => Model}/TargetPage.php | 26 +++++--- includes/NotifUser.php | 3 +- includes/Notifier.php | 14 +++-- includes/Push/PushNotifier.php | 10 +-- includes/Special/NotificationPager.php | 8 +-- includes/UserLocator.php | 21 ++++--- maintenance/generateSampleNotifications.php | 23 +++---- .../Controller/NotificationControllerTest.php | 15 ++--- tests/phpunit/DiscussionParserTest.php | 9 +-- .../EchoPresentationModelSectionTest.php | 3 +- tests/phpunit/Mapper/EventMapperTest.php | 17 ++--- .../phpunit/Mapper/NotificationMapperTest.php | 15 ++--- .../{model => Model}/NotificationTest.php | 24 ++++--- tests/phpunit/NotifUserTest.php | 16 ++--- tests/phpunit/NotificationsTest.php | 3 +- tests/phpunit/TalkPageFunctionalTest.php | 4 +- tests/phpunit/ThankYouEditTest.php | 4 +- tests/phpunit/UserLocatorTest.php | 14 +++-- tests/phpunit/unit/BundlerTest.php | 4 +- .../unit/Mapper/TargetPageMapperTest.php | 11 ++-- .../unit/{model => Model}/TargetPageTest.php | 27 ++++---- 44 files changed, 368 insertions(+), 310 deletions(-) rename includes/{model => Model}/AbstractEntity.php (65%) rename includes/{model => Model}/Event.php (93%) rename includes/{model => Model}/Notification.php (82%) rename includes/{model => Model}/TargetPage.php (82%) rename tests/phpunit/{model => Model}/NotificationTest.php (70%) rename tests/phpunit/unit/{model => Model}/TargetPageTest.php (69%) diff --git a/extension.json b/extension.json index 60bea2f27..80e7bcc7d 100644 --- a/extension.json +++ b/extension.json @@ -1072,7 +1072,6 @@ "BackfillUnreadWikis": "maintenance/backfillUnreadWikis.php", "Bundleable": "includes/Bundleable.php", "Bundler": "includes/Bundler.php", - "EchoAbstractEntity": "includes/model/AbstractEntity.php", "EchoArrayList": "includes/EchoArrayList.php", "EchoAttributeManager": "includes/AttributeManager.php", "EchoCachedList": "includes/EchoCachedList.php", @@ -1089,8 +1088,8 @@ "MediaWiki\\Extension\\Notifications\\Formatters\\EchoEditUserTalkPresentationModel": "includes/Formatters/EchoEditUserTalkPresentationModel.php", "EchoEmailFormat": "includes/EmailFormat.php", "EchoEmailFrequency": "includes/EmailFrequency.php", - "EchoEvent": "includes/model/Event.php", - "MediaWiki\\Extension\\Notifications\\Model\\Event": "includes/model/Event.php", + "EchoEvent": "includes/Model/Event.php", + "MediaWiki\\Extension\\Notifications\\Model\\Event": "includes/Model/Event.php", "EchoEventPresentationModel": "includes/Formatters/EchoEventPresentationModel.php", "MediaWiki\\Extension\\Notifications\\Formatters\\EchoEventPresentationModel": "includes/Formatters/EchoEventPresentationModel.php", "EchoForeignNotifications": "includes/ForeignNotifications.php", @@ -1099,7 +1098,8 @@ "MediaWiki\\Extension\\Notifications\\Formatters\\EchoMentionPresentationModel": "includes/Formatters/EchoMentionPresentationModel.php", "EchoMentionStatusPresentationModel": "includes/Formatters/EchoMentionStatusPresentationModel.php", "MediaWiki\\Extension\\Notifications\\Formatters\\EchoMentionStatusPresentationModel": "includes/Formatters/EchoMentionStatusPresentationModel.php", - "EchoNotification": "includes/model/Notification.php", + "EchoNotification": "includes/Model/Notification.php", + "MediaWiki\\Extension\\Notifications\\Model\\Notification": "includes/Model/Notification.php", "EchoNotificationMapper": "includes/Mapper/NotificationMapper.php", "MediaWiki\\Extension\\Notifications\\Mapper\\NotificationMapper": "includes/Mapper/NotificationMapper.php", "EchoNotifier": "includes/Notifier.php", @@ -1110,7 +1110,6 @@ "EchoServices": "includes/EchoServices.php", "EchoSummaryParser": "includes/EchoSummaryParser.php", "EchoSuppressionRowUpdateGenerator": "includes/schemaUpdate.php", - "EchoTargetPage": "includes/model/TargetPage.php", "EchoUnreadWikis": "includes/UnreadWikis.php", "EchoUserLocator": "includes/UserLocator.php", "GenerateSampleNotifications": "maintenance/generateSampleNotifications.php", diff --git a/includes/Api/ApiEchoArticleReminder.php b/includes/Api/ApiEchoArticleReminder.php index 60bf02475..34c129f1c 100644 --- a/includes/Api/ApiEchoArticleReminder.php +++ b/includes/Api/ApiEchoArticleReminder.php @@ -5,7 +5,7 @@ namespace MediaWiki\Extension\Notifications\Api; use ApiBase; use DateInterval; use DateTime; -use EchoEvent; +use MediaWiki\Extension\Notifications\Model\Event; use MWTimestamp; use Wikimedia\ParamValidator\ParamValidator; @@ -29,7 +29,7 @@ class ApiEchoArticleReminder extends ApiBase { $this->dieWithError( [ 'apierror-badparameter', 'timestamp' ], 'timestamp-not-in-future', null, 400 ); } - $eventCreation = EchoEvent::create( [ + $eventCreation = Event::create( [ 'type' => 'article-reminder', 'agent' => $user, 'title' => $this->getTitleFromTitleOrPageId( $params ), diff --git a/includes/Api/ApiEchoNotifications.php b/includes/Api/ApiEchoNotifications.php index b04bcbcad..d62061202 100644 --- a/includes/Api/ApiEchoNotifications.php +++ b/includes/Api/ApiEchoNotifications.php @@ -10,11 +10,11 @@ use Config; use EchoAttributeManager; use EchoDataOutputFormatter; use EchoForeignNotifications; -use EchoNotification; use EchoSeenTime; use EchoServices; use MediaWiki\Extension\Notifications\Controller\NotificationController; use MediaWiki\Extension\Notifications\Mapper\NotificationMapper; +use MediaWiki\Extension\Notifications\Model\Notification; use MWEchoNotifUser; use Title; use User; @@ -265,7 +265,7 @@ class ApiEchoNotifications extends ApiQueryBase { * discard unread & fetch read */ if ( $notifs && $continue ) { - /** @var EchoNotification $first */ + /** @var Notification $first */ $first = reset( $notifs ); $continueId = intval( trim( strrchr( $continue, '|' ), '|' ) ); if ( $first->getEvent()->getId() !== $continueId ) { @@ -307,7 +307,7 @@ class ApiEchoNotifications extends ApiQueryBase { } // get $overfetchedItem before bundling and rendering so that it is not affected by filtering - /** @var EchoNotification $overfetchedItem */ + /** @var Notification $overfetchedItem */ $overfetchedItem = count( $notifs ) > $limit ? array_pop( $notifs ) : null; $bundler = null; @@ -317,7 +317,7 @@ class ApiEchoNotifications extends ApiQueryBase { } while ( $notifs !== [] ) { - /** @var EchoNotification $notif */ + /** @var Notification $notif */ $notif = array_shift( $notifs ); $output = EchoDataOutputFormatter::formatOutput( $notif, $format, $user, $this->getLanguage() ); if ( $output !== false ) { @@ -443,7 +443,7 @@ class ApiEchoNotifications extends ApiQueryBase { ]; // Format output like any other notification - $notif = EchoNotification::newFromRow( $row ); + $notif = Notification::newFromRow( $row ); $output = EchoDataOutputFormatter::formatOutput( $notif, $format, $user, $this->getLanguage() ); // Add cross-wiki-specific data diff --git a/includes/Controller/NotificationController.php b/includes/Controller/NotificationController.php index 02f2db4c8..e87092951 100644 --- a/includes/Controller/NotificationController.php +++ b/includes/Controller/NotificationController.php @@ -7,7 +7,6 @@ use EchoAttributeManager; use EchoCachedList; use EchoContainmentList; use EchoContainmentSet; -use EchoEvent; use EchoOnWikiList; use EchoServices; use Hooks; @@ -17,6 +16,7 @@ use MediaWiki\Extension\Notifications\Exception\CatchableFatalErrorException; use MediaWiki\Extension\Notifications\Iterator\FilteredSequentialIterator; use MediaWiki\Extension\Notifications\Jobs\NotificationDeleteJob; use MediaWiki\Extension\Notifications\Jobs\NotificationJob; +use MediaWiki\Extension\Notifications\Model\Event; use MediaWiki\Logger\LoggerFactory; use MediaWiki\MediaWikiServices; use MediaWiki\Revision\RevisionStore; @@ -101,9 +101,9 @@ class NotificationController { } /** - * Processes notifications for a newly-created EchoEvent + * Processes notifications for a newly-created Event * - * @param EchoEvent $event + * @param Event $event * @param bool $defer Defer to job queue or not */ public static function notify( $event, $defer = true ) { @@ -176,10 +176,10 @@ class NotificationController { /** * Check if an event is associated with a minor revision. * - * @param EchoEvent $event + * @param Event $event * @return bool */ - private static function hasMinorRevision( EchoEvent $event ) { + private static function hasMinorRevision( Event $event ) { $revId = $event->getExtraParam( 'revid' ); if ( !$revId ) { return false; @@ -206,9 +206,9 @@ class NotificationController { * Schedule a job to check and delete older notifications * * @param int[] $userIds - * @param EchoEvent $event + * @param Event $event */ - public static function enqueueDeleteJob( array $userIds, EchoEvent $event ) { + public static function enqueueDeleteJob( array $userIds, Event $event ) { // Do nothing if there is no user if ( !$userIds ) { return; @@ -242,10 +242,10 @@ class NotificationController { /** * Helper function to extract event task params - * @param EchoEvent $event + * @param Event $event * @return array Event params */ - public static function getEventParams( EchoEvent $event ) { + public static function getEventParams( Event $event ) { $delay = $event->getExtraParam( 'delay' ); $rootJobSignature = $event->getExtraParam( 'rootJobSignature' ); $rootJobTimestamp = $event->getExtraParam( 'rootJobTimestamp' ); @@ -259,9 +259,9 @@ class NotificationController { /** * Push $event onto the mediawiki job queue * - * @param EchoEvent $event + * @param Event $event */ - public static function enqueueEvent( EchoEvent $event ) { + public static function enqueueEvent( Event $event ) { $queue = MediaWikiServices::getInstance()->getJobQueueGroup(); $params = self::getEventParams( $event ); @@ -288,11 +288,11 @@ class NotificationController { * Implements blacklist per active wiki expected to be initialized * from InitializeSettings.php * - * @param EchoEvent $event The event to test for exclusion + * @param Event $event The event to test for exclusion * @param User $user recipient of the notification for per-user blacklists * @return bool True when the event agent is blacklisted */ - public static function isBlacklistedByUser( EchoEvent $event, User $user ) { + public static function isBlacklistedByUser( Event $event, User $user ) { global $wgEchoAgentBlacklist, $wgEchoPerUserBlacklist; if ( !$event->getAgent() ) { @@ -380,11 +380,11 @@ class NotificationController { /** * Implements per-user whitelist sourced from a user wiki page * - * @param EchoEvent $event The event to test for inclusion in whitelist + * @param Event $event The event to test for inclusion in whitelist * @param User $user The user that owns the whitelist * @return bool True when the event agent is in the user whitelist */ - public static function isWhitelistedByUser( EchoEvent $event, User $user ) { + public static function isWhitelistedByUser( Event $event, User $user ) { $clusterCache = MediaWikiServices::getInstance()->getMainWANObjectCache(); global $wgEchoPerUserWhitelistFormat; @@ -420,9 +420,9 @@ class NotificationController { } /** - * Processes a single notification for an EchoEvent + * Processes a single notification for an Event * - * @param EchoEvent $event + * @param Event $event * @param User $user The user to be notified. * @param string $type The type of notification delivery to process, e.g. 'email'. * @throws MWException @@ -446,11 +446,11 @@ class NotificationController { * Returns an array each element of which is the result of a * user-locator|user-filters attached to the event type. * - * @param EchoEvent $event + * @param Event $event * @param string $locator Either EchoAttributeManager::ATTR_LOCATORS or EchoAttributeManager::ATTR_FILTERS * @return array */ - public static function evaluateUserCallable( EchoEvent $event, $locator = EchoAttributeManager::ATTR_LOCATORS ) { + public static function evaluateUserCallable( Event $event, $locator = EchoAttributeManager::ATTR_LOCATORS ) { $attributeManager = EchoServices::getInstance()->getAttributeManager(); $type = $event->getType(); $result = []; @@ -475,12 +475,12 @@ class NotificationController { } /** - * Retrieves an array of User objects to be notified for an EchoEvent. + * Retrieves an array of User objects to be notified for an Event. * - * @param EchoEvent $event + * @param Event $event * @return Iterator values are User objects */ - public static function getUsersToNotifyForEvent( EchoEvent $event ) { + public static function getUsersToNotifyForEvent( Event $event ) { $notify = new FilteredSequentialIterator; foreach ( self::evaluateUserCallable( $event, EchoAttributeManager::ATTR_LOCATORS ) as $users ) { $notify->add( $users ); diff --git a/includes/DataOutputFormatter.php b/includes/DataOutputFormatter.php index 2e22adbd4..a8b9a3466 100644 --- a/includes/DataOutputFormatter.php +++ b/includes/DataOutputFormatter.php @@ -1,8 +1,11 @@ getBundledNotifications(); if ( $bundledNotifs ) { - $bundledEvents = array_map( static function ( EchoNotification $notif ) { + $bundledEvents = array_map( static function ( Notification $notif ) { return $notif->getEvent(); }, $bundledNotifs ); $event->setBundledEvents( $bundledEvents ); @@ -162,7 +165,7 @@ class EchoDataOutputFormatter { EchoServices::getInstance()->getAttributeManager()->isBundleExpandable( $event->getType() ) ) { $output['bundledNotifications'] = array_values( array_filter( array_map( - function ( EchoNotification $notification ) use ( $format, $user, $lang ) { + static function ( Notification $notification ) use ( $format, $user, $lang ) { // remove nested notifications to // - ensure they are formatted as single notifications (not bundled) // - prevent further re-entrance on the current notification @@ -179,13 +182,13 @@ class EchoDataOutputFormatter { } /** - * @param EchoEvent $event + * @param Event $event * @param User $user * @param string $format * @param Language $lang * @return string[]|string|false False if it could not be formatted */ - protected static function formatNotification( EchoEvent $event, User $user, $format, $lang ) { + protected static function formatNotification( Event $event, User $user, $format, $lang ) { if ( isset( self::$formatters[$format] ) ) { $class = self::$formatters[$format]; /** @var EchoEventFormatter $formatter */ diff --git a/includes/DeferredMarkAsDeletedUpdate.php b/includes/DeferredMarkAsDeletedUpdate.php index af71e0e9d..0902907c7 100644 --- a/includes/DeferredMarkAsDeletedUpdate.php +++ b/includes/DeferredMarkAsDeletedUpdate.php @@ -1,6 +1,7 @@ events[] = $event; } private function filterEventsWithTitleDbLag() { return array_filter( $this->events, - static function ( EchoEvent $event ) { + static function ( Event $event ) { if ( !$event->getTitle() && $event->getTitle( true ) ) { // It is very likely this event was found // unrenderable because of replica lag. @@ -63,7 +64,7 @@ class EchoDeferredMarkAsDeletedUpdate implements DeferrableUpdate { $events = $this->filterEventsWithTitleDbLag(); $eventIds = array_map( - static function ( EchoEvent $event ) { + static function ( Event $event ) { return $event->getId(); }, $events diff --git a/includes/DiscussionParser.php b/includes/DiscussionParser.php index d8c216dc4..eec0c5561 100644 --- a/includes/DiscussionParser.php +++ b/includes/DiscussionParser.php @@ -1,5 +1,6 @@ count > self::$displaySize ) { break; } - $event = EchoEvent::newFromRow( $row ); + $event = Event::newFromRow( $row ); if ( !$event ) { continue; } @@ -235,7 +236,7 @@ class MWEchoEmailBatch { if ( $this->lastEvent ) { $conds[] = 'eeb_event_id <= ' . (int)$this->lastEvent; } - $fields = array_merge( EchoEvent::selectFields(), [ + $fields = array_merge( Event::selectFields(), [ 'eeb_id', 'eeb_user_id', 'eeb_event_priority', diff --git a/includes/Formatters/EchoEditUserTalkPresentationModel.php b/includes/Formatters/EchoEditUserTalkPresentationModel.php index 5291e4855..5524c5de2 100644 --- a/includes/Formatters/EchoEditUserTalkPresentationModel.php +++ b/includes/Formatters/EchoEditUserTalkPresentationModel.php @@ -2,8 +2,8 @@ namespace MediaWiki\Extension\Notifications\Formatters; -use EchoEvent; use Language; +use MediaWiki\Extension\Notifications\Model\Event; use MediaWiki\MediaWikiServices; use User; @@ -17,7 +17,7 @@ class EchoEditUserTalkPresentationModel extends EchoEventPresentationModel { /** * @inheritDoc */ - protected function __construct( EchoEvent $event, Language $language, User $user, $distributionType ) { + protected function __construct( Event $event, Language $language, User $user, $distributionType ) { parent::__construct( $event, $language, $user, $distributionType ); $this->section = new EchoPresentationModelSection( $event, $user, $language ); } diff --git a/includes/Formatters/EchoEventDigestFormatter.php b/includes/Formatters/EchoEventDigestFormatter.php index 98134dceb..81b9457de 100644 --- a/includes/Formatters/EchoEventDigestFormatter.php +++ b/includes/Formatters/EchoEventDigestFormatter.php @@ -2,8 +2,8 @@ namespace MediaWiki\Extension\Notifications\Formatters; -use EchoEvent; use Language; +use MediaWiki\Extension\Notifications\Model\Event; use Message; use User; @@ -42,7 +42,7 @@ abstract class EchoEventDigestFormatter { } /** - * @param EchoEvent[] $events + * @param Event[] $events * @param string $distributionType 'web' or 'email' * @return string[]|false Output format depends on implementation, false if it cannot be formatted */ diff --git a/includes/Formatters/EchoEventFormatter.php b/includes/Formatters/EchoEventFormatter.php index 914081f2a..92ce9f462 100644 --- a/includes/Formatters/EchoEventFormatter.php +++ b/includes/Formatters/EchoEventFormatter.php @@ -2,8 +2,8 @@ namespace MediaWiki\Extension\Notifications\Formatters; -use EchoEvent; use Language; +use MediaWiki\Extension\Notifications\Model\Event; use MediaWiki\Logger\LoggerFactory; use Message; use User; @@ -48,11 +48,11 @@ abstract class EchoEventFormatter { } /** - * @param EchoEvent $event + * @param Event $event * @param string $distributionType 'web' or 'email' * @return string[]|string|false Output format depends on implementation, false if it cannot be formatted */ - final public function format( EchoEvent $event, string $distributionType = "web" ) { + final public function format( Event $event, string $distributionType = "web" ) { // Deleted events should have been filtered out before getting there. // This is just to be sure. if ( $event->isDeleted() ) { diff --git a/includes/Formatters/EchoEventPresentationModel.php b/includes/Formatters/EchoEventPresentationModel.php index 739ef7893..0462bee5b 100644 --- a/includes/Formatters/EchoEventPresentationModel.php +++ b/includes/Formatters/EchoEventPresentationModel.php @@ -2,11 +2,11 @@ namespace MediaWiki\Extension\Notifications\Formatters; -use EchoEvent; use InvalidArgumentException; use JsonSerializable; use Language; use MediaWiki\Extension\Notifications\Controller\NotificationController; +use MediaWiki\Extension\Notifications\Model\Event; use MediaWiki\MediaWikiServices; use MediaWiki\Revision\RevisionRecord; use Message; @@ -55,7 +55,7 @@ abstract class EchoEventPresentationModel implements JsonSerializable, MessageLo public const SECTION_TITLE_RECOMMENDED_LENGTH = 50; /** - * @var EchoEvent + * @var Event */ protected $event; @@ -80,13 +80,13 @@ abstract class EchoEventPresentationModel implements JsonSerializable, MessageLo private $distributionType; /** - * @param EchoEvent $event + * @param Event $event * @param Language $language * @param User $user Only used for permissions checking and GENDER * @param string $distributionType */ protected function __construct( - EchoEvent $event, + Event $event, Language $language, User $user, $distributionType @@ -112,14 +112,14 @@ abstract class EchoEventPresentationModel implements JsonSerializable, MessageLo } /** - * @param EchoEvent $event + * @param Event $event * @param Language $language * @param User $user * @param string $distributionType 'web' or 'email' * @return EchoEventPresentationModel */ public static function factory( - EchoEvent $event, + Event $event, Language $language, User $user, $distributionType = 'web' @@ -189,7 +189,7 @@ abstract class EchoEventPresentationModel implements JsonSerializable, MessageLo } /** - * @return EchoEvent[] + * @return Event[] */ final protected function getBundledEvents() { return $this->event->getBundledEvents() ?: []; @@ -202,7 +202,7 @@ abstract class EchoEventPresentationModel implements JsonSerializable, MessageLo */ public function getBundledIds() { if ( $this->isBundled() ) { - return array_map( static function ( EchoEvent $event ) { + return array_map( static function ( Event $event ) { return $event->getId(); }, $this->getBundledEvents() ); } @@ -230,7 +230,7 @@ abstract class EchoEventPresentationModel implements JsonSerializable, MessageLo * If $includeCurrent is false, all events in the same group as the current one will be ignored. * * @param bool $includeCurrent Include the current event (and its group) - * @param callable|null $groupCallback Callback that takes an EchoEvent and returns a grouping value + * @param callable|null $groupCallback Callback that takes an Event and returns a grouping value * @return int Number of bundled events or groups * @throws InvalidArgumentException */ @@ -280,7 +280,7 @@ abstract class EchoEventPresentationModel implements JsonSerializable, MessageLo } /** - * Helper for EchoEvent::userCan + * Helper for Event::userCan * * @param int $type RevisionRecord::DELETED_* constant * @return bool diff --git a/includes/Formatters/EchoMentionPresentationModel.php b/includes/Formatters/EchoMentionPresentationModel.php index b99ce6bc8..917c35a6d 100644 --- a/includes/Formatters/EchoMentionPresentationModel.php +++ b/includes/Formatters/EchoMentionPresentationModel.php @@ -3,8 +3,8 @@ namespace MediaWiki\Extension\Notifications\Formatters; use EchoDiscussionParser; -use EchoEvent; use Language; +use MediaWiki\Extension\Notifications\Model\Event; use MediaWiki\Revision\RevisionRecord; use User; @@ -18,7 +18,7 @@ class EchoMentionPresentationModel extends EchoEventPresentationModel { /** * @inheritDoc */ - protected function __construct( EchoEvent $event, Language $language, User $user, $distributionType ) { + protected function __construct( Event $event, Language $language, User $user, $distributionType ) { parent::__construct( $event, $language, $user, $distributionType ); $this->section = new EchoPresentationModelSection( $event, $user, $language ); } diff --git a/includes/Formatters/EchoMentionStatusPresentationModel.php b/includes/Formatters/EchoMentionStatusPresentationModel.php index a00248aee..c18025e04 100644 --- a/includes/Formatters/EchoMentionStatusPresentationModel.php +++ b/includes/Formatters/EchoMentionStatusPresentationModel.php @@ -2,8 +2,8 @@ namespace MediaWiki\Extension\Notifications\Formatters; -use EchoEvent; use Language; +use MediaWiki\Extension\Notifications\Model\Event; use User; /** @@ -23,7 +23,7 @@ class EchoMentionStatusPresentationModel extends EchoEventPresentationModel { /** * @inheritDoc */ - protected function __construct( EchoEvent $event, Language $language, User $user, $distributionType ) { + protected function __construct( Event $event, Language $language, User $user, $distributionType ) { parent::__construct( $event, $language, $user, $distributionType ); $this->section = new EchoPresentationModelSection( $event, $user, $language ); } @@ -121,7 +121,7 @@ class EchoMentionStatusPresentationModel extends EchoEventPresentationModel { return [ $talkPageLink ]; } - public function isMentionSuccessEvent( EchoEvent $event ) { + public function isMentionSuccessEvent( Event $event ) { return $event->getType() === 'mention-success'; } diff --git a/includes/Formatters/EchoPageLinkedPresentationModel.php b/includes/Formatters/EchoPageLinkedPresentationModel.php index cc759148e..631d28cdf 100644 --- a/includes/Formatters/EchoPageLinkedPresentationModel.php +++ b/includes/Formatters/EchoPageLinkedPresentationModel.php @@ -2,8 +2,8 @@ namespace MediaWiki\Extension\Notifications\Formatters; -use EchoEvent; use MediaWiki\Extension\Notifications\Controller\NotificationController; +use MediaWiki\Extension\Notifications\Model\Event; use MediaWiki\MediaWikiServices; use SpecialPage; use Title; @@ -147,10 +147,10 @@ class EchoPageLinkedPresentationModel extends EchoEventPresentationModel { /** * Get the page ID of the linked-from page for a given event. - * @param EchoEvent $event page-linked event + * @param Event $event page-linked event * @return int Page ID, or 0 if the page doesn't exist */ - public function getLinkedPageId( EchoEvent $event ) { + public function getLinkedPageId( Event $event ) { $extra = $event->getExtra(); if ( isset( $extra['link-from-page-id'] ) ) { return $extra['link-from-page-id']; diff --git a/includes/Formatters/EchoPresentationModelSection.php b/includes/Formatters/EchoPresentationModelSection.php index 2ca46a83a..6c7ced780 100644 --- a/includes/Formatters/EchoPresentationModelSection.php +++ b/includes/Formatters/EchoPresentationModelSection.php @@ -3,8 +3,8 @@ namespace MediaWiki\Extension\Notifications\Formatters; use EchoDiscussionParser; -use EchoEvent; use Language; +use MediaWiki\Extension\Notifications\Model\Event; use MediaWiki\Revision\RevisionRecord; use MWException; use Parser; @@ -27,7 +27,7 @@ class EchoPresentationModelSection { private $parsedSectionTitle = null; /** - * @var EchoEvent + * @var Event */ protected $event; @@ -42,11 +42,11 @@ class EchoPresentationModelSection { protected $language; /** - * @param EchoEvent $event + * @param Event $event * @param User $user * @param Language $language */ - public function __construct( EchoEvent $event, User $user, Language $language ) { + public function __construct( Event $event, User $user, Language $language ) { $this->event = $event; $this->user = $user; $this->language = $language; diff --git a/includes/Hooks.php b/includes/Hooks.php index 3f5d45cba..cbfec61a5 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -11,8 +11,6 @@ use EchoAttributeManager; use EchoDiscussionParser; use EchoEmailFormat; use EchoEmailFrequency; -use EchoEvent; -use EchoNotification; use EchoSeenTime; use EchoServices; use EmailNotification; @@ -30,6 +28,8 @@ use MediaWiki\Extension\Notifications\Controller\NotificationController; use MediaWiki\Extension\Notifications\Formatters\EchoEventPresentationModel; use MediaWiki\Extension\Notifications\Mapper\EventMapper; use MediaWiki\Extension\Notifications\Mapper\NotificationMapper; +use MediaWiki\Extension\Notifications\Model\Event; +use MediaWiki\Extension\Notifications\Model\Notification; use MediaWiki\Extension\Notifications\Push\Api\ApiEchoPushSubscriptions; use MediaWiki\Hook\AbortTalkPageEmailNotificationHook; use MediaWiki\Hook\BeforePageDisplayHook; @@ -316,7 +316,7 @@ class Hooks implements /** * Handler for EchoGetBundleRule hook, which defines the bundle rule for each notification * - * @param EchoEvent $event + * @param Event $event * @param string &$bundleString Determines how the notification should be bundled, for example, * talk page notification is bundled based on namespace and title, the bundle string would be * 'edit-user-talk-' + namespace + title, email digest/email bundling would use this hash as @@ -626,7 +626,7 @@ class Hooks implements DeferredUpdates::addCallableUpdate( static function () use ( $userIdentity, $title, $thresholdCount ) { $notificationMapper = new NotificationMapper(); $notifications = $notificationMapper->fetchByUser( $userIdentity, 10, null, [ 'thank-you-edit' ] ); - /** @var EchoNotification $notification */ + /** @var Notification $notification */ foreach ( $notifications as $notification ) { if ( $notification->getEvent()->getExtraParam( 'editCount' ) === $thresholdCount ) { LoggerFactory::getInstance( 'Echo' )->debug( @@ -641,7 +641,7 @@ class Hooks implements } } - EchoEvent::create( [ + Event::create( [ 'type' => 'thank-you-edit', 'title' => $title, 'agent' => $userIdentity, @@ -669,7 +669,7 @@ class Hooks implements $revertedUser = $undidRevision->getUser(); // No notifications for anonymous users if ( $revertedUser && $revertedUser->getId() ) { - EchoEvent::create( [ + Event::create( [ 'type' => 'reverted', 'title' => $title, 'extra' => [ @@ -705,7 +705,7 @@ class Hooks implements /** * Handler for EchoAbortEmailNotification hook * @param User $user - * @param EchoEvent $event + * @param Event $event * @return bool true - send email, false - do not send email */ public static function onEchoAbortEmailNotification( $user, $event ) { @@ -770,7 +770,7 @@ class Hooks implements foreach ( $overrides as $prefKey => $value ) { $userOptionsManager->setOption( $user, $prefKey, $value ); } - EchoEvent::create( [ + Event::create( [ 'type' => 'welcome', 'agent' => $user, ] ); @@ -828,7 +828,7 @@ class Hooks implements if ( $expiryChanged ) { // use a separate notification for these, so the notification text doesn't // get too long - EchoEvent::create( + Event::create( [ 'type' => 'user-rights', 'extra' => [ @@ -842,7 +842,7 @@ class Hooks implements } if ( $reallyAdded || $remove ) { - EchoEvent::create( + Event::create( [ 'type' => 'user-rights', 'extra' => [ @@ -901,7 +901,7 @@ class Hooks implements } $linkFromPageId = $linksUpdate->getTitle()->getArticleID(); - EchoEvent::create( [ + Event::create( [ 'type' => 'page-linked', 'title' => $title, 'agent' => $user, @@ -1337,7 +1337,7 @@ class Hooks implements $revertedUser->getId() && // No notifications for anonymous users !$oldRevision->hasSameContent( $newRevision ) // No notifications for null rollbacks ) { - EchoEvent::create( [ + Event::create( [ 'type' => 'reverted', 'title' => $wikiPage->getTitle(), 'extra' => [ @@ -1480,7 +1480,7 @@ class Hooks implements $preview = $subject; } - EchoEvent::create( [ + Event::create( [ 'type' => 'emailuser', 'extra' => [ 'to-user-id' => $userTo->getId(), @@ -1543,7 +1543,7 @@ class Hooks implements $thankYouIds = []; $thankYouRows = $dbw->select( [ 'echo_notification', 'echo_event' ], - EchoEvent::selectFields(), + Event::selectFields(), [ 'notification_user' => $newUser->getId(), 'notification_event = event_id', @@ -1553,7 +1553,7 @@ class Hooks implements [ 'ORDER BY' => 'notification_timestamp ASC' ] ) ?: []; foreach ( $thankYouRows as $row ) { - $event = EchoEvent::newFromRow( $row ); + $event = Event::newFromRow( $row ); $editCount = $event ? $event->getExtraParam( 'editCount' ) : null; if ( $editCount ) { if ( isset( $counts[$editCount] ) ) { @@ -1698,7 +1698,7 @@ class Hooks implements } else { $type = 'watchlist-change'; } - EchoEvent::create( [ + Event::create( [ 'type' => $type, 'title' => $change->getTitle(), 'extra' => [ diff --git a/includes/Mapper/EventMapper.php b/includes/Mapper/EventMapper.php index d485b2d68..e0b0ba6e1 100644 --- a/includes/Mapper/EventMapper.php +++ b/includes/Mapper/EventMapper.php @@ -2,12 +2,12 @@ namespace MediaWiki\Extension\Notifications\Mapper; -use EchoEvent; +use MediaWiki\Extension\Notifications\Model\Event; use MWException; use User; /** - * Database mapper for EchoEvent model, which is an immutable class, there should + * Database mapper for Event model, which is an immutable class, there should * not be any update to it */ class EventMapper extends AbstractMapper { @@ -15,10 +15,10 @@ class EventMapper extends AbstractMapper { /** * Insert an event record * - * @param EchoEvent $event + * @param Event $event * @return int */ - public function insert( EchoEvent $event ) { + public function insert( Event $event ) { $dbw = $this->dbFactory->getEchoDb( DB_PRIMARY ); $row = $event->toDbArray(); @@ -36,26 +36,26 @@ class EventMapper extends AbstractMapper { } /** - * Create an EchoEvent by id + * Create an Event by id * * @param int $id * @param bool $fromPrimary - * @return EchoEvent|false False if it wouldn't load/unserialize + * @return Event|false False if it wouldn't load/unserialize * @throws MWException */ public function fetchById( $id, $fromPrimary = false ) { $db = $fromPrimary ? $this->dbFactory->getEchoDb( DB_PRIMARY ) : $this->dbFactory->getEchoDb( DB_REPLICA ); - $row = $db->selectRow( 'echo_event', EchoEvent::selectFields(), [ 'event_id' => $id ], __METHOD__ ); + $row = $db->selectRow( 'echo_event', Event::selectFields(), [ 'event_id' => $id ], __METHOD__ ); // If the row was not found, fall back on the primary database if it makes sense to do so if ( !$row && !$fromPrimary && $this->dbFactory->canRetryPrimary() ) { return $this->fetchById( $id, true ); } elseif ( !$row ) { - throw new MWException( "No EchoEvent found with ID: $id" ); + throw new MWException( "No Event found with ID: $id" ); } - return EchoEvent::newFromRow( $row ); + return Event::newFromRow( $row ); } /** @@ -84,7 +84,7 @@ class EventMapper extends AbstractMapper { * Fetch events associated with a page * * @param int $pageId - * @return EchoEvent[] Events + * @return Event[] Events */ public function fetchByPage( $pageId ) { $events = []; @@ -94,13 +94,13 @@ class EventMapper extends AbstractMapper { // From echo_event $res = $dbr->select( [ 'echo_event' ], - EchoEvent::selectFields(), + Event::selectFields(), [ 'event_page_id' => $pageId ], __METHOD__ ); if ( $res ) { foreach ( $res as $row ) { - $event = EchoEvent::newFromRow( $row ); + $event = Event::newFromRow( $row ); $events[] = $event; $seenEventIds[] = $event->getId(); } @@ -115,7 +115,7 @@ class EventMapper extends AbstractMapper { } $res = $dbr->select( [ 'echo_event', 'echo_target_page' ], - EchoEvent::selectFields(), + Event::selectFields(), $conds, __METHOD__, [ 'DISTINCT' ], @@ -123,7 +123,7 @@ class EventMapper extends AbstractMapper { ); if ( $res ) { foreach ( $res as $row ) { - $events[] = EchoEvent::newFromRow( $row ); + $events[] = Event::newFromRow( $row ); } } @@ -139,7 +139,7 @@ class EventMapper extends AbstractMapper { public function fetchIdsByPage( $pageId ) { $events = $this->fetchByPage( $pageId ); $eventIds = array_map( - static function ( EchoEvent $event ) { + static function ( Event $event ) { return $event->getId(); }, $events @@ -152,11 +152,11 @@ class EventMapper extends AbstractMapper { * * @param User $user * @param int $pageId - * @return EchoEvent[] + * @return Event[] */ public function fetchUnreadByUserAndPage( User $user, $pageId ) { $dbr = $this->dbFactory->getEchoDb( DB_REPLICA ); - $fields = array_merge( EchoEvent::selectFields(), [ 'notification_timestamp' ] ); + $fields = array_merge( Event::selectFields(), [ 'notification_timestamp' ] ); $res = $dbr->select( [ 'echo_event', 'echo_notification', 'echo_target_page' ], @@ -177,7 +177,7 @@ class EventMapper extends AbstractMapper { $data = []; foreach ( $res as $row ) { - $data[] = EchoEvent::newFromRow( $row ); + $data[] = Event::newFromRow( $row ); } return $data; diff --git a/includes/Mapper/NotificationMapper.php b/includes/Mapper/NotificationMapper.php index 8ff250bd2..40bfeb85d 100644 --- a/includes/Mapper/NotificationMapper.php +++ b/includes/Mapper/NotificationMapper.php @@ -5,8 +5,8 @@ namespace MediaWiki\Extension\Notifications\Mapper; use AtomicSectionUpdate; use BatchRowIterator; use DeferredUpdates; -use EchoNotification; use Exception; +use MediaWiki\Extension\Notifications\Model\Notification; use MediaWiki\MediaWikiServices; use MediaWiki\User\UserIdentity; use MWException; @@ -15,15 +15,15 @@ use Title; use Wikimedia\Rdbms\IDatabase; /** - * Database mapper for EchoNotification model + * Database mapper for Notification model */ class NotificationMapper extends AbstractMapper { /** * Insert a notification record - * @param EchoNotification $notification + * @param Notification $notification */ - public function insert( EchoNotification $notification ) { + public function insert( Notification $notification ) { $dbw = $this->dbFactory->getEchoDb( DB_PRIMARY ); $listeners = $this->getMethodListeners( __FUNCTION__ ); @@ -81,7 +81,7 @@ class NotificationMapper extends AbstractMapper { * @param Title[]|null $titles If set, only return notifications for these pages. * To find notifications not associated with any page, add null as an element to this array. * @param int $dbSource Use primary database or replica database - * @return EchoNotification[] + * @return Notification[] */ public function fetchUnreadByUser( UserIdentity $userIdentity, @@ -121,7 +121,7 @@ class NotificationMapper extends AbstractMapper { * @param Title[]|null $titles If set, only return notifications for these pages. * To find notifications not associated with any page, add null as an element to this array. * @param int $dbSource Use primary database or replica database - * @return EchoNotification[] + * @return Notification[] */ public function fetchReadByUser( UserIdentity $userIdentity, @@ -158,7 +158,7 @@ class NotificationMapper extends AbstractMapper { * @param array $excludeEventIds Event id's to exclude. * @param Title[]|null $titles If set, only return notifications for these pages. * To find notifications not associated with any page, add null as an element to this array. - * @return EchoNotification[] + * @return Notification[] */ public function fetchByUser( UserIdentity $userIdentity, @@ -209,7 +209,7 @@ class NotificationMapper extends AbstractMapper { * @param array $eventTypes Event types to load * @param array $conds Additional query conditions. * @param int $dbSource Use primary database or replica database - * @return EchoNotification[] + * @return Notification[] */ protected function fetchByUserInternal( UserIdentity $userIdentity, @@ -249,7 +249,7 @@ class NotificationMapper extends AbstractMapper { $res = $dbr->select( [ 'echo_notification', 'echo_event' ], - EchoNotification::selectFields(), + Notification::selectFields(), $conds, __METHOD__, [ @@ -266,11 +266,11 @@ class NotificationMapper extends AbstractMapper { return []; } - /** @var EchoNotification[] $allNotifications */ + /** @var Notification[] $allNotifications */ $allNotifications = []; foreach ( $res as $row ) { try { - $notification = EchoNotification::newFromRow( $row ); + $notification = Notification::newFromRow( $row ); if ( $notification ) { $allNotifications[] = $notification; } @@ -290,18 +290,18 @@ class NotificationMapper extends AbstractMapper { } /** - * Fetch EchoNotifications by user and event IDs. + * Fetch Notifications by user and event IDs. * * @param UserIdentity $userIdentity * @param int[] $eventIds - * @return EchoNotification[]|false + * @return Notification[]|false */ public function fetchByUserEvents( UserIdentity $userIdentity, array $eventIds ) { $dbr = $this->dbFactory->getEchoDb( DB_REPLICA ); $result = $dbr->select( [ 'echo_notification', 'echo_event' ], - EchoNotification::selectFields(), + Notification::selectFields(), [ 'notification_user' => $userIdentity->getId(), 'notification_event' => $eventIds @@ -316,7 +316,7 @@ class NotificationMapper extends AbstractMapper { if ( $result ) { $notifications = []; foreach ( $result as $row ) { - $notifications[] = EchoNotification::newFromRow( $row ); + $notifications[] = Notification::newFromRow( $row ); } return $notifications; } else { @@ -329,13 +329,13 @@ class NotificationMapper extends AbstractMapper { * know that passing a big number for offset is NOT going to work * @param UserIdentity $userIdentity * @param int $offset - * @return EchoNotification|false + * @return Notification|false */ public function fetchByUserOffset( UserIdentity $userIdentity, $offset ) { $dbr = $this->dbFactory->getEchoDb( DB_REPLICA ); $row = $dbr->selectRow( [ 'echo_notification', 'echo_event' ], - EchoNotification::selectFields(), + Notification::selectFields(), [ 'notification_user' => $userIdentity->getId(), 'event_deleted' => 0, @@ -352,7 +352,7 @@ class NotificationMapper extends AbstractMapper { ); if ( $row ) { - return EchoNotification::newFromRow( $row ); + return Notification::newFromRow( $row ); } else { return false; } diff --git a/includes/Mapper/TargetPageMapper.php b/includes/Mapper/TargetPageMapper.php index 38b56ae8b..9c544afc9 100644 --- a/includes/Mapper/TargetPageMapper.php +++ b/includes/Mapper/TargetPageMapper.php @@ -2,15 +2,15 @@ namespace MediaWiki\Extension\Notifications\Mapper; -use EchoTargetPage; +use MediaWiki\Extension\Notifications\Model\TargetPage; /** - * Database mapper for EchoTargetPage model + * Database mapper for TargetPage model */ class TargetPageMapper extends AbstractMapper { /** - * List of db fields used to construct an EchoTargetPage model + * List of db fields used to construct an TargetPage model * @var string[] */ protected static $fields = [ @@ -19,12 +19,12 @@ class TargetPageMapper extends AbstractMapper { ]; /** - * Insert an EchoTargetPage instance into the database + * Insert an TargetPage instance into the database * - * @param EchoTargetPage $targetPage + * @param TargetPage $targetPage * @return bool */ - public function insert( EchoTargetPage $targetPage ) { + public function insert( TargetPage $targetPage ) { $dbw = $this->dbFactory->getEchoDb( DB_PRIMARY ); $row = $targetPage->toDbArray(); diff --git a/includes/model/AbstractEntity.php b/includes/Model/AbstractEntity.php similarity index 65% rename from includes/model/AbstractEntity.php rename to includes/Model/AbstractEntity.php index fed21f4e0..371dfca4d 100644 --- a/includes/model/AbstractEntity.php +++ b/includes/Model/AbstractEntity.php @@ -1,9 +1,11 @@ id ) { - throw new MWException( "Unable to serialize an uninitialized EchoEvent" ); + throw new MWException( "Unable to serialize an uninitialized Event" ); } return [ 'id', 'timestamp' ]; @@ -97,11 +109,11 @@ class EchoEvent extends EchoAbstractEntity implements Bundleable { } public function __toString() { - return "EchoEvent(id={$this->id}; type={$this->type})"; + return "Event(id={$this->id}; type={$this->type})"; } /** - * Creates an EchoEvent object + * Creates an Event object * @param array $info Named arguments: * type (required): The event type; * variant: A variant of the type; @@ -122,7 +134,7 @@ class EchoEvent extends EchoAbstractEntity implements Bundleable { * [ 'extra' => Job::newRootJobParams('example') ] * * @throws MWException - * @return EchoEvent|false False if aborted via hook or Echo DB is read-only + * @return Event|false False if aborted via hook or Echo DB is read-only */ public static function create( $info = [] ) { global $wgEchoNotifications; @@ -134,7 +146,7 @@ class EchoEvent extends EchoAbstractEntity implements Bundleable { return false; } - $obj = new EchoEvent; + $obj = new Event; static $validFields = [ 'type', 'variant', 'agent', 'title', 'extra' ]; if ( empty( $info['type'] ) ) { @@ -188,7 +200,7 @@ class EchoEvent extends EchoAbstractEntity implements Bundleable { // @Todo - Database insert logic should not be inside the model $obj->insert(); - Hooks::run( 'EchoEventInsertComplete', [ $obj ] ); + Hooks::run( 'EventInsertComplete', [ $obj ] ); global $wgEchoUseJobQueue; @@ -258,7 +270,7 @@ class EchoEvent extends EchoAbstractEntity implements Bundleable { if ( $targetPages ) { $targetMapper = new TargetPageMapper(); foreach ( $targetPages as $title ) { - $targetPage = EchoTargetPage::create( $title, $this ); + $targetPage = TargetPage::create( $title, $this ); if ( $targetPage ) { $targetMapper->insert( $targetPage ); } @@ -387,26 +399,26 @@ class EchoEvent extends EchoAbstractEntity implements Bundleable { } /** - * Creates an EchoEvent from a row object + * Creates an Event from a row object * * @param stdClass $row row object from echo_event - * @return EchoEvent|false + * @return Event|false */ public static function newFromRow( $row ) { - $obj = new EchoEvent(); + $obj = new Event(); return $obj->loadFromRow( $row ) ? $obj : false; } /** - * Creates an EchoEvent from the database by ID + * Creates an Event from the database by ID * * @param int $id Event ID - * @return EchoEvent|false + * @return Event|false */ public static function newFromID( $id ) { - $obj = new EchoEvent(); + $obj = new Event(); return $obj->loadFromID( $id ) ? $obj : false; @@ -597,9 +609,7 @@ class EchoEvent extends EchoAbstractEntity implements Bundleable { * @return string */ public function getCategory() { - $attributeManager = EchoServices::getInstance()->getAttributeManager(); - - return $attributeManager->getNotificationCategory( $this->type ); + return EchoServices::getInstance()->getAttributeManager()->getNotificationCategory( $this->type ); } /** @@ -607,9 +617,7 @@ class EchoEvent extends EchoAbstractEntity implements Bundleable { * @return string */ public function getSection() { - $attributeManager = EchoServices::getInstance()->getAttributeManager(); - - return $attributeManager->getNotificationSection( $this->type ); + return EchoServices::getInstance()->getAttributeManager()->getNotificationSection( $this->type ); } /** @@ -735,7 +743,7 @@ class EchoEvent extends EchoAbstractEntity implements Bundleable { /** * Return the list of fields that should be selected to create - * a new event with EchoEvent::newFromRow + * a new event with Event::newFromRow * @return string[] */ public static function selectFields() { @@ -753,5 +761,4 @@ class EchoEvent extends EchoAbstractEntity implements Bundleable { } -// Needed to help migrate AbuseFilter -class_alias( EchoEvent::class, 'MediaWiki\\Extension\\Notifications\\Model\\Event' ); +class_alias( Event::class, 'EchoEvent' ); diff --git a/includes/model/Notification.php b/includes/Model/Notification.php similarity index 82% rename from includes/model/Notification.php rename to includes/Model/Notification.php index 4ed8abe14..d69c0d932 100644 --- a/includes/model/Notification.php +++ b/includes/Model/Notification.php @@ -1,9 +1,18 @@ event instanceof EchoEvent ) { - throw new InvalidArgumentException( 'Invalid event parameter, expected: EchoEvent object' ); + if ( !$obj->event instanceof Event ) { + throw new InvalidArgumentException( 'Invalid event parameter, expected: Event object' ); } // Notification timestamp should be the same as event timestamp @@ -133,16 +142,16 @@ class EchoNotification extends EchoAbstractEntity implements Bundleable { /** * Load a notification record from std class * @param stdClass $row - * @param EchoTargetPage[]|null $targetPages An array of EchoTargetPage instances, or null if not loaded. - * @return EchoNotification|false False if failed to load/unserialize + * @param TargetPage[]|null $targetPages An array of TargetPage instances, or null if not loaded. + * @return Notification|false False if failed to load/unserialize */ public static function newFromRow( $row, array $targetPages = null ) { - $notification = new EchoNotification(); + $notification = new Notification(); if ( property_exists( $row, 'event_type' ) ) { - $notification->event = EchoEvent::newFromRow( $row ); + $notification->event = Event::newFromRow( $row ); } else { - $notification->event = EchoEvent::newFromID( $row->notification_event ); + $notification->event = Event::newFromID( $row->notification_event ); } if ( $notification->event === false ) { @@ -175,7 +184,7 @@ class EchoNotification extends EchoAbstractEntity implements Bundleable { /** * Getter method - * @return EchoEvent The event for this notification + * @return Event The event for this notification */ public function getEvent() { return $this->event; @@ -218,10 +227,10 @@ class EchoNotification extends EchoAbstractEntity implements Bundleable { } /** - * Getter method. Returns an array of EchoTargetPages, or null if they have + * Getter method. Returns an array of TargetPage's, or null if they have * not been loaded. * - * @return EchoTargetPage[]|null + * @return TargetPage[]|null */ public function getTargetPages() { return $this->targetPages; @@ -265,11 +274,11 @@ class EchoNotification extends EchoAbstractEntity implements Bundleable { /** * Return the list of fields that should be selected to create - * a new event with EchoNotification::newFromRow + * a new event with Notification::newFromRow * @return string[] */ public static function selectFields() { - return array_merge( EchoEvent::selectFields(), [ + return array_merge( Event::selectFields(), [ 'notification_event', 'notification_user', 'notification_timestamp', @@ -278,3 +287,5 @@ class EchoNotification extends EchoAbstractEntity implements Bundleable { ] ); } } + +class_alias( Notification::class, 'EchoNotification' ); diff --git a/includes/model/TargetPage.php b/includes/Model/TargetPage.php similarity index 82% rename from includes/model/TargetPage.php rename to includes/Model/TargetPage.php index 4134f039b..d4f8bddb8 100644 --- a/includes/model/TargetPage.php +++ b/includes/Model/TargetPage.php @@ -1,11 +1,17 @@ getArticleID() ) { return null; @@ -61,10 +67,10 @@ class EchoTargetPage extends EchoAbstractEntity { } /** - * Create a EchoTargetPage instance from stdClass object + * Create a TargetPage instance from stdClass object * * @param stdClass $row - * @return EchoTargetPage + * @return TargetPage * @throws MWException */ public static function newFromRow( $row ) { @@ -106,11 +112,11 @@ class EchoTargetPage extends EchoAbstractEntity { } /** - * @return EchoEvent + * @return Event */ public function getEvent() { if ( !$this->event ) { - $this->event = EchoEvent::newFromID( $this->eventId ); + $this->event = Event::newFromID( $this->eventId ); } return $this->event; diff --git a/includes/NotifUser.php b/includes/NotifUser.php index 0c5dfe210..a758bf370 100644 --- a/includes/NotifUser.php +++ b/includes/NotifUser.php @@ -3,6 +3,7 @@ use MediaWiki\Extension\Notifications\Gateway\UserNotificationGateway; use MediaWiki\Extension\Notifications\Mapper\NotificationMapper; use MediaWiki\Extension\Notifications\Mapper\TargetPageMapper; +use MediaWiki\Extension\Notifications\Model\Notification; use MediaWiki\MediaWikiServices; use MediaWiki\User\UserFactory; use MediaWiki\User\UserIdentity; @@ -385,7 +386,7 @@ class MWEchoNotifUser { $notifs = $this->notifMapper->fetchUnreadByUser( $this->mUser, $wgEchoMaxUpdateCount, null, $eventTypes ); $eventIds = array_filter( - array_map( static function ( EchoNotification $notif ) { + array_map( static function ( Notification $notif ) { // This should not happen at all, but use 0 in // such case so to keep the code running if ( $notif->getEvent() ) { diff --git a/includes/Notifier.php b/includes/Notifier.php index 88bcd404d..d6933cb63 100644 --- a/includes/Notifier.php +++ b/includes/Notifier.php @@ -2,16 +2,18 @@ use MediaWiki\Extension\Notifications\Formatters\EchoHtmlEmailFormatter; use MediaWiki\Extension\Notifications\Formatters\EchoPlainTextEmailFormatter; +use MediaWiki\Extension\Notifications\Model\Event; +use MediaWiki\Extension\Notifications\Model\Notification; use MediaWiki\MediaWikiServices; // @todo Fill in class EchoNotifier { /** - * Record an EchoNotification for an EchoEvent + * Record a Notification for an Event * Currently used for web-based notifications. * * @param User $user User to notify. - * @param EchoEvent $event EchoEvent to notify about. + * @param Event $event Event to notify about. */ public static function notifyWithNotification( $user, $event ) { // Only create the notification if the user wants to receive that type @@ -22,14 +24,14 @@ class EchoNotifier { return; } - EchoNotification::create( [ 'user' => $user, 'event' => $event ] ); + Notification::create( [ 'user' => $user, 'event' => $event ] ); } /** * Send a Notification to a user by email * * @param User $user User to notify. - * @param EchoEvent $event EchoEvent to notify about. + * @param Event $event Event to notify about. * @return bool */ public static function notifyWithEmail( $user, $event ) { @@ -115,11 +117,11 @@ class EchoNotifier { } /** - * @param EchoEvent $event + * @param Event $event * @param User $user * @return array|false An array of 'subject' and 'body', or false if things went wrong */ - private static function generateEmail( EchoEvent $event, User $user ) { + private static function generateEmail( Event $event, User $user ) { $emailFormat = MWEchoNotifUser::newFromUser( $user )->getEmailFormat(); $userOptionsLookup = MediaWikiServices::getInstance()->getUserOptionsLookup(); $lang = Language::factory( $userOptionsLookup->getOption( $user, 'language' ) ); diff --git a/includes/Push/PushNotifier.php b/includes/Push/PushNotifier.php index c401454f9..a8db58598 100644 --- a/includes/Push/PushNotifier.php +++ b/includes/Push/PushNotifier.php @@ -2,8 +2,8 @@ namespace MediaWiki\Extension\Notifications\Push; -use EchoEvent; use EchoServices; +use MediaWiki\Extension\Notifications\Model\Event; use MediaWiki\MediaWikiServices; use User; @@ -13,9 +13,9 @@ class PushNotifier { * Submits a notification derived from an Echo event to each push notifications service * subscription found for a user, via a configured service handler implementation * @param User $user - * @param EchoEvent $event + * @param Event $event */ - public static function notifyWithPush( User $user, EchoEvent $event ): void { + public static function notifyWithPush( User $user, Event $event ): void { $attributeManager = EchoServices::getInstance()->getAttributeManager(); $userEnabledEvents = $attributeManager->getUserEnabledEvents( $user, 'push' ); if ( in_array( $event->getType(), $userEnabledEvents ) ) { @@ -25,10 +25,10 @@ class PushNotifier { /** * @param User $user - * @param EchoEvent|null $event + * @param Event|null $event * @return NotificationRequestJob */ - private static function createJob( User $user, EchoEvent $event = null ): NotificationRequestJob { + private static function createJob( User $user, Event $event = null ): NotificationRequestJob { $centralId = Utils::getPushUserId( $user ); $params = [ 'centralId' => $centralId ]; // below params are only needed for debug logging (T255068) diff --git a/includes/Special/NotificationPager.php b/includes/Special/NotificationPager.php index 67ff83dba..8fbad3d02 100644 --- a/includes/Special/NotificationPager.php +++ b/includes/Special/NotificationPager.php @@ -2,10 +2,10 @@ namespace MediaWiki\Extension\Notifications\Special; -use EchoNotification; use EchoServices; use Exception; use IContextSource; +use MediaWiki\Extension\Notifications\Model\Notification; use MWEchoDbFactory; use ReverseChronologicalPager; @@ -28,7 +28,7 @@ class NotificationPager extends ReverseChronologicalPager { public function formatRow( $row ) { // @phan-suppress-previous-line PhanPluginNeverReturnMethod LSP violation throw new Exception( "This pager does not support row formatting. " . - "Use 'getNotifications()' to get a list of EchoNotification objects." ); + "Use 'getNotifications()' to get a list of Notification objects." ); } public function getQueryInfo() { @@ -37,7 +37,7 @@ class NotificationPager extends ReverseChronologicalPager { return [ 'tables' => [ 'echo_notification', 'echo_event' ], - 'fields' => EchoNotification::selectFields(), + 'fields' => Notification::selectFields(), 'conds' => [ 'notification_user' => $this->getUser()->getId(), 'event_type' => $eventTypes, @@ -61,7 +61,7 @@ class NotificationPager extends ReverseChronologicalPager { $notifications = []; foreach ( $this->mResult as $row ) { - $notifications[] = EchoNotification::newFromRow( $row ); + $notifications[] = Notification::newFromRow( $row ); } // get rid of the overfetched diff --git a/includes/UserLocator.php b/includes/UserLocator.php index 5021e75e0..9f39b75b6 100644 --- a/includes/UserLocator.php +++ b/includes/UserLocator.php @@ -1,6 +1,7 @@ */ - public static function locateUsersWatchingTitle( EchoEvent $event, $batchSize = 500 ) { + public static function locateUsersWatchingTitle( Event $event, $batchSize = 500 ) { $title = $event->getTitle(); if ( !$title ) { return []; @@ -47,10 +48,10 @@ class EchoUserLocator { * If the event occurred on the talk page of a registered * user return that user. * - * @param EchoEvent $event + * @param Event $event * @return User[] */ - public static function locateTalkPageOwner( EchoEvent $event ) { + public static function locateTalkPageOwner( Event $event ) { $title = $event->getTitle(); if ( !$title || $title->getNamespace() !== NS_USER_TALK ) { return []; @@ -67,10 +68,10 @@ class EchoUserLocator { /** * Return the event agent * - * @param EchoEvent $event + * @param Event $event * @return User[] */ - public static function locateEventAgent( EchoEvent $event ) { + public static function locateEventAgent( Event $event ) { $agent = $event->getAgent(); if ( $agent && $agent->isRegistered() ) { return [ $agent->getId() => $agent ]; @@ -83,10 +84,10 @@ class EchoUserLocator { * Return the user that created the first revision of the * associated title. * - * @param EchoEvent $event + * @param Event $event * @return User[] */ - public static function locateArticleCreator( EchoEvent $event ) { + public static function locateArticleCreator( Event $event ) { $title = $event->getTitle(); if ( !$title || $title->getArticleID() <= 0 ) { @@ -125,11 +126,11 @@ class EchoUserLocator { * array of user ids. It will return all these users as notification * targets. * - * @param EchoEvent $event + * @param Event $event * @param string[] $keys one or more keys to check for user ids * @return User[] */ - public static function locateFromEventExtra( EchoEvent $event, array $keys ) { + public static function locateFromEventExtra( Event $event, array $keys ) { $users = []; foreach ( $keys as $key ) { $userIds = $event->getExtraParam( $key ); diff --git a/maintenance/generateSampleNotifications.php b/maintenance/generateSampleNotifications.php index 94c83b0ae..05e5a97ce 100644 --- a/maintenance/generateSampleNotifications.php +++ b/maintenance/generateSampleNotifications.php @@ -2,6 +2,7 @@ // phpcs:disable Generic.Files.LineLength -- Long html test examples // @phan-file-suppress PhanUndeclaredClassMethod, PhanUndeclaredClassConstant Other extensions used for testing purposes +use MediaWiki\Extension\Notifications\Model\Event; use MediaWiki\MediaWikiServices; use MediaWiki\Revision\RevisionRecord; use MediaWiki\Revision\SlotRecord; @@ -322,7 +323,7 @@ class GenerateSampleNotifications extends Maintenance { private function generateWelcome( User $user ) { $this->output( "Welcoming {$user->getName()}\n" ); - EchoEvent::create( [ + Event::create( [ 'type' => 'welcome', 'agent' => $user, 'timestamp' => $this->getTimestamp(), @@ -332,7 +333,7 @@ class GenerateSampleNotifications extends Maintenance { private function generateEmail( User $user, User $agent ) { $output = $this->addTimestampToOutput( "{$agent->getName()} is emailing {$user->getName()}" ); $this->output( "$output\n" ); - EchoEvent::create( [ + Event::create( [ 'type' => 'emailuser', 'extra' => [ 'to-user-id' => $user->getId(), @@ -352,7 +353,7 @@ class GenerateSampleNotifications extends Maintenance { } private function createUserRightsNotification( User $user, User $agent, $add, $remove ) { - EchoEvent::create( + Event::create( [ 'type' => 'user-rights', 'extra' => [ @@ -374,7 +375,7 @@ class GenerateSampleNotifications extends Maintenance { $this->output( "Generating CX notifications\n" ); foreach ( [ 'cx-first-translation', 'cx-tenth-translation', 'cx-hundredth-translation' ] as $eventType ) { - EchoEvent::create( + Event::create( [ 'type' => $eventType, 'extra' => [ @@ -385,7 +386,7 @@ class GenerateSampleNotifications extends Maintenance { ); } - EchoEvent::create( + Event::create( [ 'type' => 'cx-suggestions-available', 'extra' => [ @@ -428,7 +429,7 @@ class GenerateSampleNotifications extends Maintenance { $this->output( "Generating OpenStackManager notifications\n" ); foreach ( [ 'build-completed', 'reboot-completed', 'deleted' ] as $action ) { - EchoEvent::create( [ + Event::create( [ 'type' => "osm-instance-$action", 'title' => Title::newFromText( "Moai" ), 'agent' => $user, @@ -441,7 +442,7 @@ class GenerateSampleNotifications extends Maintenance { ] ); } - EchoEvent::create( [ + Event::create( [ 'type' => 'osm-projectmembers-add', 'title' => Title::newFromText( "Moai" ), 'agent' => $agent, @@ -466,7 +467,7 @@ class GenerateSampleNotifications extends Maintenance { // make an edit, thank it once $title = $this->generateNewPageTitle(); $revisionRecord = $this->addToPageContent( $title, $user, "an awesome edit! ~~~~" ); - EchoEvent::create( [ + Event::create( [ 'type' => 'edit-thank', 'title' => $title, 'extra' => [ @@ -488,7 +489,7 @@ class GenerateSampleNotifications extends Maintenance { // make an edit, thank it twice $title = $this->generateNewPageTitle(); $revisionRecord = $this->addToPageContent( $title, $user, "an even better edit! ~~~~" ); - EchoEvent::create( [ + Event::create( [ 'type' => 'edit-thank', 'title' => $title, 'extra' => [ @@ -499,7 +500,7 @@ class GenerateSampleNotifications extends Maintenance { 'agent' => $agent, 'timestamp' => $this->getTimestamp(), ] ); - EchoEvent::create( [ + Event::create( [ 'type' => 'edit-thank', 'title' => $title, 'extra' => [ @@ -564,7 +565,7 @@ class GenerateSampleNotifications extends Maintenance { $output = $this->addTimestampToOutput( "{$agent->getName()} is connecting {$user->getName()}'s page {$title->getPrefixedText()} to an item" ); $this->output( "$output\n" ); - EchoEvent::create( [ + Event::create( [ 'type' => EchoNotificationsHandlers::NOTIFICATION_TYPE, 'title' => $title, 'extra' => [ diff --git a/tests/phpunit/Controller/NotificationControllerTest.php b/tests/phpunit/Controller/NotificationControllerTest.php index f307ad413..62abe5d9c 100644 --- a/tests/phpunit/Controller/NotificationControllerTest.php +++ b/tests/phpunit/Controller/NotificationControllerTest.php @@ -1,6 +1,7 @@ createMock( EchoEvent::class ); + $event = $this->createMock( Event::class ); $event->method( 'getType' ) ->willReturn( 'unit-test' ); @@ -97,7 +98,7 @@ class NotificationControllerTest extends MediaWikiIntegrationTestCase { public function testEvaluateUserLocatorPassesParameters() { $callback = function ( $event, $firstOption, $secondOption ) { - $this->assertInstanceOf( EchoEvent::class, $event ); + $this->assertInstanceOf( Event::class, $event ); $this->assertEquals( 'first', $firstOption ); $this->assertEquals( 'second', $secondOption ); @@ -157,7 +158,7 @@ class NotificationControllerTest extends MediaWikiIntegrationTestCase { ], ] ); - $event = $this->createMock( EchoEvent::class ); + $event = $this->createMock( Event::class ); $event->method( 'getType' ) ->willReturn( 'unit-test' ); @@ -170,7 +171,7 @@ class NotificationControllerTest extends MediaWikiIntegrationTestCase { } public function testDoesNotDeliverDisabledEvent() { - $event = $this->createMock( EchoEvent::class ); + $event = $this->createMock( Event::class ); $event->method( 'isEnabledEvent' ) ->willReturn( false ); // Assume it would have to check the event type to @@ -257,7 +258,7 @@ class NotificationControllerTest extends MediaWikiIntegrationTestCase { } public function testEnqueueEvent() { - $event = $this->createMock( EchoEvent::class ); + $event = $this->createMock( Event::class ); $event->method( 'getExtraParam' ) ->willReturn( null ); $event->expects( $this->once() ) @@ -280,7 +281,7 @@ class NotificationControllerTest extends MediaWikiIntegrationTestCase { $queueGroup = $this->getServiceContainer()->getJobQueueGroup(); $this->assertCount( 0, $queueGroup->getQueuesWithJobs() ); - $event = $this->createMock( EchoEvent::class ); + $event = $this->createMock( Event::class ); $event->method( 'getExtraParam' ) ->will( $this->returnValueMap( [ @@ -303,7 +304,7 @@ class NotificationControllerTest extends MediaWikiIntegrationTestCase { $rootJobTimestamp = wfTimestamp(); MWTimestamp::setFakeTime( 0 ); - $event = $this->createMock( EchoEvent::class ); + $event = $this->createMock( Event::class ); $event->method( 'getExtraParam' ) ->will( $this->returnValueMap( [ diff --git a/tests/phpunit/DiscussionParserTest.php b/tests/phpunit/DiscussionParserTest.php index a10cd54e3..7121d0fc9 100644 --- a/tests/phpunit/DiscussionParserTest.php +++ b/tests/phpunit/DiscussionParserTest.php @@ -2,6 +2,7 @@ // phpcs:disable Generic.Files.LineLength -- Long html test examples +use MediaWiki\Extension\Notifications\Model\Event; use MediaWiki\MediaWikiServices; use MediaWiki\Revision\MutableRevisionRecord; use MediaWiki\Revision\SlotRecord; @@ -208,7 +209,7 @@ class EchoDiscussionParserTest extends MediaWikiIntegrationTestCase { 'agent' => 'Cwobeel', 'section-title' => 'Grand jury no bill reception', /* - * I wish I could also compare EchoEvent::$extra data to + * I wish I could also compare Event::$extra data to * compare user ids of mentioned users. However, due to * How PHPUnit works, setUp won't be run by the time * this dataset is generated, so we don't yet know the @@ -389,7 +390,7 @@ class EchoDiscussionParserTest extends MediaWikiIntegrationTestCase { ); $events = []; $this->setupEventCallbackForEventGeneration( - static function ( EchoEvent $event ) use ( &$events ) { + static function ( Event $event ) use ( &$events ) { $events[] = [ 'type' => $event->getType(), 'agent' => $event->getAgent()->getName(), @@ -707,7 +708,7 @@ class EchoDiscussionParserTest extends MediaWikiIntegrationTestCase { ); $events = []; $this->setupEventCallbackForEventGeneration( - static function ( EchoEvent $event ) use ( &$events ) { + static function ( Event $event ) use ( &$events ) { $events[] = [ 'type' => $event->getType(), 'agent' => $event->getAgent()->getName(), @@ -908,7 +909,7 @@ TEXT $events = []; $this->setupEventCallbackForEventGeneration( - static function ( EchoEvent $event ) use ( &$events ) { + static function ( Event $event ) use ( &$events ) { $events[] = [ 'type' => $event->getType(), 'agent' => $event->getAgent()->getName(), diff --git a/tests/phpunit/Formatters/EchoPresentationModelSectionTest.php b/tests/phpunit/Formatters/EchoPresentationModelSectionTest.php index 90d854884..f5396bae4 100644 --- a/tests/phpunit/Formatters/EchoPresentationModelSectionTest.php +++ b/tests/phpunit/Formatters/EchoPresentationModelSectionTest.php @@ -1,6 +1,7 @@ getTestSysop()->getUser(); - return EchoEvent::newFromRow( (object)array_merge( [ + return Event::newFromRow( (object)array_merge( [ 'event_id' => 12, 'event_type' => 'welcome', 'event_variant' => '1', diff --git a/tests/phpunit/Mapper/EventMapperTest.php b/tests/phpunit/Mapper/EventMapperTest.php index 90bc59bca..cae41ed68 100644 --- a/tests/phpunit/Mapper/EventMapperTest.php +++ b/tests/phpunit/Mapper/EventMapperTest.php @@ -1,6 +1,7 @@ mockEchoEvent(); + $event = $this->mockEvent(); $eventMapper = new EventMapper( $this->mockMWEchoDbFactory( $dbResult ) ); $this->assertEquals( $result, $eventMapper->insert( $event ), $message ); } @@ -61,7 +62,7 @@ class EventMapperTest extends MediaWikiIntegrationTestCase { ) ); $res = $eventMapper->fetchById( 1 ); - $this->assertInstanceOf( EchoEvent::class, $res ); + $this->assertInstanceOf( Event::class, $res ); } public function testUnsuccessfulFetchById() { @@ -77,10 +78,10 @@ class EventMapperTest extends MediaWikiIntegrationTestCase { } /** - * @return EchoEvent + * @return Event */ - protected function mockEchoEvent() { - $event = $this->createMock( EchoEvent::class ); + protected function mockEvent() { + $event = $this->createMock( Event::class ); $event->method( 'toDbArray' ) ->willReturn( [] ); @@ -128,20 +129,20 @@ class EventMapperTest extends MediaWikiIntegrationTestCase { $page = $this->getExistingTestPage(); // Create a notification that is not associated with any page - EchoEvent::create( [ + Event::create( [ 'type' => 'welcome', 'agent' => $user, ] ); // Create a notification with a title - $eventWithTitle = EchoEvent::create( [ + $eventWithTitle = Event::create( [ 'type' => 'welcome', 'agent' => $user, 'title' => $page->getTitle() ] ); // Create a notification with a target-page - $eventWithTargetPage = EchoEvent::create( [ + $eventWithTargetPage = Event::create( [ 'type' => 'welcome', 'agent' => $user, 'extra' => [ 'target-page' => $page->getId() ] diff --git a/tests/phpunit/Mapper/NotificationMapperTest.php b/tests/phpunit/Mapper/NotificationMapperTest.php index a80c32145..868721176 100644 --- a/tests/phpunit/Mapper/NotificationMapperTest.php +++ b/tests/phpunit/Mapper/NotificationMapperTest.php @@ -1,6 +1,7 @@ assertIsArray( $res ); $this->assertNotEmpty( $res ); foreach ( $res as $row ) { - $this->assertInstanceOf( EchoNotification::class, $row ); + $this->assertInstanceOf( Notification::class, $row ); } } @@ -92,7 +93,7 @@ class NotificationMapperTest extends MediaWikiIntegrationTestCase { $this->assertIsArray( $res ); $this->assertNotEmpty( $res ); foreach ( $res as $row ) { - $this->assertInstanceOf( EchoNotification::class, $row ); + $this->assertInstanceOf( Notification::class, $row ); } $notifMapper = new NotificationMapper( $this->mockMWEchoDbFactory( [] ) ); @@ -123,7 +124,7 @@ class NotificationMapperTest extends MediaWikiIntegrationTestCase { ]; $notifMapper = new NotificationMapper( $this->mockMWEchoDbFactory( [ 'selectRow' => $dbResult ] ) ); $row = $notifMapper->fetchByUserOffset( User::newFromId( 1 ), 500 ); - $this->assertInstanceOf( EchoNotification::class, $row ); + $this->assertInstanceOf( Notification::class, $row ); } public function testDeleteByUserEventOffset() { @@ -207,11 +208,11 @@ class NotificationMapperTest extends MediaWikiIntegrationTestCase { } /** - * Mock object of EchoNotification - * @return EchoNotification + * Mock object of Notification + * @return Notification */ - protected function mockEchoNotification() { - $event = $this->createMock( EchoNotification::class ); + protected function mockNotification() { + $event = $this->createMock( Notification::class ); $event->method( 'toDbArray' ) ->willReturn( [] ); diff --git a/tests/phpunit/model/NotificationTest.php b/tests/phpunit/Model/NotificationTest.php similarity index 70% rename from tests/phpunit/model/NotificationTest.php rename to tests/phpunit/Model/NotificationTest.php index f9ebc6255..a49da6db5 100644 --- a/tests/phpunit/model/NotificationTest.php +++ b/tests/phpunit/Model/NotificationTest.php @@ -1,39 +1,43 @@ mockNotificationRow() + $this->mockEventRow(); - $notif = EchoNotification::newFromRow( (object)$row ); - $this->assertInstanceOf( EchoNotification::class, $notif ); + $notif = Notification::newFromRow( (object)$row ); + $this->assertInstanceOf( Notification::class, $notif ); // getReadTimestamp() should return null $this->assertNull( $notif->getReadTimestamp() ); $this->assertEquals( $notif->getTimestamp(), wfTimestamp( TS_MW, $row['notification_timestamp'] ) ); - $this->assertInstanceOf( EchoEvent::class, $notif->getEvent() ); + $this->assertInstanceOf( Event::class, $notif->getEvent() ); $this->assertNull( $notif->getTargetPages() ); // Provide a read timestamp $row['notification_read_timestamp'] = time() + 1000; - $notif = EchoNotification::newFromRow( (object)$row ); + $notif = Notification::newFromRow( (object)$row ); // getReadTimestamp() should return the timestamp in MW format $this->assertEquals( $notif->getReadTimestamp(), wfTimestamp( TS_MW, $row['notification_read_timestamp'] ) ); - $notif = EchoNotification::newFromRow( (object)$row, [ - EchoTargetPage::newFromRow( (object)$this->mockTargetPageRow() ) + $notif = Notification::newFromRow( (object)$row, [ + TargetPage::newFromRow( (object)$this->mockTargetPageRow() ) ] ); $this->assertNotEmpty( $notif->getTargetPages() ); foreach ( $notif->getTargetPages() as $targetPage ) { - $this->assertInstanceOf( EchoTargetPage::class, $targetPage ); + $this->assertInstanceOf( TargetPage::class, $targetPage ); } } @@ -42,7 +46,7 @@ class EchoNotificationTest extends MediaWikiIntegrationTestCase { // Provide an invalid event id $row['notification_event'] = -1; $this->expectException( MWException::class ); - EchoNotification::newFromRow( (object)$row ); + Notification::newFromRow( (object)$row ); } /** diff --git a/tests/phpunit/NotifUserTest.php b/tests/phpunit/NotifUserTest.php index 08b9e4b82..6573b2b66 100644 --- a/tests/phpunit/NotifUserTest.php +++ b/tests/phpunit/NotifUserTest.php @@ -3,6 +3,8 @@ use MediaWiki\Extension\Notifications\Gateway\UserNotificationGateway; use MediaWiki\Extension\Notifications\Mapper\NotificationMapper; use MediaWiki\Extension\Notifications\Mapper\TargetPageMapper; +use MediaWiki\Extension\Notifications\Model\Event; +use MediaWiki\Extension\Notifications\Model\Notification; use MediaWiki\MediaWikiServices; use MediaWiki\User\UserOptionsLookup; @@ -85,7 +87,7 @@ class MWEchoNotifUserTest extends MediaWikiIntegrationTestCase { User::newFromId( 2 ), $this->cache, $this->mockUserNotificationGateway( [ 'markRead' => true ] ), - $this->mockNotificationMapper( [ $this->mockEchoNotification() ] ), + $this->mockNotificationMapper( [ $this->mockNotification() ] ), $this->createMock( TargetPageMapper::class ), $this->createNoOpMock( UserOptionsLookup::class ), $this->getServiceContainer()->getUserFactory(), @@ -98,7 +100,7 @@ class MWEchoNotifUserTest extends MediaWikiIntegrationTestCase { User::newFromId( 2 ), $this->cache, $this->mockUserNotificationGateway( [ 'markRead' => false ] ), - $this->mockNotificationMapper( [ $this->mockEchoNotification() ] ), + $this->mockNotificationMapper( [ $this->mockNotification() ] ), $this->createMock( TargetPageMapper::class ), $this->createNoOpMock( UserOptionsLookup::class ), $this->getServiceContainer()->getUserFactory(), @@ -154,16 +156,16 @@ class MWEchoNotifUserTest extends MediaWikiIntegrationTestCase { return $mapper; } - protected function mockEchoNotification() { - $notification = $this->createMock( EchoNotification::class ); + protected function mockNotification() { + $notification = $this->createMock( Notification::class ); $notification->method( 'getEvent' ) - ->willReturn( $this->mockEchoEvent() ); + ->willReturn( $this->mockEvent() ); return $notification; } - protected function mockEchoEvent() { - $event = $this->createMock( EchoEvent::class ); + protected function mockEvent() { + $event = $this->createMock( Event::class ); $event->method( 'getId' ) ->willReturn( 1 ); diff --git a/tests/phpunit/NotificationsTest.php b/tests/phpunit/NotificationsTest.php index 170a7c464..b92da0552 100644 --- a/tests/phpunit/NotificationsTest.php +++ b/tests/phpunit/NotificationsTest.php @@ -1,6 +1,7 @@ db->select( 'echo_event', EchoEvent::selectFields(), [ + $res = $this->db->select( 'echo_event', Event::selectFields(), [ 'event_type' => 'edit-user-talk', ], __METHOD__, [ 'ORDER BY' => 'event_id ASC' ] ); diff --git a/tests/phpunit/ThankYouEditTest.php b/tests/phpunit/ThankYouEditTest.php index faeb25aac..aa224f3a6 100644 --- a/tests/phpunit/ThankYouEditTest.php +++ b/tests/phpunit/ThankYouEditTest.php @@ -37,7 +37,7 @@ class MWEchoThankYouEditTest extends MediaWikiIntegrationTestCase { $notifications = $notificationMapper->fetchByUser( $user, 10, null, [ 'thank-you-edit' ] ); $this->assertCount( 1, $notifications ); - /** @var EchoNotification $notification */ + /** @var Notification $notification */ $notification = reset( $notifications ); $this->assertSame( 1, $notification->getEvent()->getExtraParam( 'editCount', 'not found' ) ); } @@ -66,7 +66,7 @@ class MWEchoThankYouEditTest extends MediaWikiIntegrationTestCase { $notifications = $notificationMapper->fetchByUser( $user, 10, null, [ 'thank-you-edit' ] ); $this->assertCount( 2, $notifications ); - /** @var EchoNotification $notification */ + /** @var Notification $notification */ $notification = reset( $notifications ); $this->assertSame( 10, $notification->getEvent()->getExtraParam( 'editCount', 'not found' ) ); } diff --git a/tests/phpunit/UserLocatorTest.php b/tests/phpunit/UserLocatorTest.php index b72027c5b..4df6d7b85 100644 --- a/tests/phpunit/UserLocatorTest.php +++ b/tests/phpunit/UserLocatorTest.php @@ -1,5 +1,7 @@ insert( 'watchlist', $rows, __METHOD__ ); - $event = $this->createMock( EchoEvent::class ); + $event = $this->createMock( Event::class ); $event->method( 'getTitle' ) ->willReturn( $title ); @@ -73,7 +75,7 @@ class EchoUserLocatorTest extends MediaWikiIntegrationTestCase { if ( $expect instanceof Closure ) { [ $expect, $title ] = $expect(); } - $event = $this->createMock( EchoEvent::class ); + $event = $this->createMock( Event::class ); $event->method( 'getTitle' ) ->willReturn( $title ); @@ -110,7 +112,7 @@ class EchoUserLocatorTest extends MediaWikiIntegrationTestCase { /* $summary = */ 'summary' ); - $event = $this->createMock( EchoEvent::class ); + $event = $this->createMock( Event::class ); $event->method( 'getTitle' ) ->willReturn( $title ); $event->method( 'getAgent' ) @@ -152,7 +154,7 @@ class EchoUserLocatorTest extends MediaWikiIntegrationTestCase { * @dataProvider locateEventAgentProvider */ public function testLocateEventAgent( $message, $expect, User $agent = null ) { - $event = $this->createMock( EchoEvent::class ); + $event = $this->createMock( Event::class ); $event->method( 'getAgent' ) ->willReturn( $agent ); @@ -229,7 +231,7 @@ class EchoUserLocatorTest extends MediaWikiIntegrationTestCase { * @dataProvider locateFromEventExtraProvider */ public function testLocateFromEventExtra( $message, $expect, array $extra, array $keys ) { - $event = $this->createMock( EchoEvent::class ); + $event = $this->createMock( Event::class ); $event->method( 'getExtra' ) ->willReturn( $extra ); $event->method( 'getExtraParam' ) @@ -242,7 +244,7 @@ class EchoUserLocatorTest extends MediaWikiIntegrationTestCase { protected static function arrayToValueMap( array $array ) { $result = []; foreach ( $array as $key => $value ) { - // EchoEvent::getExtraParam second argument defaults to null + // Event::getExtraParam second argument defaults to null $result[] = [ $key, null, $value ]; } diff --git a/tests/phpunit/unit/BundlerTest.php b/tests/phpunit/unit/BundlerTest.php index f0773509a..5a6bba9dc 100644 --- a/tests/phpunit/unit/BundlerTest.php +++ b/tests/phpunit/unit/BundlerTest.php @@ -1,5 +1,7 @@ getMockBuilder( EchoNotification::class ) + $mock = $this->getMockBuilder( Notification::class ) ->disableOriginalConstructor() ->onlyMethods( [ 'getBundlingKey', diff --git a/tests/phpunit/unit/Mapper/TargetPageMapperTest.php b/tests/phpunit/unit/Mapper/TargetPageMapperTest.php index a4c10a6bf..8496f6c3a 100644 --- a/tests/phpunit/unit/Mapper/TargetPageMapperTest.php +++ b/tests/phpunit/unit/Mapper/TargetPageMapperTest.php @@ -1,6 +1,7 @@ mockEchoTargetPage(); + $target = $this->mockTargetPage(); $targetMapper = new TargetPageMapper( $this->mockMWEchoDbFactory( $dbResult ) ); $this->assertEquals( $result, $targetMapper->insert( $target ), $message ); } /** - * Mock object of EchoTargetPage - * @return EchoTargetPage + * Mock object of TargetPage + * @return TargetPage */ - protected function mockEchoTargetPage() { - $target = $this->createMock( EchoTargetPage::class ); + protected function mockTargetPage() { + $target = $this->createMock( TargetPage::class ); $target->method( 'toDbArray' ) ->willReturn( [] ); $target->method( 'getPageId' ) diff --git a/tests/phpunit/unit/model/TargetPageTest.php b/tests/phpunit/unit/Model/TargetPageTest.php similarity index 69% rename from tests/phpunit/unit/model/TargetPageTest.php rename to tests/phpunit/unit/Model/TargetPageTest.php index b6bfb604d..029bd7402 100644 --- a/tests/phpunit/unit/model/TargetPageTest.php +++ b/tests/phpunit/unit/Model/TargetPageTest.php @@ -1,21 +1,24 @@ assertNull( - EchoTargetPage::create( + TargetPage::create( $this->mockTitle( 0 ), $this->mockEchoEvent() ) ); $this->assertInstanceOf( - EchoTargetPage::class, - EchoTargetPage::create( + TargetPage::class, + TargetPage::create( $this->mockTitle( 1 ), $this->mockEchoEvent() ) @@ -23,15 +26,15 @@ class EchoTargetPageTest extends MediaWikiUnitTestCase { } /** - * @return EchoTargetPage + * @return TargetPage */ public function testNewFromRow() { $row = (object)[ 'etp_page' => 2, 'etp_event' => 3 ]; - $obj = EchoTargetPage::newFromRow( $row ); - $this->assertInstanceOf( EchoTargetPage::class, $obj ); + $obj = TargetPage::newFromRow( $row ); + $this->assertInstanceOf( TargetPage::class, $obj ); return $obj; } @@ -41,13 +44,13 @@ class EchoTargetPageTest extends MediaWikiUnitTestCase { 'etp_event' => 3 ]; $this->expectException( MWException::class ); - EchoTargetPage::newFromRow( $row ); + TargetPage::newFromRow( $row ); } /** * @depends testNewFromRow */ - public function testToDbArray( EchoTargetPage $obj ) { + public function testToDbArray( TargetPage $obj ) { $row = $obj->toDbArray(); $this->assertIsArray( $row ); @@ -73,10 +76,10 @@ class EchoTargetPageTest extends MediaWikiUnitTestCase { /** * @param int $eventId - * @return EchoEvent + * @return Event */ protected function mockEchoEvent( $eventId = 1 ) { - $event = $this->createMock( EchoEvent::class ); + $event = $this->createMock( Event::class ); $event->method( 'getId' ) ->willReturn( $eventId );