From 0e6a3175162a1312c1035c4a2630a26f8c26d561 Mon Sep 17 00:00:00 2001
From: Arthur Schiwon <blizzz@arthur-schiwon.de>
Date: Wed, 25 Apr 2018 14:57:08 +0200
Subject: [PATCH] revert Log's dependency to SystemConfig to work during
 Installation

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
---
 lib/private/Log.php            | 13 ++++++-------
 lib/private/Log/LogFactory.php |  9 ++++++++-
 lib/private/Server.php         |  3 +--
 tests/lib/LoggerTest.php       |  4 ++--
 4 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/lib/private/Log.php b/lib/private/Log.php
index 099cc56776b..69705c49e87 100644
--- a/lib/private/Log.php
+++ b/lib/private/Log.php
@@ -39,7 +39,6 @@ use InterfaSys\LogNormalizer\Normalizer;
 
 use OC\Log\ExceptionSerializer;
 use OCP\Log\IFileBased;
-use OCP\IConfig;
 use OCP\Log\IWriter;
 use OCP\ILogger;
 use OCP\Support\CrashReport\IRegistry;
@@ -59,7 +58,7 @@ class Log implements ILogger {
 	/** @var IWriter */
 	private $logger;
 
-	/** @var IConfig */
+	/** @var SystemConfig */
 	private $config;
 
 	/** @var boolean|null cache the result of the log condition check for the request */
@@ -73,14 +72,14 @@ class Log implements ILogger {
 
 	/**
 	 * @param IWriter $logger The logger that should be used
-	 * @param IConfig $config the system config object
+	 * @param SystemConfig $config the system config object
 	 * @param Normalizer|null $normalizer
 	 * @param IRegistry|null $registry
 	 */
-	public function __construct(IWriter $logger, IConfig $config = null, $normalizer = null, IRegistry $registry = null) {
+	public function __construct(IWriter $logger, SystemConfig $config = null, $normalizer = null, IRegistry $registry = null) {
 		// FIXME: Add this for backwards compatibility, should be fixed at some point probably
 		if ($config === null) {
-			$config = \OC::$server->getConfig();
+			$config = \OC::$server->getSystemConfig();
 		}
 
 		$this->config = $config;
@@ -258,7 +257,7 @@ class Log implements ILogger {
 		}
 
 		if (isset($context['app'])) {
-			$logCondition = $this->config->getSystemValue('log.condition', []);
+			$logCondition = $this->config->getValue('log.condition', []);
 			$app = $context['app'];
 
 			/**
@@ -272,7 +271,7 @@ class Log implements ILogger {
 			}
 		}
 
-		return min($this->config->getSystemValue('loglevel', ILogger::WARN), ILogger::FATAL);
+		return min($this->config->getValue('loglevel', ILogger::WARN), ILogger::FATAL);
 	}
 
 	/**
diff --git a/lib/private/Log/LogFactory.php b/lib/private/Log/LogFactory.php
index c1a4d00ceaa..63f08a32320 100644
--- a/lib/private/Log/LogFactory.php
+++ b/lib/private/Log/LogFactory.php
@@ -23,6 +23,7 @@
 
 namespace OC\Log;
 
+use OC\AllConfig;
 use OC\Log;
 use OCP\ILogger;
 use OCP\IServerContainer;
@@ -60,8 +61,14 @@ class LogFactory implements ILogFactory {
 	}
 
 	public function getCustomLogger(string $path):ILogger {
+		$systemConfig = null;
+		$iconfig = $this->c->getConfig();
+		if($iconfig instanceof AllConfig) {
+			// Log is bound to SystemConfig, but fetches it from \OC::$server if not supplied
+			$systemConfig = $iconfig->getSystemConfig();
+		}
 		$log = $this->buildLogFile($path);
-		return new Log($log, $this->c->getConfig());
+		return new Log($log, $systemConfig);
 	}
 
 	protected function buildLogFile(string $logFile = ''):File {
diff --git a/lib/private/Server.php b/lib/private/Server.php
index 05772555a03..c744ba37ded 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -550,10 +550,9 @@ class Server extends ServerContainer implements IServerContainer {
 			$logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
 			$factory = new LogFactory($c);
 			$logger = $factory->get($logType);
-			$config = $this->getConfig();
 			$registry = $c->query(\OCP\Support\CrashReport\IRegistry::class);
 
-			return new Log($logger, $config, null, $registry);
+			return new Log($logger, $this->getSystemConfig(), null, $registry);
 		});
 		$this->registerAlias('Logger', \OCP\ILogger::class);
 
diff --git a/tests/lib/LoggerTest.php b/tests/lib/LoggerTest.php
index 9f226a395b6..83cb87b8733 100644
--- a/tests/lib/LoggerTest.php
+++ b/tests/lib/LoggerTest.php
@@ -30,7 +30,7 @@ class LoggerTest extends TestCase implements IWriter {
 		parent::setUp();
 
 		$this->logs = [];
-		$this->config = $this->createMock(\OCP\IConfig::class);
+		$this->config = $this->createMock(\OC\SystemConfig::class);
 		$this->registry = $this->createMock(\OCP\Support\CrashReport\IRegistry::class);
 		$this->logger = new Log($this, $this->config, null, $this->registry);
 	}
@@ -45,7 +45,7 @@ class LoggerTest extends TestCase implements IWriter {
 
 	public function testAppCondition() {
 		$this->config->expects($this->any())
-			->method('getSystemValue')
+			->method('getValue')
 			->will(($this->returnValueMap([
 				['loglevel', ILogger::WARN, ILogger::WARN],
 				['log.condition', [], ['apps' => ['files']]]
-- 
GitLab