55namespace CodedMonkey \Dirigent \Package ;
66
77use CodedMonkey \Dirigent \Composer \ComposerClient ;
8+ use CodedMonkey \Dirigent \Doctrine \Entity \Distribution ;
89use CodedMonkey \Dirigent \Doctrine \Entity \Metadata ;
10+ use CodedMonkey \Dirigent \Doctrine \Repository \DistributionRepository ;
911use CodedMonkey \Dirigent \Message \ResolveDistribution ;
1012use Symfony \Component \DependencyInjection \Attribute \Autowire ;
1113use Symfony \Component \Filesystem \Filesystem ;
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