Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace getcwd() with Roundcubemail path from composer API #47

Merged
merged 2 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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