Skip to content

Commit ec464f5

Browse files
moved removing subscriber queue to separate class
1 parent d98dc43 commit ec464f5

File tree

3 files changed

+52
-24
lines changed

3 files changed

+52
-24
lines changed

app/code/Magento/Newsletter/Model/Plugin/RemoveSubscriberFromQueue.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,25 @@
77

88
namespace Magento\Newsletter\Model\Plugin;
99

10-
use Magento\Newsletter\Model\ResourceModel\Queue as QueueResource;
10+
use Magento\Newsletter\Model\RemoveSubscriberFromQueueLink;
1111
use Magento\Newsletter\Model\Subscriber;
1212

1313
/**
14-
* Plugin responsible for removing subscriber from queue after unsubscribe
14+
* Plugin for removing subscriber from queue after unsubscribe
1515
*/
1616
class RemoveSubscriberFromQueue
1717
{
18-
private const STATUS = 'subscriber_status';
19-
2018
/**
21-
* @var QueueResource
19+
* @var RemoveSubscriberFromQueueLink
2220
*/
23-
private $queueResource;
21+
private $removeSubscriberFromQueue;
2422

2523
/**
26-
* @param QueueResource $queueResource
24+
* @param RemoveSubscriberFromQueueLink $removeSubscriberFromQueue
2725
*/
28-
public function __construct(QueueResource $queueResource)
26+
public function __construct(RemoveSubscriberFromQueueLink $removeSubscriberFromQueue)
2927
{
30-
$this->queueResource = $queueResource;
28+
$this->removeSubscriberFromQueue = $removeSubscriberFromQueue;
3129
}
3230

3331
/**
@@ -41,7 +39,7 @@ public function __construct(QueueResource $queueResource)
4139
public function afterUnsubscribe(Subscriber $subject, Subscriber $subscriber): Subscriber
4240
{
4341
if ($subscriber->isStatusChanged() && $subscriber->getSubscriberStatus() === Subscriber::STATUS_UNSUBSCRIBED) {
44-
$this->queueResource->removeSubscriberFromQueue((int) $subscriber->getId());
42+
$this->removeSubscriberFromQueue->execute((int) $subscriber->getId());
4543
}
4644

4745
return $subscriber;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Newsletter\Model;
9+
10+
use Magento\Framework\App\ResourceConnection;
11+
use Magento\Framework\DB\Adapter\AdapterInterface;
12+
13+
/**
14+
* Responsible for removing subscriber from queue
15+
*/
16+
class RemoveSubscriberFromQueueLink
17+
{
18+
/**
19+
* @var AdapterInterface
20+
*/
21+
private $connection;
22+
23+
/**
24+
* @param ResourceConnection $resource
25+
*/
26+
public function __construct(ResourceConnection $resource)
27+
{
28+
$this->connection = $resource->getConnection();
29+
}
30+
31+
/**
32+
* Removes subscriber from queue
33+
*
34+
* @param int $subscriberId
35+
* @return void
36+
*/
37+
public function execute(int $subscriberId): void
38+
{
39+
$this->connection->delete(
40+
$this->connection->getTableName('newsletter_queue_link'),
41+
['subscriber_id = ?' => $subscriberId, 'letter_sent_at IS NULL']
42+
);
43+
}
44+
}

app/code/Magento/Newsletter/Model/ResourceModel/Queue.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -125,20 +125,6 @@ public function removeSubscribersFromQueue(ModelQueue $queue)
125125
}
126126
}
127127

128-
/**
129-
* Removes subscriber from queue
130-
*
131-
* @param int $subscriberId
132-
* @return void
133-
*/
134-
public function removeSubscriberFromQueue(int $subscriberId): void
135-
{
136-
$this->getConnection()->delete(
137-
$this->getTable('newsletter_queue_link'),
138-
['subscriber_id = ?' => $subscriberId, 'letter_sent_at IS NULL']
139-
);
140-
}
141-
142128
/**
143129
* Links queue to store
144130
*

0 commit comments

Comments
 (0)