FIX Recent patch to DataObject#db changed API which broke core

This commit is contained in:
Hamish Friedlander 2013-07-04 16:31:57 +12:00
parent a862b4da99
commit ca63e33c19
2 changed files with 14 additions and 9 deletions

View File

@ -1661,16 +1661,11 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
/**
* Return all of the database fields defined in self::$db and all the parent classes.
* Doesn't include any fields specified by self::$has_one. Use $this->has_one() to get these fields
* Also returns "base" fields like "Created", "LastEdited", et cetera.
*
* @param string $fieldName Limit the output to a specific field name
* @return array The database fields
*/
public function db($fieldName = null) {
if ($fieldName && array_key_exists($fieldName, self::$fixed_fields)) {
return self::$fixed_fields[$fieldName];
}
$classes = ClassInfo::ancestry($this);
$good = false;
$items = array();
@ -1709,10 +1704,6 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
}
}
if (!$fieldName) {
// trying to get all fields, so add the fixed fields to return value
$items = array_merge(self::$fixed_fields, $items);
}
return $items;
}
@ -2675,6 +2666,9 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
$val = get_class($this);
return DBField::create_field('Varchar', $val, $fieldName, $this);
} else if(array_key_exists($fieldName, self::$fixed_fields)) {
return DBField::create_field(self::$fixed_fields[$fieldName], $this->$fieldName, $fieldName, $this);
// General casting information for items in $db
} else if($helper = $this->db($fieldName)) {
$obj = Object::create_from_string($helper, $fieldName);

View File

@ -19,6 +19,17 @@ class DataObjectTest extends SapphireTest {
'DataObjectTest_TeamComment'
);
public function testBaseFieldsExcludedFromDb() {
$obj = new DataObjectTest_ValidatedObject();
$dbFields = $obj->db();
$this->assertArrayHasKey('Name', $dbFields);
$this->assertArrayNotHasKey('Created', $dbFields);
$this->assertArrayNotHasKey('LastEdited', $dbFields);
$this->assertArrayNotHasKey('ClassName', $dbFields);
$this->assertArrayNotHasKey('ID', $dbFields);
}
public function testValidObjectsForBaseFields() {
$obj = new DataObjectTest_ValidatedObject();