function chado_example_update
2.x tripal_example.chado_node.inc | chado_example_update($node) |
Implementation of hook_update(). This function runs after the node has been inserted into the Drupal schema and allows us to update the record in Chado.
This function is not required if the hook_node_info() does not define any custom node types.
File
- tripal_example/
includes/ tripal_example.chado_node.inc, line 483 - This file should contain all Drupal hooks for interacting with nodes.
Code
function chado_example_update($node) {
// be sure to always trim text fields
$node->uniquename = trim($node->uniquename);
$node->description = trim($node->description['value']);
// use the chado_update_record() function to update the record
$match = array(
'example_id' => $example_id,
);
$values = array(
'uniquename' => $node->uniquename,
);
$options = array('return_record' => TRUE);
$status = chado_update_record('example', $match, $values, $options);
if (!$status) {
drupal_set_message(t('Unable to update example.'), 'warning');
tripal_report_error('tripal_example', TRIPAL_WARNING, 'Update example: Unable to update example where values: %values',
array('%values' => print_r($values, TRUE)));
}
// If you implemented the properties form in chado_example_form then you need
// to handle updating these properties into your Chado prop table.
$details = array(
'property_table' => 'exampleprop', // the name of the prop table
'base_table' => 'example', // the name of your Chado base table
'foreignkey_name' => 'example_id', // the name of the key in your base table
'foreignkey_value' => $example_id // the value of the example_id key
);
chado_update_node_form_properties($node, $details);
// If you implemented the dbxrefs form in chado_example_form then you need to
// handle updating these database references into your Chado _dbxref table.
$details = array(
'linking_table' => 'example_dbxref', // the name of your _dbxref table
'foreignkey_name' => 'example_id', // the name of the key in your base table
'foreignkey_value' => $example_id // the value of the example_id key
);
chado_update_node_form_dbxrefs($node, $details);
// If you implemented the relationships form in chado_example_form then you
// need to handle updating these relationships into your Chado _relationship
// table.
$details = array(
// name of the _relationship table
'relationship_table' => 'example_relationship',
// value of the example_id key
'foreignkey_value' => $example_id
);
chado_update_node_form_relationships($node, $details);
}