Skip to content

Commit c22f795

Browse files
authored
Merge pull request #47 from mvorisek/fix_41
Replace getcwd() with Roundcubemail path from composer API
2 parents 27015bb + 63b2776 commit c22f795

4 files changed

Lines changed: 23 additions & 16 deletions

File tree

src/Roundcube/Composer/ExtensionInstaller.php

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,30 @@
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
{
32-
static $vendorDir;
33-
if ($vendorDir === null) {
34-
$vendorDir = $this->getVendorDir();
41+
if (!$this->supports($package->getType())) {
42+
return parent::getInstallPath($package);
3543
}
3644

45+
$vendorDir = $this->getVendorDir();
46+
3747
return sprintf('%s/%s', $vendorDir, $this->getPackageName($package));
3848
}
3949

@@ -44,7 +54,7 @@ public function install(InstalledRepositoryInterface $repo, PackageInterface $pa
4454
{
4555
// initialize Roundcube environment
4656
if (!defined('INSTALL_PATH')) {
47-
define('INSTALL_PATH', getcwd() . '/');
57+
define('INSTALL_PATH', $this->getRoundcubemailInstallPath() . '/');
4858
}
4959
require_once INSTALL_PATH . 'program/include/iniset.php';
5060

@@ -118,7 +128,7 @@ public function update(InstalledRepositoryInterface $repo, PackageInterface $ini
118128
{
119129
// initialize Roundcube environment
120130
if (!defined('INSTALL_PATH')) {
121-
define('INSTALL_PATH', getcwd() . '/');
131+
define('INSTALL_PATH', $this->getRoundcubemailInstallPath() . '/');
122132
}
123133
require_once INSTALL_PATH . 'program/include/iniset.php';
124134

@@ -195,7 +205,7 @@ public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $
195205
{
196206
// initialize Roundcube environment
197207
if (!defined('INSTALL_PATH')) {
198-
define('INSTALL_PATH', getcwd() . '/');
208+
define('INSTALL_PATH', $this->getRoundcubemailInstallPath() . '/');
199209
}
200210
require_once INSTALL_PATH . 'program/include/iniset.php';
201211

@@ -247,10 +257,7 @@ public function supports($packageType)
247257
*
248258
* @return string
249259
*/
250-
public function getVendorDir()
251-
{
252-
return getcwd();
253-
}
260+
abstract public function getVendorDir();
254261

255262
/**
256263
* Extract the (valid) package name from the package object
@@ -368,7 +375,7 @@ private function rcubeConfigFile($file = 'config.inc.php')
368375
{
369376
$config = new \rcube_config();
370377
$paths = $config->resolve_paths($file);
371-
$path = getcwd() . '/config/' . $file;
378+
$path = $this->getRoundcubemailInstallPath() . '/config/' . $file;
372379

373380
foreach ($paths as $fpath) {
374381
if ($fpath && is_file($fpath) && is_readable($fpath)) {
@@ -396,7 +403,7 @@ private function rcubeRunScript($script, PackageInterface $package)
396403

397404
// run PHP script in Roundcube context
398405
if ($scriptfile && preg_match('/\.php$/', $scriptfile)) {
399-
$incdir = realpath(getcwd() . '/program/include');
406+
$incdir = realpath($this->getRoundcubemailInstallPath() . '/program/include');
400407
include_once($incdir . '/iniset.php');
401408
include($scriptfile);
402409
}

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)