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 }
0 commit comments