Skip to content

Commit 60a5d08

Browse files
committed
Fix mapping
1 parent adde5c3 commit 60a5d08

34 files changed

+116
-122
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/LinkTrack.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

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

7+
use DateTime;
78
use DateTimeInterface;
89
use Doctrine\ORM\Mapping as ORM;
910
use PhpList\Core\Domain\Analytics\Repository\LinkTrackRepository;
@@ -39,12 +40,17 @@ class LinkTrack implements DomainModel, Identity
3940
#[ORM\Column(name: 'firstclick', type: 'datetime', nullable: true)]
4041
private ?DateTimeInterface $firstClick = null;
4142

42-
#[ORM\Column(name: 'latestclick', type: 'datetime', nullable: true, options: ['default' => 'CURRENT_TIMESTAMP'])]
43+
#[ORM\Column(name: 'latestclick', type: 'datetime')]
4344
private ?DateTimeInterface $latestClick = null;
4445

4546
#[ORM\Column(type: 'integer', nullable: true, options: ['default' => 0])]
4647
private int $clicked = 0;
4748

49+
public function __construct()
50+
{
51+
$this->latestClick = new DateTime();
52+
}
53+
4854
public function getId(): int
4955
{
5056
return $this->id;

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/AdminLogin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class AdminLogin implements DomainModel, Identity
3737
#[ORM\Column(name: 'sessionid', type: 'string', length: 50)]
3838
private string $sessionId;
3939

40-
#[ORM\Column(name: 'active', type: 'boolean')]
40+
#[ORM\Column(name: 'active', type: 'boolean', nullable: false)]
4141
private bool $active = false;
4242

4343
public function __construct(

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: 8 additions & 17 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
{
@@ -35,7 +33,7 @@ class Administrator implements DomainModel, Identity, CreationDate, Modification
3533
private ?int $id = null;
3634

3735
#[ORM\Column(name: 'created', type: 'datetime', nullable: true)]
38-
protected ?DateTime $createdAt = null;
36+
protected DateTime $createdAt;
3937

4038
#[ORM\Column(name: 'modified', type: 'datetime', nullable: false)]
4139
private DateTime $updatedAt;
@@ -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

@@ -80,7 +77,7 @@ public function getId(): ?int
8077
return $this->id;
8178
}
8279

83-
public function getCreatedAt(): ?DateTime
80+
public function getCreatedAt(): DateTime
8481
{
8582
return $this->createdAt;
8683
}
@@ -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);
@@ -209,17 +209,8 @@ public function owns(OwnableInterface $resource): bool
209209
return $resource->getOwner()->getId() === $this->getId();
210210
}
211211

212-
#[ORM\PrePersist]
213-
public function onPrePersist(): void
214-
{
215-
if ($this->createdAt === null) {
216-
$this->createdAt = new DateTime();
217-
}
218-
$this->updatedAt = new DateTime();
219-
}
220-
221212
#[ORM\PreUpdate]
222-
public function onPreUpdate(): void
213+
public function setUpdatedAt(): void
223214
{
224215
$this->updatedAt = new DateTime();
225216
}

src/Domain/Identity/Model/AdministratorToken.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@ class AdministratorToken implements DomainModel, Identity, CreationDate
4444

4545
#[ORM\ManyToOne(targetEntity: Administrator::class)]
4646
#[ORM\JoinColumn(name: 'adminid', referencedColumnName: 'id', onDelete: 'CASCADE')]
47-
private ?Administrator $administrator = null;
47+
private Administrator $administrator;
4848

49-
public function __construct()
49+
public function __construct(Administrator $administrator)
5050
{
51-
$this->setExpiry(new DateTime());
51+
$this->generateExpiry();
52+
$this->generateKey();
53+
$this->administrator = $administrator;
5254
}
5355

5456
public function getId(): ?int
@@ -112,7 +114,7 @@ public function generateKey(): self
112114
return $this;
113115
}
114116

115-
public function getAdministrator(): Administrator|Proxy|null
117+
public function getAdministrator(): Administrator|Proxy
116118
{
117119
return $this->administrator;
118120
}

0 commit comments

Comments
 (0)