From b2098a3ebf3987d885c85ce6f9f74c7150b6615c Mon Sep 17 00:00:00 2001 From: Hamish Friedlander Date: Fri, 3 May 2013 09:17:38 +1200 Subject: [PATCH] FIX Throw error if trying to add a table-less DataObject class to index Its impossible for SearchUpdater#handle_manipulation to figure out the difference between writing to a table-less class (like Page if theres no $db set) and the table-having parent (like SiteTree) because it only examines the DB manipulation This meant if you tried to index Page without setting $db fields, only subclasses that did have $db fields would be indexed We cant fix, but we can throw an error if you try to do that --- code/search/SearchIndex.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/code/search/SearchIndex.php b/code/search/SearchIndex.php index 1892302..15fe830 100644 --- a/code/search/SearchIndex.php +++ b/code/search/SearchIndex.php @@ -187,6 +187,10 @@ abstract class SearchIndex extends ViewableData { throw new Exception('Can\'t add class to Index after fields have already been added'); } + if (!DataObject::has_own_table($class)) { + throw new InvalidArgumentException('Can\'t add classes which don\'t have data tables (no $db or $has_one set on the class)'); + } + $options = array_merge(array( 'include_children' => true ), $options);