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