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
This commit is contained in:
Hamish Friedlander 2013-05-03 09:17:38 +12:00
parent f9998a2266
commit b2098a3ebf
1 changed files with 4 additions and 0 deletions

View File

@ -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);