Fix category validation in AbstractCategorizedACPSearchResultProvider
authorMatthias Schmidt <gravatronics@live.com>
Sun, 27 Nov 2016 13:22:13 +0000 (14:22 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 27 Nov 2016 13:22:13 +0000 (14:22 +0100)
wcfsetup/install/files/lib/system/search/acp/AbstractCategorizedACPSearchResultProvider.class.php

index b906b13d85f057a4e8242fc517f5ab13810a0532..b47c258e62740aa27d42bc77f18aa97ff6673234 100644 (file)
@@ -109,9 +109,16 @@ abstract class AbstractCategorizedACPSearchResultProvider extends AbstractACPSea
                
                // create level 2 categories
                $topCategories = [];
-               foreach ($this->categories as $category) {
-                       if ($category->parentCategoryName && in_array($category->parentCategoryName, $this->topCategories)) {
-                               $topCategories[] = $category->categoryName;
+               foreach ($this->categories as $key => $category) {
+                       if ($category->parentCategoryName) {
+                               // check if parent category exists, thus if it is valid; if is does not exist, then all
+                               // child categories are also invalid
+                               if (!isset($this->categories[$category->parentCategoryName])) {
+                                       unset($this->categories[$key]);
+                               }
+                               else if (in_array($category->parentCategoryName, $this->topCategories)) {
+                                       $topCategories[] = $category->categoryName;
+                               }
                        }
                }