Skip to content

Commit 6c0c9d5

Browse files
committed
FilterList: remove migration code to assign publicId
1 parent 51e4e29 commit 6c0c9d5

4 files changed

Lines changed: 8 additions & 27 deletions

File tree

src/Entity/FilterListEntry.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ class FilterListEntry
4848
#[ORM\Column]
4949
private \DateTimeImmutable $updatedAt;
5050

51-
#[ORM\Column(nullable: true)]
52-
private ?string $publicId;
51+
#[ORM\Column]
52+
private string $publicId;
5353

5454
public function __construct(RemoteFilterListEntry $remote)
5555
{
@@ -93,7 +93,7 @@ public function getPublicId(): ?string
9393
return $this->publicId;
9494
}
9595

96-
public function assignPublicId(): void
96+
private function assignPublicId(): void
9797
{
9898
$this->publicId = IdGenerator::generateFilterListEntry();
9999
}

src/FilterList/FilterListResolver.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,12 @@ class FilterListResolver
2020
* @param array<FilterListEntry> $existingEntries
2121
* @param array<RemoteFilterListEntry> $remoteEntries
2222
*
23-
* @return array{list<FilterListEntry>, list<FilterListEntry>, bool}
23+
* @return array{list<FilterListEntry>, list<FilterListEntry>}
2424
*/
2525
public function resolve(array $existingEntries, array $remoteEntries): array
2626
{
27-
$modifiedExisting = false;
2827
$existingMap = [];
2928
foreach ($existingEntries as $existing) {
30-
if (!$existing->getPublicId()) {
31-
$existing->assignPublicId();
32-
$modifiedExisting = true;
33-
}
34-
3529
$existingMap[$existing->getPackageName()][$existing->getVersion()] = $existing;
3630
}
3731

@@ -58,7 +52,6 @@ public function resolve(array $existingEntries, array $remoteEntries): array
5852
return [
5953
$new,
6054
$unmatched,
61-
$modifiedExisting,
6255
];
6356
}
6457
}

src/Service/FilterListWorker.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function process(Job $job, SignalHandler $signal): array
7575

7676
/** @var FilterListEntry[] $existingEntries */
7777
$existingEntries = $this->doctrine->getRepository(FilterListEntry::class)->getEntriesInList($list);
78-
[$new, $removed, $modifiedExisting] = $this->malwareFeedResolver->resolve($existingEntries, $remoteEntries);
78+
[$new, $removed] = $this->malwareFeedResolver->resolve($existingEntries, $remoteEntries);
7979

8080
foreach ($new as $entry) {
8181
$this->doctrine->getManager()->persist($entry);
@@ -85,7 +85,7 @@ public function process(Job $job, SignalHandler $signal): array
8585
$this->doctrine->getManager()->remove($entry);
8686
}
8787

88-
if ($new !== [] || $removed !== [] || $modifiedExisting) {
88+
if ($new !== [] || $removed !== []) {
8989
$this->doctrine->getManager()->flush();
9090
}
9191

tests/FilterList/FilterListResolverTest.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,7 @@ public function testExistingEntryWithTwoRemoteEntriesResultsInNoChange(): void
4343
$remote = $this->createRemoteFilterListEntry('vendor/package', '1.0.0');
4444
$result = $this->resolver->resolve([$existing], [$remote, $remote]);
4545

46-
$this->assertSame([[], [], false], $result);
47-
}
48-
49-
public function testExistingWithoutIdAssignsNewPublicId(): void
50-
{
51-
$existing = new FilterListEntry($this->createRemoteFilterListEntry('vendor/package', '1.0.0'));
52-
$this->unsetPublicId($existing);
53-
$this->assertNull($existing->getPublicId());
54-
$remote = $this->createRemoteFilterListEntry('vendor/package', '1.0.0');
55-
$result = $this->resolver->resolve([$existing], [$remote, $remote]);
56-
57-
$this->assertSame([[], [], true], $result);
58-
$this->assertNotNull($existing->getPublicId());
46+
$this->assertSame([[], []], $result);
5947
}
6048

6149
public function testResolveRemoveOldEntry(): void
@@ -98,7 +86,7 @@ public function testResolveEmpty(): void
9886
{
9987
$result = $this->resolver->resolve([], []);
10088

101-
$this->assertSame([[], [], false], $result);
89+
$this->assertSame([[], []], $result);
10290
}
10391

10492
public function testResolveMultipleVersionsSamePackage(): void

0 commit comments

Comments
 (0)