Skip to content

Commit 3984b3f

Browse files
committed
Fix mapping
1 parent adde5c3 commit 3984b3f

File tree

26 files changed

+82
-82
lines changed

26 files changed

+82
-82
lines changed

src/Bounce/Service/SubscriberBlacklistService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function blacklist(Subscriber $subscriber, string $reason): void
4040
{
4141
$subscriber->setBlacklisted(true);
4242
$this->entityManager->flush();
43-
$this->blacklistManager->addEmailToBlacklist($subscriber->getEmail(), $reason);
43+
$userBlacklist = $this->blacklistManager->addEmailToBlacklist($subscriber->getEmail(), $reason);
4444
$this->entityManager->flush();
4545

4646
foreach (['REMOTE_ADDR','HTTP_X_FORWARDED_FOR'] as $item) {
@@ -50,7 +50,7 @@ public function blacklist(Subscriber $subscriber, string $reason): void
5050
}
5151
if ($request->server->get($item)) {
5252
$this->blacklistManager->addBlacklistData(
53-
email: $subscriber->getEmail(),
53+
userBlacklist: $userBlacklist,
5454
name: $item,
5555
data: $request->server->get($item)
5656
);

src/Core/Doctrine/OnlyOrmTablesFilter.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,22 @@ class OnlyOrmTablesFilter
1111
/** @var string[]|null */
1212
private ?array $allow = null;
1313

14-
public function __construct(private readonly EntityManagerInterface $em)
14+
public function __construct(private readonly EntityManagerInterface $entityManager)
1515
{
1616
}
1717

1818
public function __invoke(string $assetName): bool
1919
{
2020
// asset names can be "schema.table" ➜ normalize
21-
if (false !== ($pos = strrpos($assetName, '.'))) {
21+
$pos = strrpos($assetName, '.');
22+
if ($pos !== false) {
2223
$assetName = substr($assetName, $pos + 1);
2324
}
2425

2526
// Build the whitelist lazily to avoid touching the EM during container compilation or early boot.
2627
if ($this->allow === null) {
2728
$names = [];
28-
foreach ($this->em->getMetadataFactory()->getAllMetadata() as $m) {
29+
foreach ($this->entityManager->getMetadataFactory()->getAllMetadata() as $m) {
2930
// main table
3031
$table = $m->getTableName();
3132
if ($table) {

src/Domain/Analytics/Model/UserStats.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ class UserStats implements DomainModel, Identity
2929
#[ORM\Column(name: 'item', type: 'string', length: 255, nullable: true)]
3030
private ?string $item = null;
3131

32-
#[ORM\Column(name: 'listid', type: 'integer', options: ['default' => 0])]
32+
#[ORM\Column(name: 'listid', type: 'integer', nullable: true, options: ['default' => 0])]
3333
private int $listId = 0;
3434

35-
#[ORM\Column(name: 'value', type: 'integer', nullable: false)]
36-
private int $value;
35+
#[ORM\Column(name: 'value', type: 'integer', nullable: true, options: ['default' => 0])]
36+
private ?int $value = null;
3737

3838
public function getId(): ?int
3939
{

src/Domain/Configuration/Model/EventLog.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace PhpList\Core\Domain\Configuration\Model;
66

7+
use DateTimeImmutable;
78
use DateTimeInterface;
89
use Doctrine\ORM\Mapping as ORM;
910
use PhpList\Core\Domain\Common\Model\Interfaces\DomainModel;
@@ -14,6 +15,7 @@
1415
#[ORM\Table(name: 'phplist_eventlog')]
1516
#[ORM\Index(name: 'enteredidx', columns: ['entered'])]
1617
#[ORM\Index(name: 'pageidx', columns: ['page'])]
18+
#[ORM\HasLifecycleCallbacks]
1719
class EventLog implements DomainModel, Identity
1820
{
1921
#[ORM\Id]
@@ -35,6 +37,13 @@ public function getId(): ?int
3537
return $this->id;
3638
}
3739

40+
#[ORM\PrePersist]
41+
public function setCreatedTimestamps(): void
42+
{
43+
$now = new DateTimeImmutable();
44+
$this->entered = $now;
45+
}
46+
3847
public function getEntered(): ?DateTimeInterface
3948
{
4049
return $this->entered;

src/Domain/Configuration/Model/UrlCache.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#[ORM\Entity(repositoryClass: UrlCacheRepository::class)]
1414
#[ORM\Table(name: 'phplist_urlcache')]
1515
#[ORM\Index(name: 'urlindex', columns: ['url'])]
16+
#[ORM\HasLifecycleCallbacks]
1617
class UrlCache implements DomainModel, Identity
1718
{
1819
#[ORM\Id]
@@ -71,10 +72,11 @@ public function setLastModified(?int $lastModified): self
7172
return $this;
7273
}
7374

74-
public function setAdded(?DateTime $added): self
75+
#[ORM\PrePersist]
76+
public function setCreatedTimestamps(): void
7577
{
76-
$this->added = $added;
77-
return $this;
78+
$now = new DateTime();
79+
$this->added = $now;
7880
}
7981

8082
public function setContent(?string $content): self

src/Domain/Identity/Model/AdminPasswordRequest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
#[ORM\Entity(repositoryClass: AdminPasswordRequestRepository::class)]
1414
#[ORM\Table(name: 'phplist_admin_password_request')]
15-
#[ORM\HasLifecycleCallbacks]
1615
class AdminPasswordRequest implements DomainModel, Identity
1716
{
1817
#[ORM\Id]

src/Domain/Identity/Model/Administrator.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@
2222
* @author Tatevik Grigoryan <[email protected]>
2323
*/
2424
#[ORM\Entity(repositoryClass: AdministratorRepository::class)]
25-
#[ORM\Table(
26-
name: 'phplist_admin',
27-
uniqueConstraints: [new ORM\UniqueConstraint(name: 'loginnameidx', columns: ['loginname'])]
28-
)]
25+
#[ORM\Table(name: 'phplist_admin')]
26+
#[ORM\UniqueConstraint(name: 'loginnameidx', columns: ['loginname'])]
2927
#[ORM\HasLifecycleCallbacks]
3028
class Administrator implements DomainModel, Identity, CreationDate, ModificationDate
3129
{
@@ -71,7 +69,6 @@ public function __construct()
7169
{
7270
$this->createdAt = new DateTime();
7371
$this->updatedAt = new DateTime();
74-
$this->loginName = '';
7572
$this->email = '';
7673
}
7774

@@ -170,6 +167,8 @@ public function setPrivileges(Privileges $privileges): self
170167

171168
/**
172169
* @throws InvalidArgumentException
170+
*
171+
* @SuppressWarnings(PHPMD.StaticAccess)
173172
*/
174173
public function setPrivilegesFromArray(array $privilegesData): void
175174
{
@@ -184,6 +183,7 @@ public function setPrivilegesFromArray(array $privilegesData): void
184183
$this->setPrivileges($privileges);
185184
}
186185

186+
/** @SuppressWarnings(PHPMD.StaticAccess) */
187187
public function getPrivileges(): Privileges
188188
{
189189
return Privileges::fromSerialized($this->privileges);

src/Domain/Messaging/Model/ListMessage.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ class ListMessage implements DomainModel, Identity, ModificationDate
3939
#[ORM\Column(name: 'modified', type: 'datetime')]
4040
private ?DateTime $updatedAt = null;
4141

42+
public function __construct()
43+
{
44+
$this->updatedAt = new DateTime();
45+
$this->entered = new DateTime();
46+
}
47+
4248
public function getId(): ?int
4349
{
4450
return $this->id;
@@ -71,23 +77,14 @@ public function getEntered(): ?DateTimeInterface
7177
return $this->entered;
7278
}
7379

74-
public function setEntered(?DateTimeInterface $entered): self
75-
{
76-
$this->entered = $entered;
77-
return $this;
78-
}
79-
8080
public function getUpdatedAt(): ?DateTime
8181
{
8282
return $this->updatedAt;
8383
}
8484

85-
#[ORM\PrePersist]
8685
#[ORM\PreUpdate]
87-
public function updateUpdatedAt(): DomainModel
86+
public function updateUpdatedAt(): void
8887
{
8988
$this->updatedAt = new DateTime();
90-
91-
return $this;
9289
}
9390
}

src/Domain/Messaging/Model/Message.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace PhpList\Core\Domain\Messaging\Model;
66

77
use DateTime;
8+
use DateTimeImmutable;
89
use Doctrine\Common\Collections\ArrayCollection;
910
use Doctrine\Common\Collections\Collection;
1011
use Doctrine\ORM\Mapping as ORM;
@@ -31,8 +32,8 @@ class Message implements DomainModel, Identity, ModificationDate, OwnableInterfa
3132
#[ORM\GeneratedValue]
3233
private ?int $id = null;
3334

34-
#[ORM\Column(name: 'modified', type: 'datetime')]
35-
private ?DateTime $updatedAt = null;
35+
#[ORM\Column(name: 'modified', type: 'datetime_immutable', nullable: false)]
36+
private ?DateTimeImmutable $updatedAt = null;
3637

3738
#[ORM\Embedded(class: MessageFormat::class, columnPrefix: false)]
3839
private MessageFormat $format;
@@ -88,18 +89,27 @@ public function getId(): ?int
8889
return $this->id;
8990
}
9091

92+
/** @SuppressWarnings(PHPMD.StaticAccess) */
9193
public function getUpdatedAt(): ?DateTime
9294
{
93-
return $this->updatedAt;
95+
if (null === $this->updatedAt) {
96+
return null;
97+
}
98+
99+
return DateTime::createFromImmutable($this->updatedAt);
94100
}
95101

96102
#[ORM\PrePersist]
97-
#[ORM\PreUpdate]
98-
public function updateUpdatedAt(): DomainModel
103+
public function setCreatedTimestamps(): void
99104
{
100-
$this->updatedAt = new DateTime();
105+
$this->metadata->setEntered(new DateTime());
106+
}
101107

102-
return $this;
108+
#[ORM\PrePersist]
109+
#[ORM\PreUpdate]
110+
public function touchUpdatedTimestamp(): void
111+
{
112+
$this->updatedAt = new DateTimeImmutable();
103113
}
104114

105115
public function getFormat(): MessageFormat

src/Domain/Messaging/Model/SendProcess.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,9 @@ public function getUpdatedAt(): ?DateTime
4848

4949
#[ORM\PrePersist]
5050
#[ORM\PreUpdate]
51-
public function updateUpdatedAt(): DomainModel
51+
public function updateUpdatedAt(): void
5252
{
5353
$this->updatedAt = new DateTime();
54-
55-
return $this;
5654
}
5755

5856
public function getStartedDate(): ?DateTime

0 commit comments

Comments
 (0)