@@ -42,11 +42,28 @@ public function __construct(
4242 $ this ->distributionStoragePath = "$ storagePath/distribution " ;
4343 }
4444
45+ public function isAvailable (): bool
46+ {
47+
48+ }
49+
50+ /**
51+ * Check if the distribution exists on the filesystem, circumventing the database.
52+ */
4553 public function exists (string $ packageName , string $ packageVersion , ?string $ reference , ?string $ type ): bool
4654 {
4755 return null !== $ reference && null !== $ type && $ this ->filesystem ->exists ($ this ->path ($ packageName , $ packageVersion , $ reference , $ type ));
4856 }
4957
58+ public function findEntity (Version $ version , string $ reference , string $ type ): ?Distribution
59+ {
60+ return $ this ->distributionRepository ->findOneBy ([
61+ 'version ' => $ version ,
62+ 'reference ' => $ reference ,
63+ 'type ' => $ type ,
64+ ]);
65+ }
66+
5067 public function path (string $ packageName , string $ packageVersion , string $ reference , string $ type ): string
5168 {
5269 return "$ this ->distributionStoragePath / $ packageName/ $ packageVersion- $ reference. $ type " ;
@@ -66,6 +83,14 @@ public function resolve(Version $version, ?string $reference, ?string $type, boo
6683 return false ;
6784 }
6885
86+ $ distribution = $ this ->findEntity ($ version , $ reference , $ type );
87+ if (!$ distribution ) {
88+ $ distribution = new Distribution ();
89+ $ distribution ->setVersion ($ version );
90+ $ distribution ->setReference ($ reference );
91+ $ distribution ->setType ($ type );
92+ }
93+
6994 if ($ async ) {
7095 // Resolve the distribution asynchronously so it's available in the future now that we know it was requested
7196 $ message = Envelope::wrap (new ResolveDistribution ($ version ->getId (), $ reference , $ type ))
@@ -120,6 +145,7 @@ private function build(Version $version, ?string $reference, ?string $type): boo
120145 $ distribution = new Distribution ();
121146 $ distribution ->setVersion ($ version );
122147 $ distribution ->setReference ($ reference );
148+ $ distribution ->setType ($ type );
123149
124150 $ this ->distributionRepository ->save ($ distribution , flush: true );
125151
@@ -150,6 +176,7 @@ private function mirror(Version $version, ?string $reference, ?string $type): bo
150176 $ distribution = new Distribution ();
151177 $ distribution ->setVersion ($ version );
152178 $ distribution ->setReference ($ reference );
179+ $ distribution ->setType ($ type );
153180
154181 $ this ->distributionRepository ->save ($ distribution , flush: true );
155182
0 commit comments