mlanthaler: Bugfix: Added needed checks if the $ancestry variable is set respectively if it is an array.

(merged from branches/gsoc)


git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@42140 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2007-09-16 16:40:57 +00:00
parent 23b88e60f6
commit 0edcb97d57

View File

@ -408,7 +408,8 @@ class DataObject extends Controller {
}
foreach($this->getClassAncestry() as $ancestor) {
if(ClassInfo::hasTable($ancestor)) $ancestry[] = $ancestor;
if(ClassInfo::hasTable($ancestor))
$ancestry[] = $ancestor;
}
// Look for some changes to make
@ -426,7 +427,7 @@ class DataObject extends Controller {
// New records have their insert into the base data table done first, so that they can pass the
// generated primary key on to the rest of the manipulation
if(!$this->record['ID']) {
if(!$this->record['ID'] && isset($ancestry[0])) {
$baseTable = $ancestry[0];
DB::query("INSERT INTO `{$baseTable}` SET Created = NOW()");
@ -437,30 +438,32 @@ class DataObject extends Controller {
}
// Divvy up field saving into a number of database manipulations
foreach($ancestry as $idx => $class) {
$classSingleton = singleton($class);
foreach($this->record as $fieldName => $value) {
if(isset($this->changed[$fieldName]) && $this->changed[$fieldName] && $fieldType = $classSingleton->fieldExists($fieldName)) {
$manipulation[$class]['fields'][$fieldName] = $value ? ("'" . addslashes($value) . "'") : singleton($fieldType)->nullValue();
if(is_array($ancestry)) {
foreach($ancestry as $idx => $class) {
$classSingleton = singleton($class);
foreach($this->record as $fieldName => $value) {
if(isset($this->changed[$fieldName]) && $this->changed[$fieldName] && $fieldType = $classSingleton->fieldExists($fieldName)) {
$manipulation[$class]['fields'][$fieldName] = $value ? ("'" . addslashes($value) . "'") : singleton($fieldType)->nullValue();
}
}
}
// Add the class name to the base object
if($idx == 0) {
$manipulation[$class]['fields']["LastEdited"] = "now()";
if($dbCommand == 'insert') {
$manipulation[$class]['fields']["Created"] = "now()";
//echo "<li>$this->class - " .get_class($this);
$manipulation[$class]['fields']["ClassName"] = "'$this->class'";
// Add the class name to the base object
if($idx == 0) {
$manipulation[$class]['fields']["LastEdited"] = "now()";
if($dbCommand == 'insert') {
$manipulation[$class]['fields']["Created"] = "now()";
//echo "<li>$this->class - " .get_class($this);
$manipulation[$class]['fields']["ClassName"] = "'$this->class'";
}
}
}
// In cases where there are no fields, this 'stub' will get picked up on
if(ClassInfo::hasTable($class)) {
$manipulation[$class]['command'] = $dbCommand;
$manipulation[$class]['id'] = $this->record['ID'];
} else {
unset($manipulation[$class]);
// In cases where there are no fields, this 'stub' will get picked up on
if(ClassInfo::hasTable($class)) {
$manipulation[$class]['command'] = $dbCommand;
$manipulation[$class]['id'] = $this->record['ID'];
} else {
unset($manipulation[$class]);
}
}
}
@ -502,6 +505,7 @@ class DataObject extends Controller {
return $this->record['ID'];
}
/**
* Perform a write without affecting the version table.
* On objects without versioning.
@ -1765,4 +1769,6 @@ class DataObject extends Controller {
*/
public static $default_sort = null;
}
?>