Skip to content

Commit

Permalink
Merge pull request #47 from mvorisek/fix_41
Browse files Browse the repository at this point in the history
Replace getcwd() with Roundcubemail path from composer API
  • Loading branch information
alecpl authored Apr 9, 2024
2 parents 27015bb + 63b2776 commit c22f795
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
33 changes: 20 additions & 13 deletions src/Roundcube/Composer/ExtensionInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,30 @@
* @version GIT: <git_id>
* @link https://github.com/roundcube/plugin-installer
*/
class ExtensionInstaller extends LibraryInstaller
abstract class ExtensionInstaller extends LibraryInstaller
{
protected $composer_type;

protected function getRoundcubemailInstallPath(): string
{
$roundcubemailPackage = $this->composer
->getRepositoryManager()
->findPackage('roundcube/roundcubemail', '*');

return $this->getInstallPath($roundcubemailPackage);
}

/**
* {@inheritDoc}
*/
public function getInstallPath(PackageInterface $package)
{
static $vendorDir;
if ($vendorDir === null) {
$vendorDir = $this->getVendorDir();
if (!$this->supports($package->getType())) {
return parent::getInstallPath($package);
}

$vendorDir = $this->getVendorDir();

return sprintf('%s/%s', $vendorDir, $this->getPackageName($package));
}

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

Expand Down Expand Up @@ -118,7 +128,7 @@ public function update(InstalledRepositoryInterface $repo, PackageInterface $ini
{
// initialize Roundcube environment
if (!defined('INSTALL_PATH')) {
define('INSTALL_PATH', getcwd() . '/');
define('INSTALL_PATH', $this->getRoundcubemailInstallPath() . '/');
}
require_once INSTALL_PATH . 'program/include/iniset.php';

Expand Down Expand Up @@ -195,7 +205,7 @@ public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $
{
// initialize Roundcube environment
if (!defined('INSTALL_PATH')) {
define('INSTALL_PATH', getcwd() . '/');
define('INSTALL_PATH', $this->getRoundcubemailInstallPath() . '/');
}
require_once INSTALL_PATH . 'program/include/iniset.php';

Expand Down Expand Up @@ -247,10 +257,7 @@ public function supports($packageType)
*
* @return string
*/
public function getVendorDir()
{
return getcwd();
}
abstract public function getVendorDir();

/**
* Extract the (valid) package name from the package object
Expand Down Expand Up @@ -368,7 +375,7 @@ private function rcubeConfigFile($file = 'config.inc.php')
{
$config = new \rcube_config();
$paths = $config->resolve_paths($file);
$path = getcwd() . '/config/' . $file;
$path = $this->getRoundcubemailInstallPath() . '/config/' . $file;

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

// run PHP script in Roundcube context
if ($scriptfile && preg_match('/\.php$/', $scriptfile)) {
$incdir = realpath(getcwd() . '/program/include');
$incdir = realpath($this->getRoundcubemailInstallPath() . '/program/include');
include_once($incdir . '/iniset.php');
include($scriptfile);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Roundcube/Composer/PluginInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class PluginInstaller extends ExtensionInstaller

public function getVendorDir()
{
return getcwd() . DIRECTORY_SEPARATOR . 'plugins';
return $this->getRoundcubemailInstallPath() . DIRECTORY_SEPARATOR . 'plugins';
}

protected function confirmInstall($package_name)
Expand Down
2 changes: 1 addition & 1 deletion src/Roundcube/Composer/RoundcubeInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class RoundcubeInstaller implements PluginInterface
{
private $extentions = ['\Roundcube\Composer\PluginInstaller', '\Roundcube\Composer\SkinInstaller'];
private $extentions = [PluginInstaller::class, SkinInstaller::class];
private $installers = [];

public function activate(Composer $composer, IOInterface $io)
Expand Down
2 changes: 1 addition & 1 deletion src/Roundcube/Composer/SkinInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class SkinInstaller extends ExtensionInstaller

public function getVendorDir()
{
return getcwd() . DIRECTORY_SEPARATOR . 'skins';
return $this->getRoundcubemailInstallPath() . DIRECTORY_SEPARATOR . 'skins';
}

protected function confirmInstall($package_name)
Expand Down

0 comments on commit c22f795

Please sign in to comment.