Skip to content

Commit 9d0c1db

Browse files
TatevikGrtatevikg1
andauthored
Bounceregex manager (#354)
* BounceRegexManager * Fix manager directory * Prop name update admin -> adminId --------- Co-authored-by: Tatevik <tatevikg1@gmail.com>
1 parent f80edc8 commit 9d0c1db

File tree

13 files changed

+295
-37
lines changed

13 files changed

+295
-37
lines changed

config/services/managers.yml

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,74 +4,78 @@ services:
44
autoconfigure: true
55
public: false
66

7-
PhpList\Core\Domain\Subscription\Service\Manager\SubscriberManager:
7+
PhpList\Core\Domain\Identity\Service\SessionManager:
88
autowire: true
99
autoconfigure: true
1010

11-
PhpList\Core\Domain\Identity\Service\SessionManager:
11+
PhpList\Core\Domain\Identity\Service\AdministratorManager:
1212
autowire: true
1313
autoconfigure: true
1414

15-
PhpList\Core\Domain\Subscription\Service\Manager\SubscriberListManager:
15+
PhpList\Core\Domain\Identity\Service\AdminAttributeDefinitionManager:
1616
autowire: true
1717
autoconfigure: true
1818

19-
PhpList\Core\Domain\Subscription\Service\Manager\SubscriptionManager:
19+
PhpList\Core\Domain\Identity\Service\AdminAttributeManager:
2020
autowire: true
2121
autoconfigure: true
2222

23-
PhpList\Core\Domain\Messaging\Service\MessageManager:
23+
PhpList\Core\Domain\Identity\Service\PasswordManager:
2424
autowire: true
2525
autoconfigure: true
2626

27-
PhpList\Core\Domain\Messaging\Service\TemplateManager:
27+
PhpList\Core\Domain\Subscription\Service\Manager\SubscriberManager:
2828
autowire: true
2929
autoconfigure: true
3030

31-
PhpList\Core\Domain\Messaging\Service\TemplateImageManager:
31+
PhpList\Core\Domain\Subscription\Service\Manager\SubscriberListManager:
3232
autowire: true
3333
autoconfigure: true
3434

35-
PhpList\Core\Domain\Identity\Service\AdministratorManager:
35+
PhpList\Core\Domain\Subscription\Service\Manager\SubscriptionManager:
3636
autowire: true
3737
autoconfigure: true
3838

39-
PhpList\Core\Domain\Identity\Service\AdminAttributeDefinitionManager:
39+
PhpList\Core\Domain\Subscription\Service\Manager\AttributeDefinitionManager:
4040
autowire: true
4141
autoconfigure: true
4242

43-
PhpList\Core\Domain\Identity\Service\AdminAttributeManager:
43+
PhpList\Core\Domain\Subscription\Service\Manager\SubscriberHistoryManager:
4444
autowire: true
4545
autoconfigure: true
4646

47-
PhpList\Core\Domain\Subscription\Service\Manager\AttributeDefinitionManager:
47+
PhpList\Core\Domain\Subscription\Service\Manager\SubscriberAttributeManager:
4848
autowire: true
4949
autoconfigure: true
5050

51-
PhpList\Core\Domain\Subscription\Service\Manager\SubscriberHistoryManager:
51+
PhpList\Core\Domain\Subscription\Service\Manager\SubscriberBlacklistManager:
5252
autowire: true
5353
autoconfigure: true
5454

55-
PhpList\Core\Domain\Subscription\Service\Manager\SubscriberAttributeManager:
55+
PhpList\Core\Domain\Subscription\Service\Manager\SubscribePageManager:
5656
autowire: true
5757
autoconfigure: true
5858

59-
PhpList\Core\Domain\Configuration\Service\Manager\ConfigManager:
59+
PhpList\Core\Domain\Messaging\Service\Manager\MessageManager:
6060
autowire: true
6161
autoconfigure: true
6262

63-
PhpList\Core\Domain\Identity\Service\PasswordManager:
63+
PhpList\Core\Domain\Messaging\Service\Manager\TemplateManager:
6464
autowire: true
6565
autoconfigure: true
6666

67-
PhpList\Core\Domain\Messaging\Service\Manager\ListMessageManager:
67+
PhpList\Core\Domain\Messaging\Service\Manager\TemplateImageManager:
6868
autowire: true
6969
autoconfigure: true
7070

71-
PhpList\Core\Domain\Subscription\Service\Manager\SubscriberBlacklistManager:
71+
PhpList\Core\Domain\Messaging\Service\Manager\BounceRegexManager:
7272
autowire: true
7373
autoconfigure: true
7474

75-
PhpList\Core\Domain\Subscription\Service\Manager\SubscribePageManager:
75+
PhpList\Core\Domain\Messaging\Service\Manager\ListMessageManager:
76+
autowire: true
77+
autoconfigure: true
78+
79+
PhpList\Core\Domain\Configuration\Service\Manager\ConfigManager:
7680
autowire: true
7781
autoconfigure: true

config/services/repositories.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,8 @@ services:
130130
parent: PhpList\Core\Domain\Common\Repository\AbstractRepository
131131
arguments:
132132
- PhpList\Core\Domain\Subscription\Model\SubscribePageData
133+
134+
PhpList\Core\Domain\Messaging\Repository\BounceRegexRepository:
135+
parent: PhpList\Core\Domain\Common\Repository\AbstractRepository
136+
arguments:
137+
- PhpList\Core\Domain\Messaging\Model\BounceRegex

src/Domain/Messaging/Model/BounceRegex.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class BounceRegex implements DomainModel, Identity
3131
#[ORM\Column(name: 'listorder', type: 'integer', nullable: true, options: ['default' => 0])]
3232
private ?int $listOrder = 0;
3333

34-
#[ORM\Column(type: 'integer', nullable: true)]
35-
private ?int $admin;
34+
#[ORM\Column(name: 'admin', type: 'integer', nullable: true)]
35+
private ?int $adminId;
3636

3737
#[ORM\Column(type: 'text', nullable: true)]
3838
private ?string $comment;
@@ -48,7 +48,7 @@ public function __construct(
4848
?string $regexHash = null,
4949
?string $action = null,
5050
?int $listOrder = 0,
51-
?int $admin = null,
51+
?int $adminId = null,
5252
?string $comment = null,
5353
?string $status = null,
5454
?int $count = 0
@@ -57,7 +57,7 @@ public function __construct(
5757
$this->regexHash = $regexHash;
5858
$this->action = $action;
5959
$this->listOrder = $listOrder;
60-
$this->admin = $admin;
60+
$this->adminId = $adminId;
6161
$this->comment = $comment;
6262
$this->status = $status;
6363
$this->count = $count;
@@ -112,14 +112,14 @@ public function setListOrder(?int $listOrder): self
112112
return $this;
113113
}
114114

115-
public function getAdmin(): ?int
115+
public function getAdminId(): ?int
116116
{
117-
return $this->admin;
117+
return $this->adminId;
118118
}
119119

120-
public function setAdmin(?int $admin): self
120+
public function setAdminId(?int $adminId): self
121121
{
122-
$this->admin = $admin;
122+
$this->adminId = $adminId;
123123
return $this;
124124
}
125125

src/Domain/Messaging/Repository/BounceRegexRepository.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@
77
use PhpList\Core\Domain\Common\Repository\AbstractRepository;
88
use PhpList\Core\Domain\Common\Repository\CursorPaginationTrait;
99
use PhpList\Core\Domain\Common\Repository\Interfaces\PaginatableRepositoryInterface;
10+
use PhpList\Core\Domain\Messaging\Model\BounceRegex;
1011

1112
class BounceRegexRepository extends AbstractRepository implements PaginatableRepositoryInterface
1213
{
1314
use CursorPaginationTrait;
15+
16+
public function findOneByRegexHash(string $regexHash): ?BounceRegex
17+
{
18+
return $this->findOneBy(['regexHash' => $regexHash]);
19+
}
1420
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpList\Core\Domain\Messaging\Service\Manager;
6+
7+
use Doctrine\ORM\EntityManagerInterface;
8+
use PhpList\Core\Domain\Messaging\Model\Bounce;
9+
use PhpList\Core\Domain\Messaging\Model\BounceRegex;
10+
use PhpList\Core\Domain\Messaging\Model\BounceRegexBounce;
11+
use PhpList\Core\Domain\Messaging\Repository\BounceRegexRepository;
12+
13+
class BounceRegexManager
14+
{
15+
private BounceRegexRepository $bounceRegexRepository;
16+
private EntityManagerInterface $entityManager;
17+
18+
public function __construct(
19+
BounceRegexRepository $bounceRegexRepository,
20+
EntityManagerInterface $entityManager
21+
) {
22+
$this->bounceRegexRepository = $bounceRegexRepository;
23+
$this->entityManager = $entityManager;
24+
}
25+
26+
/**
27+
* Creates or updates (if exists) a BounceRegex from a raw regex pattern.
28+
*/
29+
public function createOrUpdateFromPattern(
30+
string $regex,
31+
?string $action = null,
32+
?int $listOrder = 0,
33+
?int $adminId = null,
34+
?string $comment = null,
35+
?string $status = null
36+
): BounceRegex {
37+
$regexHash = md5($regex);
38+
39+
$existing = $this->bounceRegexRepository->findOneByRegexHash($regexHash);
40+
41+
if ($existing !== null) {
42+
$existing->setRegex($regex)
43+
->setAction($action ?? $existing->getAction())
44+
->setListOrder($listOrder ?? $existing->getListOrder())
45+
->setAdminId($adminId ?? $existing->getAdminId())
46+
->setComment($comment ?? $existing->getComment())
47+
->setStatus($status ?? $existing->getStatus());
48+
49+
$this->bounceRegexRepository->save($existing);
50+
51+
return $existing;
52+
}
53+
54+
$bounceRegex = new BounceRegex(
55+
regex: $regex,
56+
regexHash: $regexHash,
57+
action: $action,
58+
listOrder: $listOrder,
59+
adminId: $adminId,
60+
comment: $comment,
61+
status: $status,
62+
count: 0
63+
);
64+
65+
$this->bounceRegexRepository->save($bounceRegex);
66+
67+
return $bounceRegex;
68+
}
69+
70+
/** @return BounceRegex[] */
71+
public function getAll(): array
72+
{
73+
return $this->bounceRegexRepository->findAll();
74+
}
75+
76+
public function getByHash(string $regexHash): ?BounceRegex
77+
{
78+
return $this->bounceRegexRepository->findOneByRegexHash($regexHash);
79+
}
80+
81+
public function delete(BounceRegex $bounceRegex): void
82+
{
83+
$this->bounceRegexRepository->remove($bounceRegex);
84+
}
85+
86+
/**
87+
* Associates a bounce with the regex it matched and increments usage count.
88+
*/
89+
public function associateBounce(BounceRegex $regex, Bounce $bounce): BounceRegexBounce
90+
{
91+
$relation = new BounceRegexBounce($regex->getId() ?? 0, $bounce->getId() ?? 0);
92+
$this->entityManager->persist($relation);
93+
94+
$regex->setCount(($regex->getCount() ?? 0) + 1);
95+
$this->entityManager->flush();
96+
97+
return $relation;
98+
}
99+
}

src/Domain/Messaging/Service/MessageManager.php renamed to src/Domain/Messaging/Service/Manager/MessageManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace PhpList\Core\Domain\Messaging\Service;
5+
namespace PhpList\Core\Domain\Messaging\Service\Manager;
66

77
use PhpList\Core\Domain\Identity\Model\Administrator;
88
use PhpList\Core\Domain\Messaging\Model\Dto\MessageContext;

src/Domain/Messaging/Service/TemplateImageManager.php renamed to src/Domain/Messaging/Service/Manager/TemplateImageManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace PhpList\Core\Domain\Messaging\Service;
5+
namespace PhpList\Core\Domain\Messaging\Service\Manager;
66

77
use Doctrine\ORM\EntityManagerInterface;
88
use DOMDocument;

src/Domain/Messaging/Service/TemplateManager.php renamed to src/Domain/Messaging/Service/Manager/TemplateManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace PhpList\Core\Domain\Messaging\Service;
5+
namespace PhpList\Core\Domain\Messaging\Service\Manager;
66

77
use Doctrine\ORM\EntityManagerInterface;
88
use PhpList\Core\Domain\Common\Model\ValidationContext;

0 commit comments

Comments
 (0)