[BUGFIX] Fatal Error in Page Tree filter
authorSteffen Ritter <info@rs-websystems.de>
Sun, 23 Oct 2011 21:34:50 +0000 (23:34 +0200)
committerXavier Perseguers <xavier@typo3.org>
Mon, 24 Oct 2011 17:06:53 +0000 (19:06 +0200)
When entering short numeric values in the Page Tree filter of a large
tree, a PHP Fatal Error can occur:
Call to a member function offsetExists() on a non-object.

Change-Id: I3734769a068e442359dc69d4262fd237f9384860
Resolves: #28297
Releases: 4.6, 4.5
Reviewed-on: http://review.typo3.org/5729
Reviewed-by: Benny Schimmer
Tested-by: Benny Schimmer
Reviewed-by: Xavier Perseguers
Tested-by: Xavier Perseguers
t3lib/tree/pagetree/class.t3lib_tree_pagetree_dataprovider.php

index 0a59a78..2becef3 100644 (file)
@@ -169,6 +169,8 @@ class t3lib_tree_pagetree_DataProvider extends t3lib_tree_AbstractDataProvider {
                $records = $this->getSubpages(-1, $searchFilter);
                if (!is_array($records) || !count($records)) {
                        return $nodeCollection;
+               } elseif (count($records) > 500) {
+                       return $nodeCollection;
                }
 
                $isNumericSearchFilter = (is_numeric($searchFilter) && $searchFilter > 0);
@@ -200,50 +202,53 @@ class t3lib_tree_pagetree_DataProvider extends t3lib_tree_AbstractDataProvider {
 
                                $rootlineElement = t3lib_tree_pagetree_Commands::getNodeRecord($rootlineElement['uid']);
                                $ident = intval($rootlineElement['sorting']) . intval($rootlineElement['uid']);
-                               if ($reference->offsetExists($ident)) {
+                               if ($reference && $reference->offsetExists($ident)) {
                                        /** @var $refNode t3lib_tree_pagetree_Node */
                                        $refNode = $reference->offsetGet($ident);
                                        $refNode->setExpanded(TRUE);
                                        $refNode->setLeaf(FALSE);
 
                                        $reference = $refNode->getChildNodes();
-                                       continue;
-                               }
-
-                               $refNode = t3lib_tree_pagetree_Commands::getNewNode($rootlineElement, $mountPoint);
-                               $replacement = '<span class="typo3-pagetree-filteringTree-highlight">$1</span>';
-                               if ($isNumericSearchFilter && intval($rootlineElement['uid']) === intval($searchFilter)) {
-                                       $text = str_replace('$1', $refNode->getText(), $replacement);
+                                       if ($reference == null) {
+                                               $reference = t3lib_div::makeInstance('t3lib_tree_pagetree_NodeCollection');
+                                               $refNode->setChildNodes($reference);
+                                       }
                                } else {
-                                       $text = preg_replace('/(' . $searchFilter . ')/i', $replacement, $refNode->getText());
-                               }
-
-                               $refNode->setText(
-                                       $text,
-                                       $refNode->getTextSourceField(),
-                                       $refNode->getPrefix(),
-                                       $refNode->getSuffix()
-                               );
-
-                               /** @var $childCollection t3lib_tree_pagetree_NodeCollection */
-                               $childCollection = t3lib_div::makeInstance('t3lib_tree_pagetree_NodeCollection');
+                                       $refNode = t3lib_tree_pagetree_Commands::getNewNode($rootlineElement, $mountPoint);
+                                       $replacement = '<span class="typo3-pagetree-filteringTree-highlight">$1</span>';
+                                       if ($isNumericSearchFilter && intval($rootlineElement['uid']) === intval($searchFilter)) {
+                                               $text = str_replace('$1', $refNode->getText(), $replacement);
+                                       } else {
+                                               $text = preg_replace('/(' . $searchFilter . ')/i', $replacement, $refNode->getText());
+                                       }
 
-                               if (($i +1) >= $amountOfRootlineElements) {
-                                       $childNodes = $this->getNodes($refNode, $mountPoint);
-                                       foreach ($childNodes as $childNode) {
-                                               /** @var $childNode t3lib_tree_pagetree_Node */
-                                               $childRecord = $childNode->getRecord();
-                                               $childIdent = intval($childRecord['sorting']) . intval($childRecord['uid']);
-                                               $childCollection->offsetSet($childIdent, $childNode);
+                                       $refNode->setText(
+                                               $text,
+                                               $refNode->getTextSourceField(),
+                                               $refNode->getPrefix(),
+                                               $refNode->getSuffix()
+                                       );
+
+                                       /** @var $childCollection t3lib_tree_pagetree_NodeCollection */
+                                       $childCollection = t3lib_div::makeInstance('t3lib_tree_pagetree_NodeCollection');
+
+                                       if (($i +1) >= $amountOfRootlineElements) {
+                                               $childNodes = $this->getNodes($refNode, $mountPoint);
+                                               foreach ($childNodes as $childNode) {
+                                                       /** @var $childNode t3lib_tree_pagetree_Node */
+                                                       $childRecord = $childNode->getRecord();
+                                                       $childIdent = intval($childRecord['sorting']) . intval($childRecord['uid']);
+                                                       $childCollection->offsetSet($childIdent, $childNode);
+                                               }
+                                               $refNode->setChildNodes($childNodes);
                                        }
-                                       $refNode->setChildNodes($childNodes);
-                               }
 
-                               $refNode->setChildNodes($childCollection);
-                               $reference->offsetSet($ident, $refNode);
-                               $reference->ksort();
+                                       $refNode->setChildNodes($childCollection);
+                                       $reference->offsetSet($ident, $refNode);
+                                       $reference->ksort();
 
-                               $reference = $childCollection;
+                                       $reference = $childCollection;
+                               }
                        }
                }