File tree Expand file tree Collapse file tree 3 files changed +52
-24
lines changed
app/code/Magento/Newsletter/Model Expand file tree Collapse file tree 3 files changed +52
-24
lines changed Original file line number Diff line number Diff line change 7
7
8
8
namespace Magento \Newsletter \Model \Plugin ;
9
9
10
- use Magento \Newsletter \Model \ResourceModel \ Queue as QueueResource ;
10
+ use Magento \Newsletter \Model \RemoveSubscriberFromQueueLink ;
11
11
use Magento \Newsletter \Model \Subscriber ;
12
12
13
13
/**
14
- * Plugin responsible for removing subscriber from queue after unsubscribe
14
+ * Plugin for removing subscriber from queue after unsubscribe
15
15
*/
16
16
class RemoveSubscriberFromQueue
17
17
{
18
- private const STATUS = 'subscriber_status ' ;
19
-
20
18
/**
21
- * @var QueueResource
19
+ * @var RemoveSubscriberFromQueueLink
22
20
*/
23
- private $ queueResource ;
21
+ private $ removeSubscriberFromQueue ;
24
22
25
23
/**
26
- * @param QueueResource $queueResource
24
+ * @param RemoveSubscriberFromQueueLink $removeSubscriberFromQueue
27
25
*/
28
- public function __construct (QueueResource $ queueResource )
26
+ public function __construct (RemoveSubscriberFromQueueLink $ removeSubscriberFromQueue )
29
27
{
30
- $ this ->queueResource = $ queueResource ;
28
+ $ this ->removeSubscriberFromQueue = $ removeSubscriberFromQueue ;
31
29
}
32
30
33
31
/**
@@ -41,7 +39,7 @@ public function __construct(QueueResource $queueResource)
41
39
public function afterUnsubscribe (Subscriber $ subject , Subscriber $ subscriber ): Subscriber
42
40
{
43
41
if ($ subscriber ->isStatusChanged () && $ subscriber ->getSubscriberStatus () === Subscriber::STATUS_UNSUBSCRIBED ) {
44
- $ this ->queueResource -> removeSubscriberFromQueue ((int ) $ subscriber ->getId ());
42
+ $ this ->removeSubscriberFromQueue -> execute ((int ) $ subscriber ->getId ());
45
43
}
46
44
47
45
return $ subscriber ;
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -125,20 +125,6 @@ public function removeSubscribersFromQueue(ModelQueue $queue)
125
125
}
126
126
}
127
127
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
-
142
128
/**
143
129
* Links queue to store
144
130
*
You can’t perform that action at this time.
0 commit comments