[BUGFIX] Refactor the initialize process of IconRegistry 06/46306/2
authorFrank Naegler <frank.naegler@typo3.org>
Mon, 25 Jan 2016 12:45:17 +0000 (13:45 +0100)
committerBenni Mack <benni@typo3.org>
Thu, 28 Jan 2016 22:41:22 +0000 (23:41 +0100)
Fix a problem in case of IconFactory not being fully initialized.

Resolves: #72926
Releases: master, 7.6
Change-Id: Iaeb511e4a2c681a135b2ec993a4b2f91e5bd53e8
Reviewed-on: https://review.typo3.org/46306
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/core/Classes/Imaging/IconRegistry.php

index 1639e7c..f899b75 100644 (file)
@@ -30,6 +30,11 @@ class IconRegistry implements \TYPO3\CMS\Core\SingletonInterface
     /**
      * @var bool
      */
+    protected $fullInitialized = false;
+
+    /**
+     * @var bool
+     */
     protected $tcaInitialized = false;
 
     /**
@@ -2640,29 +2645,45 @@ class IconRegistry implements \TYPO3\CMS\Core\SingletonInterface
     protected $defaultIconIdentifier = 'default-not-found';
 
     /**
-    * The constructor
-    */
+     * The constructor
+     */
     public function __construct()
     {
+        $this->initialize();
+    }
+
+    /**
+     * Initialize the registry
+     * This method can be called multiple times, depending on initialization status.
+     * In some cases e.g. TCA is not available, the method must be called multiple times.
+     */
+    protected function initialize()
+    {
         if (!$this->tcaInitialized && !empty($GLOBALS['TCA'])) {
             $this->registerTCAIcons();
         }
-        $this->registerFlags();
+        if (!$this->flagsInitialized) {
+            $this->registerFlags();
+        }
+        if ($this->tcaInitialized && $this->flagsInitialized) {
+            $this->fullInitialized = true;
+        }
     }
 
     /**
      * @param string $identifier
-     *
      * @return bool
      */
     public function isRegistered($identifier)
     {
+        if (!$this->fullInitialized) {
+            $this->initialize();
+        }
         return isset($this->icons[$identifier]);
     }
 
     /**
      * @param string $identifier
-     *
      * @return bool
      */
     public function isDeprecated($identifier)
@@ -2729,13 +2750,8 @@ class IconRegistry implements \TYPO3\CMS\Core\SingletonInterface
      */
     public function getIconConfigurationByIdentifier($identifier)
     {
-        // In some cases TCA is not available, auto register TCA icons
-        // only the first time the TCA is available
-        if (!$this->tcaInitialized && !empty($GLOBALS['TCA'])) {
-            $this->registerTCAIcons();
-        }
-        if ($this->flagsInitialized) {
-            $this->registerFlags();
+        if (!$this->fullInitialized) {
+            $this->initialize();
         }
         if (!$this->isRegistered($identifier)) {
             throw new Exception('Icon with identifier "' . $identifier . '" is not registered"', 1437425804);
@@ -2770,6 +2786,9 @@ class IconRegistry implements \TYPO3\CMS\Core\SingletonInterface
      */
     public function getAllRegisteredIconIdentifiers()
     {
+        if (!$this->fullInitialized) {
+            $this->initialize();
+        }
         return array_keys($this->icons);
     }
 
@@ -2805,11 +2824,6 @@ class IconRegistry implements \TYPO3\CMS\Core\SingletonInterface
      */
     protected function registerTCAIcons()
     {
-        // if TCA is not available, e.g. for some unit test, return directly
-        if (!is_array($GLOBALS['TCA'])) {
-            return;
-        }
-
         $resultArray = array();
 
         $tcaTables = array_keys($GLOBALS['TCA']);
@@ -2820,7 +2834,7 @@ class IconRegistry implements \TYPO3\CMS\Core\SingletonInterface
                 $tcaCtrl = $GLOBALS['TCA'][$tableName]['ctrl'];
                 $icon = null;
                 $iconIdentifier = 'tcarecords-' . $tableName . '-default';
-                if ($this->isRegistered($iconIdentifier)) {
+                if (isset($this->icons[$iconIdentifier])) {
                     continue;
                 }
                 if (isset($tcaCtrl['iconfile'])) {