From b78625e0ae34514d7c0ea4eae3f3fd4e64b1c9a8 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Tue, 10 May 2016 17:19:45 +0200 Subject: [PATCH] Add repair step for copying the RewriteBase --- lib/private/repair.php | 2 + .../repair/copyrewritebasetoconfig.php | 89 +++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 lib/private/repair/copyrewritebasetoconfig.php diff --git a/lib/private/repair.php b/lib/private/repair.php index 63b569b2ed3..d3d2eafe92e 100644 --- a/lib/private/repair.php +++ b/lib/private/repair.php @@ -34,6 +34,7 @@ use OC\Repair\AssetCache; use OC\Repair\BrokenUpdaterRepair; use OC\Repair\CleanTags; use OC\Repair\Collation; +use OC\Repair\CopyRewriteBaseToConfig; use OC\Repair\DropOldJobs; use OC\Repair\OldGroupMembershipShares; use OC\Repair\RemoveGetETagEntries; @@ -144,6 +145,7 @@ class Repair extends BasicEmitter { new Collation(\OC::$server->getConfig(), $connection), new SqliteAutoincrement($connection), new SearchLuceneTables(), + new CopyRewriteBaseToConfig(\OC::$server->getConfig()), ]; //There is no need to delete all previews on every single update diff --git a/lib/private/repair/copyrewritebasetoconfig.php b/lib/private/repair/copyrewritebasetoconfig.php new file mode 100644 index 00000000000..e5e03f9d437 --- /dev/null +++ b/lib/private/repair/copyrewritebasetoconfig.php @@ -0,0 +1,89 @@ + + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +namespace OC\Repair; + +use OC\Hooks\BasicEmitter; +use OC\RepairStep; +use OCP\IConfig; + +/** + * Class CopyRewriteBaseToConfig + * + * @package OC\Repair + */ +class CopyRewriteBaseToConfig extends BasicEmitter implements RepairStep { + /** @var IConfig */ + private $config; + + /** + * @param IConfig $config + */ + public function __construct(IConfig $config) { + $this->config = $config; + } + + /** + * {@inheritdoc} + */ + public function getName() { + return 'Copy the rewrite base to the config file'; + } + + /** + * {@inheritdoc} + */ + public function run() { + $ocVersionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0'); + + $versionsToApplyFrom = [ + '9.0.0.19', + '9.0.1.3', + '9.0.2.2', + ]; + + if(in_array($ocVersionFromBeforeUpdate, $versionsToApplyFrom, true)) { + // For CLI read the value from overwrite.cli.url + if(\OC::$CLI) { + $webRoot = $this->config->getSystemValue('overwrite.cli.url', ''); + if($webRoot === '') { + return; + } + $webRoot = parse_url($webRoot, PHP_URL_PATH); + $webRoot = rtrim($webRoot, '/'); + } else { + $webRoot = !empty(\OC::$WEBROOT) ? \OC::$WEBROOT : '/'; + } + + // ownCloud may be configured to live at the root folder without a + // trailing slash being specified. In this case manually set the + // rewrite base to `/` + $rewriteBase = $webRoot; + if($webRoot === '') { + $rewriteBase = '/'; + } + + $this->config->setSystemValue('htaccess.RewriteBase', $rewriteBase); + \OC\Setup::updateHtaccess(); + } + + } +}