From: Alexander Ebert Date: Sun, 24 Jul 2016 19:03:57 +0000 (+0200) Subject: Using better install path suggestions for apps X-Git-Tag: 3.0.0_Beta_1~977 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=c03e5c92a1a305715ba43d321c93267dd5a6193b;p=GitHub%2FWoltLab%2FWCF.git Using better install path suggestions for apps --- diff --git a/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php b/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php index 0c6a735ceb..3a12490b73 100644 --- a/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php +++ b/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php @@ -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);