Skip to content

Commit bb00cb6

Browse files
committed
Save local distributions to the database
1 parent b4f00c4 commit bb00cb6

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/Package/PackageDistributionResolver.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
namespace CodedMonkey\Dirigent\Package;
66

77
use CodedMonkey\Dirigent\Composer\ComposerClient;
8+
use CodedMonkey\Dirigent\Doctrine\Entity\Distribution;
89
use CodedMonkey\Dirigent\Doctrine\Entity\Metadata;
10+
use CodedMonkey\Dirigent\Doctrine\Repository\DistributionRepository;
911
use CodedMonkey\Dirigent\Message\ResolveDistribution;
1012
use Symfony\Component\DependencyInjection\Attribute\Autowire;
1113
use Symfony\Component\Filesystem\Filesystem;
@@ -20,6 +22,7 @@
2022
public function __construct(
2123
private MessageBusInterface $messenger,
2224
private ComposerClient $composer,
25+
private DistributionRepository $distributionRepository,
2326
#[Autowire(param: 'dirigent.distributions.dev_versions')]
2427
private bool $includeDevVersions,
2528
#[Autowire(param: 'dirigent.storage.path')]
@@ -68,6 +71,14 @@ public function resolve(Metadata $metadata, string $type, bool $async): bool
6871
return false;
6972
}
7073

74+
$distribution = $this->distributionRepository->findOneBy(['metadata' => $metadata, 'type' => $type]);
75+
if (null === $distribution) {
76+
$distribution = new Distribution($metadata);
77+
$distribution->setReference($reference);
78+
$distribution->setType($type);
79+
$distribution->setReleasedAt($metadata->getReleasedAt());
80+
}
81+
7182
$distUrl = $metadata->getDistUrl();
7283
$path = $this->path($packageName, $versionName, $reference, $type);
7384

@@ -76,6 +87,8 @@ public function resolve(Metadata $metadata, string $type, bool $async): bool
7687
$httpDownloader = $this->composer->createHttpDownloader();
7788
$httpDownloader->copy($distUrl, $path);
7889

90+
$this->distributionRepository->save($distribution);
91+
7992
return true;
8093
}
8194
}

0 commit comments

Comments
 (0)