[BUGFIX] StorageRepository should ignore not found driver class
authorGeorg Ringer <mail@ringerge.org>
Tue, 14 Aug 2012 04:35:07 +0000 (06:35 +0200)
committerSteffen Ritter <info@rs-websystems.de>
Wed, 10 Oct 2012 13:36:29 +0000 (15:36 +0200)
If a driver doesn't exist anymore, the storage repository shouldn't load
it.

Most drivers will be implemented by extensions but if this extension is
deactived, the StorageRepository still tries to load this driver which is
not possible anymore and this ends in an uncaught exception in BE.
Therefore it should be checked if an implementation is available.

Change-Id: Ib71bef82a53096746cff4bd9577d6adbeae90ac5
Fixes: #39789
Releases: 6.0
Reviewed-on: http://review.typo3.org/13643
Reviewed-by: Steffen Ritter
Tested-by: Steffen Ritter
typo3/sysext/core/Classes/Resource/Driver/DriverRegistry.php
typo3/sysext/core/Classes/Resource/StorageRepository.php
typo3/sysext/core/Tests/Unit/Resource/Driver/DriverRegistryTest.php

index 25dadbf..a2eada1 100644 (file)
@@ -127,6 +127,15 @@ class DriverRegistry implements \TYPO3\CMS\Core\SingletonInterface {
                return $this->drivers[$shortName];
        }
 
+       /**
+        * Checks if the given driver exists
+        *
+        * @param string $shortName Name of the driver
+        * @return boolean TRUE if the driver exists, FALSE otherwise
+        */
+       public function driverExists($shortName) {
+               return array_key_exists($shortName, $this->drivers);
+       }
 }
 
 
index d29198d..9a4eff8 100644 (file)
@@ -52,12 +52,27 @@ class StorageRepository extends \TYPO3\CMS\Core\Resource\AbstractRepository {
        protected $typeField = 'type';
 
        /**
+        * @var \TYPO3\CMS\Core\Log\Logger
+        */
+       protected $logger;
+
+       public function __construct() {
+               parent::__construct();
+
+               /** @var $logManager \TYPO3\CMS\Core\Log\LogManager */
+               $logManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Core\Log\LogManager');
+               $this->logger = $logManager->getLogger(__CLASS__);
+       }
+
+       /**
         * Finds storages by type.
         *
         * @param string $storageType
         * @return \TYPO3\CMS\Core\Resource\ResourceStorage[]
         */
        public function findByStorageType($storageType) {
+               /** @var $driverRegistry \TYPO3\CMS\Core\Resource\Driver\DriverRegistry */
+               $driverRegistry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Core\Resource\Driver\DriverRegistry');
                $storageObjects = array();
                $whereClause = $this->typeField . ' = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($storageType, $this->table);
                $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
@@ -66,7 +81,14 @@ class StorageRepository extends \TYPO3\CMS\Core\Resource\AbstractRepository {
                        $whereClause . $this->getWhereClauseForEnabledFields()
                );
                while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
-                       $storageObjects[] = $this->createDomainObject($row);
+                       if ($driverRegistry->driverExists($row['driver'])) {
+                               $storageObjects[] = $this->createDomainObject($row);
+                       } else {
+                               $this->logger->warning(
+                                       sprintf('Could not instantiate storage "%s" because of missing driver.', array($row['name'])),
+                                       $row
+                               );
+                       }
                }
                $GLOBALS['TYPO3_DB']->sql_free_result($res);
                return $storageObjects;
@@ -101,8 +123,19 @@ class StorageRepository extends \TYPO3\CMS\Core\Resource\AbstractRepository {
                        $this->table,
                        ($whereClause ? $whereClause : '1=1') . $this->getWhereClauseForEnabledFields()
                );
+
+               /** @var $driverRegistry \TYPO3\CMS\Core\Resource\Driver\DriverRegistry */
+               $driverRegistry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Core\Resource\Driver\DriverRegistry');
+
                while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
-                       $storageObjects[] = $this->createDomainObject($row);
+                       if ($driverRegistry->driverExists($row['driver'])) {
+                               $storageObjects[] = $this->createDomainObject($row);
+                       } else {
+                               $this->logger->warning(
+                                       sprintf('Could not instantiate storage "%s" because of missing driver.', array($row['name'])),
+                                       $row
+                               );
+                       }
                }
                $GLOBALS['TYPO3_DB']->sql_free_result($res);
                return $storageObjects;
index bcac4e0..34e39e2 100644 (file)
@@ -115,6 +115,32 @@ class DriverRegistryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $this->assertEquals($className, $this->fixture->getDriverClass($shortName));
        }
 
+       /**
+        * @test
+        */
+       public function driverExistsReturnsTrueForAllExistingDrivers() {
+               $className = $this->getMockClass('TYPO3\\CMS\\Core\\Resource\\Driver\\AbstractDriver');
+               $shortName = uniqid();
+               $GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['registeredDrivers'] = array(
+                       $shortName => array(
+                               'class' => $className
+                       )
+               );
+               $this->initializeFixture();
+               $this->assertTrue($this->fixture->driverExists($shortName));
+               $this->assertFalse($this->fixture->driverExists(uniqid()));
+       }
+
+       /**
+        * @test
+        */
+       public function driverExistsReturnsFalseIfDriverDoesNotExist() {
+               $GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['registeredDrivers'] = array(
+               );
+               $this->initializeFixture();
+               $this->assertFalse($this->fixture->driverExists(uniqid()));
+       }
+
 }
 
 ?>
\ No newline at end of file