Skip to content

Commit 4d91081

Browse files
committed
Use composer InstalledRepository to determine install dir
1 parent 5eb0d08 commit 4d91081

1 file changed

Lines changed: 18 additions & 11 deletions

File tree

src/ExtensionInstaller.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,38 @@
55
use Composer\Installer\LibraryInstaller;
66
use Composer\Package\PackageInterface;
77
use Composer\Package\Version\VersionParser;
8+
use Composer\Repository\InstalledRepository;
89
use Composer\Repository\InstalledRepositoryInterface;
910
use Composer\Util\Filesystem;
1011
use Composer\Util\ProcessExecutor;
1112
use React\Promise\PromiseInterface;
1213

1314
abstract class ExtensionInstaller extends LibraryInstaller
1415
{
16+
private $roundcubemailInstallPath;
17+
1518
protected $composer_type;
1619

17-
protected function getRoundcubemailInstallPath(): string
20+
protected function setRoundcubemailInstallPath(InstalledRepositoryInterface $repo): void
1821
{
19-
$rootPackage = $this->composer->getPackage();
20-
if ($rootPackage->getName() === 'roundcube/roundcubemail') {
21-
$this->initializeVendorDir();
22+
// https://github.com/composer/composer/discussions/11927#discussioncomment-9116893
23+
$repo = new InstalledRepository([$repo]);
2224

23-
return dirname($this->vendorDir);
24-
}
25+
$roundcubemailPackages = $repo->findPackagesWithReplacersAndProviders('roundcube/roundcubemail');
26+
assert(count($roundcubemailPackages) === 1);
27+
$roundcubemailPackage = $roundcubemailPackages[0];
2528

26-
$roundcubemailPackage = $this->composer
27-
->getRepositoryManager()
28-
->findPackage('roundcube/roundcubemail', '*');
29+
$this->roundcubemailInstallPath = $this->getInstallPath($roundcubemailPackage);
30+
}
2931

30-
return $this->getInstallPath($roundcubemailPackage);
32+
protected function getRoundcubemailInstallPath(): string
33+
{
34+
return $this->roundcubemailInstallPath;
3135
}
3236

3337
public function getInstallPath(PackageInterface $package)
3438
{
35-
if (!$this->supports($package->getType())) {
39+
if (!$this->supports($package->getType()) || $this->roundcubemailInstallPath === null /* install path is not known at download phase */) {
3640
return parent::getInstallPath($package);
3741
}
3842

@@ -44,6 +48,7 @@ public function getInstallPath(PackageInterface $package)
4448
public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
4549
{
4650
// initialize Roundcube environment
51+
$this->setRoundcubemailInstallPath($repo);
4752
if (!defined('INSTALL_PATH')) {
4853
define('INSTALL_PATH', $this->getRoundcubemailInstallPath() . '/');
4954
}
@@ -114,6 +119,7 @@ public function install(InstalledRepositoryInterface $repo, PackageInterface $pa
114119
public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
115120
{
116121
// initialize Roundcube environment
122+
$this->setRoundcubemailInstallPath($repo);
117123
if (!defined('INSTALL_PATH')) {
118124
define('INSTALL_PATH', $this->getRoundcubemailInstallPath() . '/');
119125
}
@@ -187,6 +193,7 @@ public function update(InstalledRepositoryInterface $repo, PackageInterface $ini
187193
public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
188194
{
189195
// initialize Roundcube environment
196+
$this->setRoundcubemailInstallPath($repo);
190197
if (!defined('INSTALL_PATH')) {
191198
define('INSTALL_PATH', $this->getRoundcubemailInstallPath() . '/');
192199
}

0 commit comments

Comments
 (0)