Skip to content

Commit ca852e1

Browse files
committed
Replace getcwd() with ExtensionInstaller::getRoundcubemailInstallPath()
1 parent 27015bb commit ca852e1

4 files changed

Lines changed: 23 additions & 13 deletions

File tree

src/Roundcube/Composer/ExtensionInstaller.php

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,28 @@
2020
* @version GIT: <git_id>
2121
* @link https://github.com/roundcube/plugin-installer
2222
*/
23-
class ExtensionInstaller extends LibraryInstaller
23+
abstract class ExtensionInstaller extends LibraryInstaller
2424
{
2525
protected $composer_type;
2626

27+
protected function getRoundcubemailInstallPath(): string
28+
{
29+
$roundcubemailPackage = $this->composer
30+
->getRepositoryManager()
31+
->findPackage('roundcube/roundcubemail', '*');
32+
33+
return $this->getInstallPath($roundcubemailPackage);
34+
}
35+
2736
/**
2837
* {@inheritDoc}
2938
*/
3039
public function getInstallPath(PackageInterface $package)
3140
{
41+
if (!$this->supports($package->getType())) {
42+
return parent::getInstallPath($package);
43+
}
44+
3245
static $vendorDir;
3346
if ($vendorDir === null) {
3447
$vendorDir = $this->getVendorDir();
@@ -44,7 +57,7 @@ public function install(InstalledRepositoryInterface $repo, PackageInterface $pa
4457
{
4558
// initialize Roundcube environment
4659
if (!defined('INSTALL_PATH')) {
47-
define('INSTALL_PATH', getcwd() . '/');
60+
define('INSTALL_PATH', $this->getRoundcubemailInstallPath() . '/');
4861
}
4962
require_once INSTALL_PATH . 'program/include/iniset.php';
5063

@@ -118,7 +131,7 @@ public function update(InstalledRepositoryInterface $repo, PackageInterface $ini
118131
{
119132
// initialize Roundcube environment
120133
if (!defined('INSTALL_PATH')) {
121-
define('INSTALL_PATH', getcwd() . '/');
134+
define('INSTALL_PATH', $this->getRoundcubemailInstallPath() . '/');
122135
}
123136
require_once INSTALL_PATH . 'program/include/iniset.php';
124137

@@ -195,7 +208,7 @@ public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $
195208
{
196209
// initialize Roundcube environment
197210
if (!defined('INSTALL_PATH')) {
198-
define('INSTALL_PATH', getcwd() . '/');
211+
define('INSTALL_PATH', $this->getRoundcubemailInstallPath() . '/');
199212
}
200213
require_once INSTALL_PATH . 'program/include/iniset.php';
201214

@@ -247,10 +260,7 @@ public function supports($packageType)
247260
*
248261
* @return string
249262
*/
250-
public function getVendorDir()
251-
{
252-
return getcwd();
253-
}
263+
abstract public function getVendorDir();
254264

255265
/**
256266
* Extract the (valid) package name from the package object
@@ -368,7 +378,7 @@ private function rcubeConfigFile($file = 'config.inc.php')
368378
{
369379
$config = new \rcube_config();
370380
$paths = $config->resolve_paths($file);
371-
$path = getcwd() . '/config/' . $file;
381+
$path = $this->getRoundcubemailInstallPath() . '/config/' . $file;
372382

373383
foreach ($paths as $fpath) {
374384
if ($fpath && is_file($fpath) && is_readable($fpath)) {
@@ -396,7 +406,7 @@ private function rcubeRunScript($script, PackageInterface $package)
396406

397407
// run PHP script in Roundcube context
398408
if ($scriptfile && preg_match('/\.php$/', $scriptfile)) {
399-
$incdir = realpath(getcwd() . '/program/include');
409+
$incdir = realpath($this->getRoundcubemailInstallPath() . '/program/include');
400410
include_once($incdir . '/iniset.php');
401411
include($scriptfile);
402412
}

src/Roundcube/Composer/PluginInstaller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class PluginInstaller extends ExtensionInstaller
1616

1717
public function getVendorDir()
1818
{
19-
return getcwd() . DIRECTORY_SEPARATOR . 'plugins';
19+
return $this->getRoundcubemailInstallPath() . DIRECTORY_SEPARATOR . 'plugins';
2020
}
2121

2222
protected function confirmInstall($package_name)

src/Roundcube/Composer/RoundcubeInstaller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class RoundcubeInstaller implements PluginInterface
1010
{
11-
private $extentions = ['\Roundcube\Composer\PluginInstaller', '\Roundcube\Composer\SkinInstaller'];
11+
private $extentions = [PluginInstaller::class, SkinInstaller::class];
1212
private $installers = [];
1313

1414
public function activate(Composer $composer, IOInterface $io)

src/Roundcube/Composer/SkinInstaller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class SkinInstaller extends ExtensionInstaller
1616

1717
public function getVendorDir()
1818
{
19-
return getcwd() . DIRECTORY_SEPARATOR . 'skins';
19+
return $this->getRoundcubemailInstallPath() . DIRECTORY_SEPARATOR . 'skins';
2020
}
2121

2222
protected function confirmInstall($package_name)

0 commit comments

Comments
 (0)