[BUGFIX] Flush caches in group should throw exception 81/26981/9
authorHelmut Hummel <helmut.hummel@typo3.org>
Tue, 21 Jan 2014 14:31:51 +0000 (15:31 +0100)
committerFelix Oertel <mehl@foertel.com>
Sun, 4 May 2014 10:15:28 +0000 (12:15 +0200)
If a not existent cache group is specified
to the flushCachesInGroup methods, there is no
indication that actually nothing happened.

Throw an exception instead, so that calling code
can easily be fixed.

Resolves: #58465
Releases: 6.2
Change-Id: I9617fcee9abfa27a9cb76a3fd12543c62420e719
Reviewed-on: https://review.typo3.org/26981
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
Reviewed-by: Felix Oertel
Tested-by: Felix Oertel
typo3/sysext/core/Classes/Cache/CacheManager.php
typo3/sysext/core/Classes/Cache/Exception/NoSuchCacheGroupException.php [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/Cache/CacheManagerTest.php

index ff4b18d..3fd04a8 100644 (file)
@@ -23,6 +23,10 @@ namespace TYPO3\CMS\Core\Cache;
  *
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
+
+use TYPO3\CMS\Core\Cache\Exception\NoSuchCacheGroupException;
+
+
 /**
  * The Cache Manager
  *
@@ -165,6 +169,7 @@ class CacheManager implements \TYPO3\CMS\Core\SingletonInterface {
         *
         * @param string $groupIdentifier
         * @return void
+        * @throws NoSuchCacheGroupException
         * @api
         */
        public function flushCachesInGroup($groupIdentifier) {
@@ -175,6 +180,8 @@ class CacheManager implements \TYPO3\CMS\Core\SingletonInterface {
                                        $this->caches[$cacheIdentifier]->flush();
                                }
                        }
+               } else {
+                       throw new NoSuchCacheGroupException('No cache in the specified group \'' . $groupIdentifier . '\'', 1390334120);
                }
        }
 
@@ -185,6 +192,7 @@ class CacheManager implements \TYPO3\CMS\Core\SingletonInterface {
         * @param string $groupIdentifier
         * @param string $tag Tag to search for
         * @return void
+        * @throws NoSuchCacheGroupException
         * @api
         */
        public function flushCachesInGroupByTag($groupIdentifier, $tag) {
@@ -195,6 +203,8 @@ class CacheManager implements \TYPO3\CMS\Core\SingletonInterface {
                                        $this->caches[$cacheIdentifier]->flushByTag($tag);
                                }
                        }
+               } else {
+                       throw new NoSuchCacheGroupException('No cache in the specified group \'' . $groupIdentifier . '\'', 1390337129);
                }
        }
 
diff --git a/typo3/sysext/core/Classes/Cache/Exception/NoSuchCacheGroupException.php b/typo3/sysext/core/Classes/Cache/Exception/NoSuchCacheGroupException.php
new file mode 100644 (file)
index 0000000..115015a
--- /dev/null
@@ -0,0 +1,35 @@
+<?php
+namespace TYPO3\CMS\Core\Cache\Exception;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2014 TYPO3 CMS Team
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * A "No Such Cache Group" exception
+ *
+ * @api
+ */
+class NoSuchCacheGroupException extends \TYPO3\CMS\Core\Cache\Exception {
+
+
+}
index 1aabde7..83dd01e 100644 (file)
@@ -118,6 +118,24 @@ class CacheManagerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 
        /**
         * @test
+        * @expectedException \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheGroupException
+        */
+       public function flushCachesInGroupThrowsExceptionForNonExistingGroup() {
+               $manager = new \TYPO3\CMS\Core\Cache\CacheManager();
+               $manager->flushCachesInGroup('nonExistingGroup');
+       }
+
+       /**
+        * @test
+        * @expectedException \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheGroupException
+        */
+       public function flushCachesInGroupByTagThrowsExceptionForNonExistingGroup() {
+               $manager = new \TYPO3\CMS\Core\Cache\CacheManager();
+               $manager->flushCachesInGroup('nonExistingGroup', 'someTag');
+       }
+
+       /**
+        * @test
         */
        public function getCacheCreatesCacheInstanceWithGivenConfiguration() {
                $manager = new \TYPO3\CMS\Core\Cache\CacheManager();