6262use Symfony \Component \Routing \Generator \UrlGeneratorInterface ;
6363use Symfony \Contracts \EventDispatcher \Event ;
6464use Symfony \Contracts \EventDispatcher \EventDispatcherInterface ;
65+ use Webmozart \Assert \Assert ;
6566
6667final readonly class VersionUpdatedResult
6768{
@@ -458,7 +459,7 @@ public function update(IOInterface $io, Config $config, Package $package, VcsRep
458459 *
459460 * @param array{id: int, version: string, normalizedVersion: string, development: int, source: array{type: string|null, url: string|null, reference: string|null}|null, dist: array{type: string|null, url: string|null, reference: string|null, shasum: string|null}|null, softDeletedAt: string|null, deletionReason: string|null, lastBlockedReference: string|null, defaultBranch: int} $existingVersion
460461 */
461- private function applyStableImmutabilityGate (IOInterface $ io , \Doctrine \ORM \EntityManagerInterface $ em , Package $ package , array $ existingVersion , CompletePackageInterface $ data , int $ flags , VcsDriverInterface $ driver , ?string $ newEffectiveRef ): VersionSkippedResult
462+ private function applyStableImmutabilityGate (IOInterface $ io , \Doctrine \ORM \EntityManagerInterface $ em , VersionRepository $ versionRepo , Package $ package , array $ existingVersion , CompletePackageInterface $ data , int $ flags , VcsDriverInterface $ driver , ?string $ newEffectiveRef ): VersionSkippedResult
462463 {
463464 $ normVersion = $ data ->getVersion ();
464465 $ prettyVersion = $ data ->getPrettyVersion ();
@@ -484,7 +485,7 @@ private function applyStableImmutabilityGate(IOInterface $io, \Doctrine\ORM\Enti
484485 }
485486
486487 if ($ flags & self ::UPDATE_SOURCE_DIST_URL ) {
487- $ this ->applySourceDistUrlRewrite ($ io , $ em , $ existingVersion , $ data , $ driver );
488+ $ this ->applySourceDistUrlRewrite ($ io , $ versionRepo , $ existingVersion , $ data , $ driver );
488489 }
489490
490491 return new VersionSkippedResult (id: $ existingVersion ['id ' ], version: strtolower ($ normVersion ));
@@ -516,7 +517,7 @@ private function applyStableImmutabilityGate(IOInterface $io, \Doctrine\ORM\Enti
516517 *
517518 * @param array{id: int, source: array{type: string|null, url: string|null, reference: string|null}|null, dist: array{type: string|null, url: string|null, reference: string|null, shasum: string|null}|null} $existingVersion
518519 */
519- private function applySourceDistUrlRewrite (IOInterface $ io , \ Doctrine \ ORM \ EntityManagerInterface $ em , array $ existingVersion , CompletePackageInterface $ data , VcsDriverInterface $ driver ): void
520+ private function applySourceDistUrlRewrite (IOInterface $ io , VersionRepository $ versionRepo , array $ existingVersion , CompletePackageInterface $ data , VcsDriverInterface $ driver ): void
520521 {
521522 $ prettyVersion = $ data ->getPrettyVersion ();
522523 $ skip = function (string $ reason ) use ($ io , $ prettyVersion , $ data , $ existingVersion ): void {
@@ -573,19 +574,36 @@ private function applySourceDistUrlRewrite(IOInterface $io, \Doctrine\ORM\Entity
573574 return ;
574575 }
575576
576- $ newSource = ($ oldSource ?? []) + [];
577+ $ version = $ versionRepo ->find ($ existingVersion ['id ' ]);
578+ if (null === $ version ) {
579+ $ skip ('version not found by id ' );
580+
581+ return ;
582+ }
583+
584+ Assert::notNull ($ oldSource );
585+ Assert::notNull ($ oldDist );
586+ $ oldSourceUrl = $ oldSource ['url ' ] ?? null ;
587+ $ oldDistUrlStored = $ oldDist ['url ' ] ?? null ;
588+
589+ $ newSource = $ oldSource ;
577590 $ newSource ['url ' ] = $ newSourceUrl ;
578- $ newDist = ( $ oldDist ?? []) + [] ;
591+ $ newDist = $ oldDist ;
579592 $ newDist ['url ' ] = $ newDistUrl ;
580593
581- $ em ->getConnection ()->executeStatement (
582- 'UPDATE package_version SET source = :source, dist = :dist WHERE id = :id ' ,
583- [
584- 'source ' => json_encode ($ newSource , \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE ),
585- 'dist ' => json_encode ($ newDist , \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE ),
586- 'id ' => $ existingVersion ['id ' ],
587- ]
588- );
594+ $ version ->setSource ($ newSource );
595+ $ version ->setDist ($ newDist );
596+
597+ $ this ->logger ->info ('Rewrote source/dist URL for stable version ' , [
598+ 'package ' => $ data ->getName (),
599+ 'version ' => $ prettyVersion ,
600+ 'version_id ' => $ existingVersion ['id ' ],
601+ 'source_url_from ' => $ oldSourceUrl ,
602+ 'source_url_to ' => $ newSourceUrl ,
603+ 'dist_url_from ' => $ oldDistUrlStored ,
604+ 'dist_url_to ' => $ newDistUrl ,
605+ 'reference ' => $ newSourceRef ,
606+ ]);
589607 }
590608
591609 /**
@@ -625,7 +643,7 @@ private function updateInformation(IOInterface $io, VersionRepository $versionRe
625643
626644 // Stable-version immutability gate: any existing stable version is frozen.
627645 if (!$ data ->isDev ()) {
628- return $ this ->applyStableImmutabilityGate ($ io , $ em , $ package , $ existingVersion , $ data , $ flags , $ driver , $ newEffectiveRef );
646+ return $ this ->applyStableImmutabilityGate ($ io , $ em , $ versionRepo , $ package , $ existingVersion , $ data , $ flags , $ driver , $ newEffectiveRef );
629647 }
630648 } elseif ($ newEffectiveRef === null ) {
631649 // Brand-new version with no usable identity: refuse to create.
0 commit comments