Fix calculation of paths during WCFSetup
authorTim Düsterhus <duesterhus@woltlab.com>
Tue, 2 Aug 2016 16:58:13 +0000 (18:58 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Tue, 2 Aug 2016 16:58:13 +0000 (18:58 +0200)
wcfsetup/install/files/lib/system/WCFSetup.class.php
wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php

index 6ebde3c0ee2aa4a0ff4446a2036a88fa7a19929a..9787bdc0529327ebb80a80aec8cdcbb4d58f3821 100644 (file)
@@ -512,7 +512,7 @@ class WCFSetup extends WCF {
                }
                else {
                        // resolve path relative to document root
-                       $relativePath = str_replace(FileUtil::unifyDirSeparator($_SERVER['DOCUMENT_ROOT']), '', FileUtil::unifyDirSeparator(INSTALL_SCRIPT_DIR));
+                       $relativePath = FileUtil::getRelativePath($_SERVER['DOCUMENT_ROOT'], INSTALL_SCRIPT_DIR);
                        foreach ($packages as $application => $packageData) {
                                self::$directories[$application] = $relativePath . ($application === 'wcf' ? '' : $packageData['directory'] . '/');
                        }
@@ -834,7 +834,7 @@ class WCFSetup extends WCF {
                        }
                        else {
                                // regular file
-                               $fileInserts[] = str_replace(WCF_DIR, '', $file);
+                               $fileInserts[] = preg_replace('/^'.preg_quote(WCF_DIR, '/').'/', '', $file);
                        }
                }
                
index 62dfd3336a1f995709995f89bd5c0cbdfcce0ec3..8dfbbdb181e9502116e846e5f1bd877d08b7ade8 100644 (file)
@@ -794,8 +794,19 @@ class PackageInstallationDispatcher {
                                        $wcfDomainPath = $row['domainPath'];
                                }
                                
-                               $documentRoot = str_replace($wcfDomainPath, '', FileUtil::unifyDirSeparator(WCF_DIR));
-                               $domainPath = str_replace($documentRoot, '', $packageDir);
+                               $documentRoot = '';
+                               
+                               // strip longest common suffix
+                               $a = strrev(FileUtil::unifyDirSeparator($wcfDomainPath));
+                               $b = strrev($documentRoot = FileUtil::unifyDirSeparator(WCF_DIR));
+                               for ($i = 0, $max = min(strlen($a), strlen($b)); $i < $max; $i++) {
+                                       if ($a{$i} !== $b{$i}) {
+                                               $documentRoot = substr(strrev($b), 0, -$i);
+                                               break;
+                                       }
+                               }
+                               
+                               $domainPath = FileUtil::addLeadingSlash(FileUtil::getRelativePath($documentRoot, $packageDir));
                                
                                // update application path
                                $application = new Application($this->getPackage()->packageID);