22
33namespace Roundcube \Composer ;
44
5+ use Composer \Installer \InstallationManager ;
56use Composer \Installer \LibraryInstaller ;
67use Composer \Package \PackageInterface ;
78use Composer \Package \Version \VersionParser ;
@@ -35,23 +36,41 @@ protected function setRoundcubemailInstallPath(InstalledRepositoryInterface $ins
3536
3637 if ($ roundcubemailPackage === $ rootPackage ) { // $this->getInstallPath($package) does not work for root package
3738 $ this ->initializeVendorDir ();
38- $ this -> roundcubemailInstallPath = dirname ($ this ->vendorDir );
39+ $ installPath = dirname ($ this ->vendorDir );
3940 } else {
40- $ this ->roundcubemailInstallPath = $ this ->getInstallPath ($ roundcubemailPackage );
41+ $ installPath = $ this ->getInstallPath ($ roundcubemailPackage );
42+ }
43+
44+ if ($ this ->roundcubemailInstallPath === null ) {
45+ $ this ->roundcubemailInstallPath = $ installPath ;
46+ } elseif ($ this ->roundcubemailInstallPath !== $ installPath ) {
47+ throw new \Exception ('Install path of "roundcube/roundcubemail" package has unexpectedly changed ' );
4148 }
4249 }
4350
4451 protected function getRoundcubemailInstallPath (): string
4552 {
53+ // install path is not set at composer download phase
54+ // never assume any path, but for this known composer behaviour get it from backtrace instead
55+ if ($ this ->roundcubemailInstallPath === null ) {
56+ $ backtrace = debug_backtrace ();
57+ foreach ($ backtrace as $ frame ) {
58+ // relies on https://github.com/composer/composer/blob/2.7.4/src/Composer/Installer/InstallationManager.php#L243
59+ if (($ frame ['object ' ] ?? null ) instanceof InstallationManager
60+ && $ frame ['function ' ] === 'downloadAndExecuteBatch '
61+ ) {
62+ $ this ->setRoundcubemailInstallPath ($ frame ['args ' ][0 ]);
63+ }
64+ }
65+ }
66+
4667 return $ this ->roundcubemailInstallPath ;
4768 }
4869
70+ #[\Override]
4971 public function getInstallPath (PackageInterface $ package )
5072 {
51- if (
52- !$ this ->supports ($ package ->getType ())
53- || $ this ->roundcubemailInstallPath === null // install path is not known at download phase
54- ) {
73+ if (!$ this ->supports ($ package ->getType ())) {
5574 return parent ::getInstallPath ($ package );
5675 }
5776
@@ -63,13 +82,21 @@ public function getInstallPath(PackageInterface $package)
6382
6483 private function initializeRoundcubemailEnvironment (): void
6584 {
66- // initialize Roundcube environment
6785 if (!defined ('INSTALL_PATH ' )) {
6886 define ('INSTALL_PATH ' , $ this ->getRoundcubemailInstallPath () . '/ ' );
6987 }
7088 require_once INSTALL_PATH . 'program/include/iniset.php ' ;
7189 }
7290
91+ #[\Override]
92+ public function isInstalled (InstalledRepositoryInterface $ repo , PackageInterface $ package )
93+ {
94+ $ this ->setRoundcubemailInstallPath ($ repo );
95+
96+ return parent ::isInstalled ($ repo , $ package );
97+ }
98+
99+ #[\Override]
73100 public function install (InstalledRepositoryInterface $ repo , PackageInterface $ package )
74101 {
75102 $ this ->setRoundcubemailInstallPath ($ repo );
@@ -131,6 +158,7 @@ public function install(InstalledRepositoryInterface $repo, PackageInterface $pa
131158 return null ;
132159 }
133160
161+ #[\Override]
134162 public function update (InstalledRepositoryInterface $ repo , PackageInterface $ initial , PackageInterface $ target )
135163 {
136164 $ this ->setRoundcubemailInstallPath ($ repo );
@@ -196,6 +224,7 @@ public function update(InstalledRepositoryInterface $repo, PackageInterface $ini
196224 return null ;
197225 }
198226
227+ #[\Override]
199228 public function uninstall (InstalledRepositoryInterface $ repo , PackageInterface $ package )
200229 {
201230 $ this ->setRoundcubemailInstallPath ($ repo );
@@ -237,6 +266,7 @@ public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $
237266 return null ;
238267 }
239268
269+ #[\Override]
240270 public function supports ($ packageType )
241271 {
242272 return $ packageType === $ this ->composer_type ;
0 commit comments