Skip to content

Commit 8a1327c

Browse files
committed
Add pruned property to package version entity
1 parent 487ba51 commit 8a1327c

3 files changed

Lines changed: 62 additions & 1 deletion

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace DoctrineMigrations;
6+
7+
use Doctrine\DBAL\Schema\Schema;
8+
use Doctrine\Migrations\AbstractMigration;
9+
10+
final class Version20260416081737 extends AbstractMigration
11+
{
12+
public function getDescription(): string
13+
{
14+
return '';
15+
}
16+
17+
public function up(Schema $schema): void
18+
{
19+
$this->addSql(<<<'SQL'
20+
ALTER TABLE version ADD pruned BOOLEAN DEFAULT NULL
21+
SQL);
22+
$this->addSql(<<<'SQL'
23+
UPDATE version SET pruned = false
24+
SQL);
25+
$this->addSql(<<<'SQL'
26+
ALTER TABLE version ALTER pruned SET NOT NULL
27+
SQL);
28+
}
29+
30+
public function down(Schema $schema): void
31+
{
32+
$this->addSql(<<<'SQL'
33+
ALTER TABLE version DROP pruned
34+
SQL);
35+
}
36+
}

src/Doctrine/Entity/Version.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ class Version extends TrackedEntity implements \Stringable
2323
#[ORM\Column]
2424
private bool $development;
2525

26+
#[ORM\Column]
27+
private bool $pruned = false;
28+
2629
#[ORM\Column]
2730
private bool $defaultBranch = false;
2831

@@ -91,6 +94,16 @@ public function setDevelopment(bool $development): void
9194
$this->development = $development;
9295
}
9396

97+
public function isPruned(): bool
98+
{
99+
return $this->pruned;
100+
}
101+
102+
public function setPruned(bool $pruned): void
103+
{
104+
$this->pruned = $pruned;
105+
}
106+
94107
public function isDefaultBranch(): bool
95108
{
96109
return $this->defaultBranch;

src/Package/PackageMetadataResolver.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ public function __construct(
4141
private bool $retainRevisionsTagged,
4242
#[Autowire(param: 'dirigent.metadata.retain_revisions.dev_versions')]
4343
private bool $retainRevisionsDev,
44+
#[Autowire(param: 'dirigent.metadata.retain_versions.tagged_versions')]
45+
private bool $retainVersionsTagged,
46+
#[Autowire(param: 'dirigent.metadata.retain_versions.dev_versions')]
47+
private bool $retainVersionsDev,
4448
) {
4549
}
4650

@@ -209,7 +213,15 @@ private function updatePackage(Package $package, array $composerPackages, ?VcsDr
209213

210214
// Remove outdated versions
211215
foreach ($existingVersionMetadata as $version) {
212-
$this->entityManager->remove($version);
216+
$removeVersion = $version->isDevelopment() ? !$this->retainVersionsDev : !$this->retainVersionsTagged;
217+
if ($removeVersion) {
218+
$this->entityManager->remove($version);
219+
} else {
220+
$version->setPruned(true);
221+
$version->setUpdatedAt(new \DateTimeImmutable());
222+
223+
$this->entityManager->persist($version);
224+
}
213225
}
214226

215227
$package->setUpdatedAt(new \DateTimeImmutable());

0 commit comments

Comments
 (0)