diff --git a/src/Subscribers.php b/src/Subscribers.php index 7fbaa68fc706f91dec412304a74667828c9b1d30..a85623e3f9faaebf755486e5591fa7107d8e2996 100644 --- a/src/Subscribers.php +++ b/src/Subscribers.php @@ -177,9 +177,13 @@ class Subscribers implements SubscribersInterface { if ($subscribe_options['uids']) { // We got a list of user IDs directly from the implementing module, // However we need to adhere to the range. - $uids = $subscribe_options['range'] ? array_slice($subscribe_options['uids'], 0, $subscribe_options['range'], TRUE) : $subscribe_options['uids']; - } + $offset = 0; + if ($subscribe_options['last uid']) { + $offset = array_search($subscribe_options['last uid'], array_keys($subscribe_options['uids'])) + 1; + } + $uids = $subscribe_options['range'] ? array_slice($subscribe_options['uids'], $offset, $subscribe_options['range'], TRUE) : $subscribe_options['uids']; + } if (empty($uids) && !$uids = $this->getSubscribers($entity, $message, $subscribe_options, $context)) { // If we use a queue, it will be deleted. return; @@ -231,7 +235,15 @@ class Subscribers implements SubscribersInterface { } } - if ($use_queue) { + $last_key = key(array_slice($subscribe_options['uids'], -1, 1, TRUE)); + + // Last key could not be found which means there are no more queue items to + // create. + if ($last_key === NULL) { + return; + } + + if ($use_queue && isset($last_uid) && $last_key != $last_uid) { // Add item to the queue. $task = [ 'message' => $message,