function chado_stock_update
2.x tripal_stock.chado_node.inc | chado_stock_update($node) |
3.x tripal_stock.chado_node.inc | chado_stock_update($node) |
1.x tripal_stock.module | chado_stock_update($node) |
Implements hook_update(). Handles Editing/Updating of main stock info
NOTE: Currently just writes over all old data
Parameters
$node: The current node including fields with the form element names and submitted values
Return value
TRUE if the node was successfully updated in drupal/chado; FALSE otherwise
Related topics
File
- legacy/
tripal_stock/ includes/ tripal_stock.chado_node.inc, line 565 - Stock Node Functionality
Code
function chado_stock_update($node) {
$node->uniquename = trim($node->uniquename);
$node->sname = trim($node->sname);
$node->stock_description = trim($node->stock_description['value']);
if ($node->revision) {
// there is no way to handle revisions in Chado but leave
// this here just to make not we've addressed it.
}
//update dbxref
$dbxref_status = NULL;
$dbxref_present = FALSE;
if ($node->database) {
$dbxref_present = TRUE;
if ($node->accession) {
$dbxref_mode = '';
$stock = chado_select_record(
'stock',
array('dbxref_id', 'type_id'),
array('stock_id' => $node->stock_id)
);
if ($stock[0]->dbxref_id) {
$values = array(
'db_id' => $node->database,
'accession' => $node->accession,
'description' => $node->db_description
);
$dbxref_status = chado_update_record(
'dbxref',
array('dbxref_id' => $stock[0]->dbxref_id),
$values
);
$dbxref_mode = 'Update';
}
else {
if ($stock[0]->type_id) {
//create the dbxref
//used the type_id as a control to check we have a stock but not a dbxref
$values = array(
'db_id' => $node->database,
'accession' => $node->accession,
'description' => $node->db_description,
'version' => '1',
);
$dbxref_status = chado_insert_record(
'dbxref',
$values
);
$dbxref_mode = 'Create';
}
else {
drupal_set_message(t('Unable to find stock to Update'), 'error');
tripal_report_error('tripal_stock', TRIPAL_ERROR,
'Stock Update: Unable to find stock to update using values: %values',
array('%values', print_r($values, TRUE))
);
return FALSE;
}
}
}
if (!$dbxref_status) {
tripal_report_error('tripal_stock', TRIPAL_WARNING,
'Stock Update: Unable to %mode main stock dbxref with values: %values',
array('%values' => print_r($values, TRUE), '%mode' => $dbxref_mode));
}
}
//can't change stock id which is all thats stored in drupal thus only update chado
$update_values = array(
'organism_id' => $node->organism_id,
'name' => $node->sname,
'uniquename' => $node->uniquename,
'description' => $node->stock_description,
'type_id' => $node->type_id,
);
if ($dbxref_present) {
if ($dbxref_status) {
$update_values['dbxref_id'] = array(
'db_id' => $node->database,
'accession' => $node->accession
);
}
}
$status = chado_update_record('stock', array('stock_id' => $node->stock_id), $update_values);
if (!$status) {
drupal_set_message(t('Unable to update stock'), 'error');
tripal_report_error('tripal_stock', TRIPAL_ERROR,
'Stock Update: Unable to update stock using match values: %mvalues and update values: %uvalues',
array('%mvalues' => print_r(array('stock_id' => $node->stock_id), TRUE), '%uvalues' => print_r($update_values, TRUE))
);
}
else {
// set the URL for this stock page
$values = array('stock_id' => $node->stock_id);
$stock = chado_select_record('stock', array('*'), $values);
}
// now update the properties
if ($node->stock_id > 0) {
$details = array(
'property_table' => 'stockprop',
'base_table' => 'stock',
'foreignkey_name' => 'stock_id',
'foreignkey_value' => $node->stock_id
);
chado_update_node_form_properties($node, $details);
}
// now update the additional dbxrefs
if ($node->stock_id > 0) {
$details = array(
'linking_table' => 'stock_dbxref',
'foreignkey_name' => 'stock_id',
'foreignkey_value' => $node->stock_id
);
chado_update_node_form_dbxrefs($node, $details);
}
// now update relationships
if ($node->stock_id > 0) {
$details = array(
'relationship_table' => 'stock_relationship',
'foreignkey_value' => $node->stock_id
);
chado_update_node_form_relationships($node, $details);
}
}