diff --git a/extension.json b/extension.json index 520982fb1..546c3070d 100644 --- a/extension.json +++ b/extension.json @@ -1077,7 +1077,8 @@ "EchoArrayList": "includes/EchoArrayList.php", "EchoAttributeManager": "includes/AttributeManager.php", "EchoCachedList": "includes/EchoCachedList.php", - "EchoCallbackIterator": "includes/iterator/CallbackIterator.php", + "EchoCallbackIterator": "includes/Iterator/CallbackIterator.php", + "MediaWiki\\Extension\\Notifications\\Iterator\\CallbackIterator": "includes/Iterator/CallbackIterator.php", "EchoContainmentList": "includes/EchoContainmentList.php", "EchoContainmentSet": "includes/EchoContainmentSet.php", "EchoDataOutputFormatter": "includes/DataOutputFormatter.php", @@ -1093,15 +1094,12 @@ "EchoEventMapper": "includes/mapper/EventMapper.php", "EchoEventPresentationModel": "includes/Formatters/EchoEventPresentationModel.php", "MediaWiki\\Extension\\Notifications\\Formatters\\EchoEventPresentationModel": "includes/Formatters/EchoEventPresentationModel.php", - "EchoFilteredSequentialIterator": "includes/iterator/FilteredSequentialIterator.php", "EchoForeignNotifications": "includes/ForeignNotifications.php", "EchoForeignWikiRequest": "includes/ForeignWikiRequest.php", "EchoMentionPresentationModel": "includes/Formatters/EchoMentionPresentationModel.php", "MediaWiki\\Extension\\Notifications\\Formatters\\EchoMentionPresentationModel": "includes/Formatters/EchoMentionPresentationModel.php", "EchoMentionStatusPresentationModel": "includes/Formatters/EchoMentionStatusPresentationModel.php", "MediaWiki\\Extension\\Notifications\\Formatters\\EchoMentionStatusPresentationModel": "includes/Formatters/EchoMentionStatusPresentationModel.php", - "EchoMultipleIterator": "includes/iterator/MultipleIterator.php", - "EchoNotRecursiveIterator": "includes/iterator/NotRecursiveIterator.php", "EchoNotification": "includes/model/Notification.php", "EchoNotificationMapper": "includes/mapper/NotificationMapper.php", "EchoNotifier": "includes/Notifier.php", diff --git a/includes/Controller/NotificationController.php b/includes/Controller/NotificationController.php index 282a5c839..02f2db4c8 100644 --- a/includes/Controller/NotificationController.php +++ b/includes/Controller/NotificationController.php @@ -8,13 +8,13 @@ use EchoCachedList; use EchoContainmentList; use EchoContainmentSet; use EchoEvent; -use EchoFilteredSequentialIterator; use EchoOnWikiList; use EchoServices; use Hooks; use Iterator; use MapCacheLRU; 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\Logger\LoggerFactory; @@ -481,7 +481,7 @@ class NotificationController { * @return Iterator values are User objects */ public static function getUsersToNotifyForEvent( EchoEvent $event ) { - $notify = new EchoFilteredSequentialIterator; + $notify = new FilteredSequentialIterator; foreach ( self::evaluateUserCallable( $event, EchoAttributeManager::ATTR_LOCATORS ) as $users ) { $notify->add( $users ); } diff --git a/includes/iterator/CallbackIterator.php b/includes/Iterator/CallbackIterator.php similarity index 63% rename from includes/iterator/CallbackIterator.php rename to includes/Iterator/CallbackIterator.php index fe47e0ffb..af90d97cb 100644 --- a/includes/iterator/CallbackIterator.php +++ b/includes/Iterator/CallbackIterator.php @@ -1,9 +1,14 @@ callable, $this->iterator->current() ); } } + +class_alias( CallbackIterator::class, 'EchoCallbackIterator' ); diff --git a/includes/iterator/FilteredSequentialIterator.php b/includes/Iterator/FilteredSequentialIterator.php similarity index 82% rename from includes/iterator/FilteredSequentialIterator.php rename to includes/Iterator/FilteredSequentialIterator.php index 67c67c25e..a0135378e 100644 --- a/includes/iterator/FilteredSequentialIterator.php +++ b/includes/Iterator/FilteredSequentialIterator.php @@ -1,5 +1,15 @@ add( array( $userA, $userB, $userC ) ); * * $it = new BatchRowIterator( ... ); * ... * $it = new RecursiveIteratorIterator( $it ); - * $users->add( new EchoCallbackIterator( $it, function( $row ) { + * $users->add( new CallbackIterator( $it, function( $row ) { * ... * return $user; * } ) ); @@ -27,12 +37,12 @@ * * By default the BatchRowIterator returns an array of rows, this class * expects a stream of user objects. To bridge that gap the - * RecursiveIteratorIterator is used to flatten and the EchoCallbackIterator + * RecursiveIteratorIterator is used to flatten and the CallbackIterator * is used to transform each database $row into a User object. * * @todo name? */ -class EchoFilteredSequentialIterator implements IteratorAggregate { +class FilteredSequentialIterator implements IteratorAggregate { /** * @var Iterator[] */ @@ -96,7 +106,7 @@ class EchoFilteredSequentialIterator implements IteratorAggregate { return reset( $this->iterators ); default: - return new RecursiveIteratorIterator( new EchoMultipleIterator( $this->iterators ) ); + return new RecursiveIteratorIterator( new MultipleIterator( $this->iterators ) ); } } diff --git a/includes/iterator/MultipleIterator.php b/includes/Iterator/MultipleIterator.php similarity index 83% rename from includes/iterator/MultipleIterator.php rename to includes/Iterator/MultipleIterator.php index 2c77a7956..252244d9f 100644 --- a/includes/iterator/MultipleIterator.php +++ b/includes/Iterator/MultipleIterator.php @@ -1,5 +1,11 @@ current() ) ); + // so that nested arrays don't get recursed. + return new NotRecursiveIterator( new ArrayIterator( $this->current() ) ); } } diff --git a/includes/iterator/NotRecursiveIterator.php b/includes/Iterator/NotRecursiveIterator.php similarity index 69% rename from includes/iterator/NotRecursiveIterator.php rename to includes/Iterator/NotRecursiveIterator.php index 4c0ee84a1..a6a6f86de 100644 --- a/includes/iterator/NotRecursiveIterator.php +++ b/includes/Iterator/NotRecursiveIterator.php @@ -1,5 +1,10 @@ wl_user ); } ); diff --git a/tests/phpunit/unit/iterator/FilteredSequentialIteratorTest.php b/tests/phpunit/unit/Iterator/FilteredSequentialIteratorTest.php similarity index 78% rename from tests/phpunit/unit/iterator/FilteredSequentialIteratorTest.php rename to tests/phpunit/unit/Iterator/FilteredSequentialIteratorTest.php index 9819ebe09..f6c8a1cab 100644 --- a/tests/phpunit/unit/iterator/FilteredSequentialIteratorTest.php +++ b/tests/phpunit/unit/Iterator/FilteredSequentialIteratorTest.php @@ -1,13 +1,16 @@ assertEquals( $expected, $res, 'Basic iteration with callback applied' ); } - public static function echoFilteredSequentialIteratorProvider() { + public static function filteredSequentialIteratorProvider() { $odd = static function ( $v ) { return $v & 1; }; @@ -89,10 +92,10 @@ class FilteredSequentialIteratorTest extends MediaWikiUnitTestCase { } /** - * @dataProvider echoFilteredSequentialIteratorProvider + * @dataProvider filteredSequentialIteratorProvider */ - public function testEchoFilteredSequentialIterator( $message, $expect, $userLists, $filters ) { - $notify = new EchoFilteredSequentialIterator; + public function testFilteredSequentialIterator( $message, $expect, $userLists, $filters ) { + $notify = new FilteredSequentialIterator; foreach ( $userLists as $userList ) { $notify->add( $userList );