]> source.dussan.org Git - nextcloud-server.git/commitdiff
Workaround to fix the too early init dilemma
authorMorris Jobke <hey@morrisjobke.de>
Thu, 4 Dec 2014 08:35:01 +0000 (09:35 +0100)
committerMorris Jobke <hey@morrisjobke.de>
Mon, 8 Dec 2014 21:33:36 +0000 (22:33 +0100)
* this needs to be properly fixed by a proper organisation of the base.php
* introduced fixDIInit() in AllConfig that moves the injection
  of DatabaseConnection to a later point in time
* problems mostly because of the autoconfig setup

lib/private/allconfig.php
lib/private/server.php
tests/lib/allconfig.php

index ed4378cfc44849c2e24bf1070e45e47e93397066..ea919006f968d6a61e5e5e95eb2a8da970646a1b 100644 (file)
@@ -46,9 +46,27 @@ class AllConfig implements \OCP\IConfig {
        /**
         * @param SystemConfig $systemConfig
         */
-       function __construct(SystemConfig $systemConfig, IDBConnection $connection) {
+       function __construct(SystemConfig $systemConfig) {
                $this->systemConfig = $systemConfig;
-               $this->connection = $connection;
+       }
+
+       /**
+        * TODO - FIXME This fixes an issue with base.php that cause cyclic
+        * dependencies, especially with autoconfig setup
+        *
+        * Replace this by properly injected database connection. Currently the
+        * base.php triggers the getDatabaseConnection too early which causes in
+        * autoconfig setup case a too early distributed database connection and
+        * the autoconfig then needs to reinit all already initialized dependencies
+        * that use the database connection.
+        *
+        * otherwise a SQLite database is created in the wrong directory
+        * because the database connection was created with an uninitialized config
+        */
+       private function fixDIInit() {
+               if($this->connection === null) {
+                       $this->connection = \OC::$server->getDatabaseConnection();
+               }
        }
 
        /**
@@ -145,6 +163,9 @@ class AllConfig implements \OCP\IConfig {
         * @throws \OCP\PreConditionNotMetException if a precondition is specified and is not met
         */
        public function setUserValue($userId, $appName, $key, $value, $preCondition = null) {
+               // TODO - FIXME
+               $this->fixDIInit();
+
                // Check if the key does exist
                $sql  = 'SELECT `configvalue` FROM `*PREFIX*preferences` '.
                                'WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?';
@@ -232,6 +253,9 @@ class AllConfig implements \OCP\IConfig {
         * @param string $key the key under which the value is being stored
         */
        public function deleteUserValue($userId, $appName, $key) {
+               // TODO - FIXME
+               $this->fixDIInit();
+
                $sql  = 'DELETE FROM `*PREFIX*preferences` '.
                                'WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?';
                $this->connection->executeUpdate($sql, array($userId, $appName, $key));
@@ -247,6 +271,9 @@ class AllConfig implements \OCP\IConfig {
         * @param string $userId the userId of the user that we want to remove all values from
         */
        public function deleteAllUserValues($userId) {
+               // TODO - FIXME
+               $this->fixDIInit();
+
                $sql  = 'DELETE FROM `*PREFIX*preferences` '.
                        'WHERE `userid` = ?';
                $this->connection->executeUpdate($sql, array($userId));
@@ -260,6 +287,9 @@ class AllConfig implements \OCP\IConfig {
         * @param string $appName the appName of the app that we want to remove all values from
         */
        public function deleteAppFromAllUsers($appName) {
+               // TODO - FIXME
+               $this->fixDIInit();
+
                $sql  = 'DELETE FROM `*PREFIX*preferences` '.
                                'WHERE `appid` = ?';
                $this->connection->executeUpdate($sql, array($appName));
@@ -279,6 +309,9 @@ class AllConfig implements \OCP\IConfig {
         *     ]
         */
        private function getUserValues($userId) {
+               // TODO - FIXME
+               $this->fixDIInit();
+
                if (isset($this->userCache[$userId])) {
                        return $this->userCache[$userId];
                }
@@ -305,6 +338,9 @@ class AllConfig implements \OCP\IConfig {
         * @return array Mapped values: userId => value
         */
        public function getUserValueForUsers($appName, $key, $userIds) {
+               // TODO - FIXME
+               $this->fixDIInit();
+
                if (empty($userIds) || !is_array($userIds)) {
                        return array();
                }
@@ -333,7 +369,6 @@ class AllConfig implements \OCP\IConfig {
                }
 
                return $userValues;
-
        }
 
        /**
index 28406d873193f91efc2ab57a34f102819c3350b9..5a1e955bdd2691964da8993bb73b696aa4d33fe6 100644 (file)
@@ -168,8 +168,7 @@ class Server extends SimpleContainer implements IServerContainer {
                });
                $this->registerService('AllConfig', function (Server $c) {
                        return new \OC\AllConfig(
-                               $c->getSystemConfig(),
-                               $c->getDatabaseConnection()
+                               $c->getSystemConfig()
                        );
                });
                $this->registerService('SystemConfig', function ($c) {
index 63ee60f20788be0d9233978bed81fec683b068b9..7f8ad5ec22171edace56b3bd207e88b72a87748a 100644 (file)
@@ -166,6 +166,9 @@ class TestAllConfig extends \Test\TestCase {
        }
 
        public function testSetUserValueUnchanged() {
+               // TODO - FIXME until the dependency injection is handled properly (in AllConfig)
+               $this->markTestSkipped('Skipped because this is just testable if database connection can be injected');
+
                $resultMock = $this->getMockBuilder('\Doctrine\DBAL\Driver\Statement')
                        ->disableOriginalConstructor()->getMock();
                $resultMock->expects($this->once())