summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorblizzz <blizzz@arthur-schiwon.de>2018-09-26 15:22:30 +0200
committerGitHub <noreply@github.com>2018-09-26 15:22:30 +0200
commitff55bcdad5c2c36375c41eb641b87bc70967e384 (patch)
tree3101462c038f9a38c4b22b4b5e664eef9268177d /lib
parentfb17f1a26b3643744e09c89bf770bff5767b0ccb (diff)
parent3b7ac0c94d473b9458d39e4d0b1d4d33cd31c379 (diff)
downloadnextcloud-server-ff55bcdad5c2c36375c41eb641b87bc70967e384.tar.gz
nextcloud-server-ff55bcdad5c2c36375c41eb641b87bc70967e384.zip
Merge pull request #11150 from nextcloud/feature/noid/unit-test-find-webroot
Extract logic for webroot into method and add test
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Setup.php42
1 files changed, 31 insertions, 11 deletions
diff --git a/lib/private/Setup.php b/lib/private/Setup.php
index 25e0b4d8817..d5ccde6bba3 100644
--- a/lib/private/Setup.php
+++ b/lib/private/Setup.php
@@ -43,6 +43,7 @@ namespace OC;
use bantu\IniGetWrapper\IniGetWrapper;
use Exception;
+use InvalidArgumentException;
use OC\App\AppStore\Bundles\BundleFetcher;
use OC\Authentication\Token\DefaultTokenCleanupJob;
use OC\Authentication\Token\DefaultTokenProvider;
@@ -431,27 +432,46 @@ class Setup {
}
/**
- * Append the correct ErrorDocument path for Apache hosts
- * @return bool True when success, False otherwise
+ * Find webroot from config
+ *
+ * @param SystemConfig $config
+ * @return string
+ * @throws InvalidArgumentException when invalid value for overwrite.cli.url
*/
- public static function updateHtaccess() {
- $config = \OC::$server->getSystemConfig();
-
+ private static function findWebRoot(SystemConfig $config): string {
// For CLI read the value from overwrite.cli.url
- if(\OC::$CLI) {
+ if (\OC::$CLI) {
$webRoot = $config->getValue('overwrite.cli.url', '');
- if($webRoot === '') {
- return false;
+ if ($webRoot === '') {
+ throw new InvalidArgumentException('overwrite.cli.url is empty');
}
$webRoot = parse_url($webRoot, PHP_URL_PATH);
if ($webRoot === null) {
- return false;
+ throw new InvalidArgumentException('invalid value for overwrite.cli.url');
}
$webRoot = rtrim($webRoot, '/');
} else {
$webRoot = !empty(\OC::$WEBROOT) ? \OC::$WEBROOT : '/';
}
+ return $webRoot;
+ }
+
+ /**
+ * Append the correct ErrorDocument path for Apache hosts
+ *
+ * @return bool True when success, False otherwise
+ * @throws \OCP\AppFramework\QueryException
+ */
+ public static function updateHtaccess() {
+ $config = \OC::$server->getSystemConfig();
+
+ try {
+ $webRoot = self::findWebRoot($config);
+ } catch (InvalidArgumentException $e) {
+ return false;
+ }
+
$setupHelper = new \OC\Setup(
$config,
\OC::$server->getIniWrapper(),
@@ -467,10 +487,10 @@ class Setup {
$htaccessContent = explode($content, $htaccessContent, 2)[0];
//custom 403 error page
- $content.= "\nErrorDocument 403 ".$webRoot."/";
+ $content .= "\nErrorDocument 403 " . $webRoot . '/';
//custom 404 error page
- $content.= "\nErrorDocument 404 ".$webRoot."/";
+ $content .= "\nErrorDocument 404 " . $webRoot . '/';
// Add rewrite rules if the RewriteBase is configured
$rewriteBase = $config->getValue('htaccess.RewriteBase', '');