[BUGFIX] Instantiate Logger on cache backend creation 72/61472/5
authorAnja Leichsenring <aleichsenring@ab-softlab.de>
Wed, 7 Aug 2019 11:38:15 +0000 (13:38 +0200)
committerAndreas Fernandez <a.fernandez@scripting-base.de>
Thu, 8 Aug 2019 11:29:58 +0000 (13:29 +0200)
Cache backends are created via new, not using GU::makeInstance.
So it happened no cache has been initialized, causing errors upon
calls for the logger.
Putting cache creation into the cache backend constructor solves
the problem and makes sure the logger is always available.

Resolves: #88775
Resolves: #87820
Releases: master, 9.5
Change-Id: I4005b812e96c028528f3740c581b8086cfc592f0
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/61472
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
typo3/sysext/core/Classes/Cache/Backend/AbstractBackend.php
typo3/sysext/core/Tests/Functional/Cache/Backend/RedisBackendTest.php
typo3/sysext/core/Tests/Unit/Cache/Backend/AbstractBackendTest.php
typo3/sysext/core/Tests/Unit/Cache/Backend/ApcuBackendTest.php
typo3/sysext/core/Tests/Unit/Cache/Backend/FileBackendTest.php
typo3/sysext/core/Tests/Unit/Cache/Backend/TransientMemoryBackendTest.php
typo3/sysext/core/Tests/Unit/Cache/Backend/Typo3DatabaseBackendTest.php

index 7c9132a..ef92327 100644 (file)
@@ -16,6 +16,8 @@ namespace TYPO3\CMS\Core\Cache\Backend;
 
 use Psr\Log\LoggerAwareInterface;
 use Psr\Log\LoggerAwareTrait;
+use TYPO3\CMS\Core\Log\LogManager;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
  * An abstract caching backend
@@ -75,6 +77,12 @@ abstract class AbstractBackend implements BackendInterface, LoggerAwareInterface
                 }
             }
         }
+        if ($this->logger === null) {
+            $this->setLogger(
+                GeneralUtility::makeInstance(LogManager::class)
+                    ->getLogger(__CLASS__)
+            );
+        }
     }
 
     /**
index b6949d4..5828058 100644 (file)
@@ -13,6 +13,8 @@ namespace TYPO3\CMS\Core\Tests\Functional\Cache\Backend;
  *
  * The TYPO3 project - inspiring people to share!
  */
+
+use Psr\Log\LoggerInterface;
 use TYPO3\CMS\Core\Cache\Backend\RedisBackend;
 use TYPO3\CMS\Core\Cache\Exception\InvalidDataException;
 use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
@@ -59,7 +61,9 @@ class RedisBackendTest extends FunctionalTestCase
         $frontendProphecy = $this->prophesize(FrontendInterface::class);
         $frontendProphecy->getIdentifier()->willReturn('pages');
 
+        $GLOBALS['TYPO3_CONF_VARS']['LOG'] = 'only needed for logger initialisation';
         $subject = new RedisBackend('Testing', $backendOptions);
+        $subject->setLogger($this->prophesize(LoggerInterface::class)->reveal());
         $subject->setCache($frontendProphecy->reveal());
         $subject->initializeObject();
         $subject->flush();
index 9bf5a4d..e77577c 100644 (file)
@@ -22,6 +22,8 @@ use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
  */
 class AbstractBackendTest extends UnitTestCase
 {
+    protected $resetSingletonInstances = true;
+
     /**
      * @test
      */
index 83a7bc1..efb2f6e 100644 (file)
@@ -28,6 +28,8 @@ use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
  */
 class ApcuBackendTest extends UnitTestCase
 {
+    protected $resetSingletonInstances = true;
+
     /**
      * Set up
      */
index f6963c0..541624e 100644 (file)
@@ -31,6 +31,8 @@ use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
  */
 class FileBackendTest extends UnitTestCase
 {
+    protected $resetSingletonInstances = true;
+
     /**
      * Sets up this testcase
      * @throws \org\bovigo\vfs\vfsStreamException
index 627b062..15debab 100644 (file)
@@ -21,6 +21,8 @@ use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
  */
 class TransientMemoryBackendTest extends UnitTestCase
 {
+    protected $resetSingletonInstances = true;
+
     /**
      * @test
      */
index f13bb4d..16f04ae 100644 (file)
@@ -30,6 +30,8 @@ use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
  */
 class Typo3DatabaseBackendTest extends UnitTestCase
 {
+    protected $resetSingletonInstances = true;
+
     /**
      * @test
      */