mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FIX: Remove some unnecessary ClassInfo calls in DataObjectSchema
This commit is contained in:
parent
d57dea0318
commit
91bd92df31
@ -138,11 +138,11 @@ class DataObjectSchema
|
||||
*/
|
||||
public function baseDataClass($class)
|
||||
{
|
||||
$class = ClassInfo::class_name($class);
|
||||
$current = $class;
|
||||
while ($next = get_parent_class($current)) {
|
||||
if ($next === DataObject::class) {
|
||||
return $current;
|
||||
// Only use ClassInfo::class_name() to format the class if we've not used get_parent_class()
|
||||
return ($current === $class) ? ClassInfo::class_name($current) : $current;
|
||||
}
|
||||
$current = $next;
|
||||
}
|
||||
@ -201,6 +201,11 @@ class DataObjectSchema
|
||||
$db = [];
|
||||
$classes = $uninherited ? [$class] : ClassInfo::ancestry($class);
|
||||
foreach ($classes as $tableClass) {
|
||||
// Skip irrelevant parent classes
|
||||
if (!is_subclass_of($tableClass, DataObject::class)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Find all fields on this class
|
||||
$fields = $this->databaseFields($tableClass, false);
|
||||
// Merge with composite fields
|
||||
@ -394,6 +399,10 @@ class DataObjectSchema
|
||||
*/
|
||||
public function classHasTable($class)
|
||||
{
|
||||
if (!is_subclass_of($class, DataObject::class)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$fields = $this->databaseFields($class, false);
|
||||
return !empty($fields);
|
||||
}
|
||||
|
@ -1341,10 +1341,7 @@ class DataObjectTest extends SapphireTest
|
||||
$this->assertFalse($schema->classHasTable(DataObject::class));
|
||||
$this->assertFalse($schema->classHasTable(ViewableData::class));
|
||||
|
||||
// Invalid class
|
||||
$this->expectException(ReflectionException::class);
|
||||
$this->expectExceptionMessage('Class ThisIsntADataObject does not exist');
|
||||
|
||||
/* Invalid class name */
|
||||
$this->assertFalse($schema->classHasTable("ThisIsntADataObject"));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user