]> git.mxchange.org Git - friendica.git/commitdiff
Fix App\Mode determination
authorPhilipp Holzer <admin+github@philipp.info>
Sun, 21 Jul 2019 12:40:50 +0000 (14:40 +0200)
committerPhilipp Holzer <admin+github@philipp.info>
Sun, 21 Jul 2019 12:40:50 +0000 (14:40 +0200)
src/App/Mode.php
tests/src/App/ModeTest.php

index 7f5c31c4bb336c7f733f1a3b8d0ac7f085c534da..6cb79b6edd4532ac25d4ffeb9791162b82b4ee33 100644 (file)
@@ -13,9 +13,9 @@ use Friendica\Util\BasePath;
  */
 class Mode
 {
-       const LOCALCONFIGPRESENT = 1;
-       const DBAVAILABLE = 2;
-       const DBCONFIGAVAILABLE = 4;
+       const LOCALCONFIGPRESENT  = 1;
+       const DBAVAILABLE         = 2;
+       const DBCONFIGAVAILABLE   = 4;
        const MAINTENANCEDISABLED = 8;
 
        /***
@@ -58,7 +58,7 @@ class Mode
         *
         * @return Mode returns itself
         *
-        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        * @throws \Exception
         */
        public function determine($basePath = null)
        {
@@ -88,8 +88,10 @@ class Mode
 
                $this->mode |= Mode::DBCONFIGAVAILABLE;
 
-               if ($this->configCache->get('system', 'maintenance') ||
-                   $this->database->selectFirst('config', ['v'], ['cat' => 'system', 'k' => 'maintenance'])) {
+               if (!empty($this->configCache->get('system', 'maintenance')) ||
+                   // Don't use Config or Configuration here because we're possibly BEFORE initializing the Configuration,
+                   // so this could lead to a dependency circle
+                   !empty($this->database->selectFirst('config', ['v'], ['cat' => 'system', 'k' => 'maintenance'])['v'])) {
                        return $this;
                }
 
@@ -134,4 +136,4 @@ class Mode
                       $this->has(Mode::DBCONFIGAVAILABLE) &&
                       $this->has(Mode::MAINTENANCEDISABLED);
        }
-}
\ No newline at end of file
+}
index b8d2e5136b15fa4825cbd2cfd560a2e0e17d8216..06aad106614f578c435490baad5c4b34a36020f5 100644 (file)
@@ -125,7 +125,31 @@ class ModeTest extends MockedTest
                                      ->andReturn(false)->once();
                $this->databaseMock->shouldReceive('selectFirst')
                                   ->with('config', ['v'], ['cat' => 'system', 'k' => 'maintenance'])
-                                  ->andReturn(false)->once();
+                                  ->andReturn(['v' => null])->once();
+
+               $mode = new Mode($this->basePathMock, $this->databaseMock, $this->configCacheMock);
+               $mode->determine();
+
+               $this->assertTrue($mode->isNormal());
+               $this->assertFalse($mode->isInstall());
+
+               $this->assertTrue($mode->has(Mode::DBCONFIGAVAILABLE));
+               $this->assertTrue($mode->has(Mode::MAINTENANCEDISABLED));
+       }
+
+       /**
+        * Test explicit disabled maintenance (in case you manually disable it)
+        */
+       public function testDisabledMaintenance()
+       {
+               $this->databaseMock->shouldReceive('connected')->andReturn(true)->once();
+               $this->databaseMock->shouldReceive('fetchFirst')
+                                  ->with('SHOW TABLES LIKE \'config\'')->andReturn(true)->once();
+               $this->configCacheMock->shouldReceive('get')->with('system', 'maintenance')
+                                     ->andReturn(false)->once();
+               $this->databaseMock->shouldReceive('selectFirst')
+                                  ->with('config', ['v'], ['cat' => 'system', 'k' => 'maintenance'])
+                                  ->andReturn(['v' => '0'])->once();
 
                $mode = new Mode($this->basePathMock, $this->databaseMock, $this->configCacheMock);
                $mode->determine();