Skip to content

Commit ac103ee

Browse files
authored
Fix regression bug with notification type enqueuing as separate notification (#138)
* Fix regression bug with notification type enqueuing as separate notification #137 * Coding standards fix * Use identity operator when comparing
1 parent 2cecb29 commit ac103ee

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

modules/localgov_workflows_notifications/src/WorkflowNotification.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ public function enqueue(ContentEntityInterface $entity, string $type): void {
4242
continue;
4343
}
4444

45-
// Ensure the queue contains only one item for per service contact.
45+
// Aggregate notifications by service contact and type.
4646
$found = FALSE;
4747
$claimed_items = [];
4848
while ($queue_item = $queue->claimItem(1)) {
49-
if ($queue_item->data->service_contact == $contact->id()) {
49+
if ($queue_item->data->service_contact == $contact->id() && $queue_item->data->type === $type) {
5050

5151
// Delete old item and create new one with additional entity.
5252
$queue->deleteItem($queue_item);

modules/localgov_workflows_notifications/tests/src/Kernel/WorkflowNotificationTest.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public function testEnqueueNodes() {
166166
$this->notifier->enqueue($node5, 'published');
167167
$this->assertEquals(2, $this->queue->numberOfItems());
168168

169-
// Enqueue a notification with different type.
169+
// Ensure notifications are not duplicated.
170170
$node6 = $this->createNode([
171171
'type' => 'page',
172172
'title' => $this->randomMachineName(),
@@ -175,6 +175,17 @@ public function testEnqueueNodes() {
175175
],
176176
]);
177177
$this->notifier->enqueue($node6, 'published');
178+
$this->assertEquals(2, $this->queue->numberOfItems());
179+
180+
// Enqueue a notification with different type.
181+
$node7 = $this->createNode([
182+
'type' => 'page',
183+
'title' => $this->randomMachineName(),
184+
'localgov_service_contacts' => [
185+
['target_id' => $this->serviceContacts['enabled']->id()],
186+
],
187+
]);
188+
$this->notifier->enqueue($node7, 'unpublished');
178189
$this->assertEquals(3, $this->queue->numberOfItems());
179190
}
180191

0 commit comments

Comments
 (0)