Using better install path suggestions for apps
authorAlexander Ebert <ebert@woltlab.com>
Sun, 24 Jul 2016 19:03:57 +0000 (21:03 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 24 Jul 2016 19:03:57 +0000 (21:03 +0200)
wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php

index 0c6a735ceb55f3f78fa9f498b9647de39fd50843..3a12490b73bb7d0ad5d3f5a6ca9ed505f61e2fa5 100644 (file)
@@ -697,17 +697,33 @@ class PackageInstallationDispatcher {
                        $packageDir->setName('packageDir');
                        $packageDir->setLabel(WCF::getLanguage()->get('wcf.acp.package.packageDir.input'));
                        
-                       $defaultPath = FileUtil::addTrailingSlash(FileUtil::unifyDirSeparator(dirname(WCF_DIR)));
-                       // check if there is already an application
-                       $sql = "SELECT  COUNT(*)
-                               FROM    wcf".WCF_N."_package
-                               WHERE   packageDir = ?";
+                       // check if there are packages installed in a parent
+                       // directory of WCF, or if packages are below it
+                       $sql = "SELECT  packageDir
+                               FROM    wcf".WCF_N."_package
+                               WHERE   packageDir <> ''";
                        $statement = WCF::getDB()->prepareStatement($sql);
-                       $statement->execute(['../']);
-                       if ($statement->fetchSingleColumn()) {
-                               // use abbreviation
-                               $defaultPath .= strtolower(Package::getAbbreviation($this->getPackage()->package)) . '/';
+                       $statement->execute();
+                       
+                       $isParent = null;
+                       while ($column = $statement->fetchColumn()) {
+                               if ($isParent !== null) {
+                                       continue;
+                               }
+                               
+                               if (preg_match('~^\.\./[^\.]~', $column)) {
+                                       $isParent = false;
+                               }
+                               else if (mb_strpos($column, '.') !== 0) {
+                                       $isParent = true;
+                               }
+                       }
+                       
+                       $defaultPath = WCF_DIR;
+                       if ($isParent === false) {
+                               $defaultPath = dirname(WCF_DIR);
                        }
+                       $defaultPath = FileUtil::addTrailingSlash(FileUtil::unifyDirSeparator($defaultPath)) . Package::getAbbreviation($this->getPackage()->package) . '/';
                        
                        $packageDir->setValue($defaultPath);
                        $container->appendChild($packageDir);