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,10 @@ public function resolve(Metadata $metadata, string $type, bool $async): bool
6871 return false ;
6972 }
7073
74+ if (null === $ distribution = $ this ->distributionRepository ->findOneBy (['metadata ' => $ metadata , 'type ' => $ type ])) {
75+ $ distribution = new Distribution ($ metadata , $ type );
76+ }
77+
7178 $ distributionUrl = $ metadata ->getDistributionUrl ();
7279 $ path = $ this ->path ($ packageName , $ versionName , $ reference , $ type );
7380
@@ -76,6 +83,11 @@ public function resolve(Metadata $metadata, string $type, bool $async): bool
7683 $ httpDownloader = $ this ->composer ->createHttpDownloader ();
7784 $ httpDownloader ->copy ($ distributionUrl , $ path );
7885
86+ $ distribution ->setSource ($ distributionUrl );
87+ $ distribution ->setResolvedAt ();
88+
89+ $ this ->distributionRepository ->save ($ distribution , true );
90+
7991 return true ;
8092 }
8193}
0 commit comments