|
@@ -40,13 +40,14 @@ function tripal_chado_field_storage_write($entity_type, $entity, $op, $fields) {
|
|
// Convert the fields into a key/value list of fields and their values.
|
|
// Convert the fields into a key/value list of fields and their values.
|
|
$field_vals = tripal_chado_field_storage_write_merge_fields($fields, $entity_type, $entity);
|
|
$field_vals = tripal_chado_field_storage_write_merge_fields($fields, $entity_type, $entity);
|
|
|
|
|
|
- // Write the record for the base table. First get the values for this table
|
|
|
|
- // and set the record_id (update) or the type_id (insert)
|
|
|
|
|
|
+ // First, write the record for the base table. If we have a record id then
|
|
|
|
+ // this is an upate and we need to set the primary key. If not, then this
|
|
|
|
+ // is an insert and we need to set the type_id if the table supports it.
|
|
$values = $field_vals[$base_table][0];
|
|
$values = $field_vals[$base_table][0];
|
|
if ($record_id) {
|
|
if ($record_id) {
|
|
$values[$base_pkey] = $record_id;
|
|
$values[$base_pkey] = $record_id;
|
|
}
|
|
}
|
|
- else {
|
|
|
|
|
|
+ elseif ($type_field) {
|
|
$values[$type_field] = $cvterm->cvterm_id;
|
|
$values[$type_field] = $cvterm->cvterm_id;
|
|
}
|
|
}
|
|
$base_record_id = tripal_chado_field_storage_write_table($base_table, $values);
|
|
$base_record_id = tripal_chado_field_storage_write_table($base_table, $values);
|
|
@@ -107,7 +108,7 @@ function tripal_chado_field_storage_write_table($table_name, $values) {
|
|
$fkeys = $schema['foreign keys'];
|
|
$fkeys = $schema['foreign keys'];
|
|
$pkey = $schema['primary key'][0];
|
|
$pkey = $schema['primary key'][0];
|
|
|
|
|
|
- // Before inserting or updating this table, recruse if there are any
|
|
|
|
|
|
+ // Before inserting or updating this table, recurse if there are any
|
|
// nested FK array values.
|
|
// nested FK array values.
|
|
foreach ($values as $column => $value) {
|
|
foreach ($values as $column => $value) {
|
|
// If this value is an array then it must be a FK... let's recurse.
|
|
// If this value is an array then it must be a FK... let's recurse.
|
|
@@ -157,7 +158,7 @@ function tripal_chado_field_storage_write_table($table_name, $values) {
|
|
// Insert the values array as a new record in the table.
|
|
// Insert the values array as a new record in the table.
|
|
$record = chado_insert_record($table_name, $values);
|
|
$record = chado_insert_record($table_name, $values);
|
|
if ($record === FALSE) {
|
|
if ($record === FALSE) {
|
|
- throw new Exception('Could not insert Chado record into table: "' . $tablename . '".');
|
|
|
|
|
|
+ throw new Exception('Could not insert Chado record into table: "' . $table_name . '".');
|
|
}
|
|
}
|
|
return $record[$pkey];
|
|
return $record[$pkey];
|
|
}
|
|
}
|
|
@@ -167,7 +168,7 @@ function tripal_chado_field_storage_write_table($table_name, $values) {
|
|
// not being tested for here.
|
|
// not being tested for here.
|
|
$match[$pkey] = $values[$pkey];
|
|
$match[$pkey] = $values[$pkey];
|
|
if (!chado_update_record($table_name, $match, $values)) {
|
|
if (!chado_update_record($table_name, $match, $values)) {
|
|
- drupal_set_message("Could not update Chado record in table: $tablename.", 'error');
|
|
|
|
|
|
+ drupal_set_message("Could not update Chado record in table: $table_name.", 'error');
|
|
}
|
|
}
|
|
return $values[$pkey];
|
|
return $values[$pkey];
|
|
}
|
|
}
|