55use Composer \Installer \LibraryInstaller ;
66use Composer \Package \PackageInterface ;
77use Composer \Package \Version \VersionParser ;
8+ use Composer \Repository \InstalledRepository ;
89use Composer \Repository \InstalledRepositoryInterface ;
10+ use Composer \Repository \RootPackageRepository ;
911use Composer \Util \Filesystem ;
1012use Composer \Util \ProcessExecutor ;
1113use React \Promise \PromiseInterface ;
1214
1315abstract class ExtensionInstaller extends LibraryInstaller
1416{
17+ private $ roundcubemailInstallPath ;
18+
1519 protected $ composer_type ;
1620
17- protected function getRoundcubemailInstallPath ( ): string
21+ protected function setRoundcubemailInstallPath ( InstalledRepositoryInterface $ installedRepo ): void
1822 {
19- $ rootPackage = $ this ->composer ->getPackage ();
20- if ($ rootPackage ->getName () === 'roundcube/roundcubemail ' ) {
23+ // https://github.com/composer/composer/discussions/11927#discussioncomment-9116893
24+ $ rootPackage = clone $ this ->composer ->getPackage ();
25+ $ installedRepo = new InstalledRepository ([
26+ $ installedRepo ,
27+ new RootPackageRepository ($ rootPackage ),
28+ ]);
29+
30+ $ roundcubemailPackages = $ installedRepo ->findPackagesWithReplacersAndProviders ('roundcube/roundcubemail ' );
31+ assert (count ($ roundcubemailPackages ) === 1 );
32+ $ roundcubemailPackage = $ roundcubemailPackages [0 ];
33+
34+ if ($ roundcubemailPackage === $ rootPackage ) { // $this->getInstallPath($package) does not work for root package
2135 $ this ->initializeVendorDir ();
22-
23- return dirname ($ this ->vendorDir );
36+ $ this ->roundcubemailInstallPath = dirname ($ this ->vendorDir );
37+ } else {
38+ $ this ->roundcubemailInstallPath = $ this ->getInstallPath ($ roundcubemailPackage );
2439 }
40+ }
2541
26- $ roundcubemailPackage = $ this ->composer
27- ->getRepositoryManager ()
28- ->findPackage ('roundcube/roundcubemail ' , '* ' );
29-
30- return $ this ->getInstallPath ($ roundcubemailPackage );
42+ protected function getRoundcubemailInstallPath (): string
43+ {
44+ return $ this ->roundcubemailInstallPath ;
3145 }
3246
3347 public function getInstallPath (PackageInterface $ package )
3448 {
35- if (!$ this ->supports ($ package ->getType ())) {
49+ if (!$ this ->supports ($ package ->getType ()) || $ this -> roundcubemailInstallPath === null /* install path is not known at download phase */ ) {
3650 return parent ::getInstallPath ($ package );
3751 }
3852
@@ -43,6 +57,8 @@ public function getInstallPath(PackageInterface $package)
4357
4458 public function install (InstalledRepositoryInterface $ repo , PackageInterface $ package )
4559 {
60+ $ this ->setRoundcubemailInstallPath ($ repo );
61+
4662 // initialize Roundcube environment
4763 if (!defined ('INSTALL_PATH ' )) {
4864 define ('INSTALL_PATH ' , $ this ->getRoundcubemailInstallPath () . '/ ' );
@@ -113,6 +129,8 @@ public function install(InstalledRepositoryInterface $repo, PackageInterface $pa
113129
114130 public function update (InstalledRepositoryInterface $ repo , PackageInterface $ initial , PackageInterface $ target )
115131 {
132+ $ this ->setRoundcubemailInstallPath ($ repo );
133+
116134 // initialize Roundcube environment
117135 if (!defined ('INSTALL_PATH ' )) {
118136 define ('INSTALL_PATH ' , $ this ->getRoundcubemailInstallPath () . '/ ' );
@@ -186,6 +204,8 @@ public function update(InstalledRepositoryInterface $repo, PackageInterface $ini
186204
187205 public function uninstall (InstalledRepositoryInterface $ repo , PackageInterface $ package )
188206 {
207+ $ this ->setRoundcubemailInstallPath ($ repo );
208+
189209 // initialize Roundcube environment
190210 if (!defined ('INSTALL_PATH ' )) {
191211 define ('INSTALL_PATH ' , $ this ->getRoundcubemailInstallPath () . '/ ' );
0 commit comments