function chado_example_delete

2.x tripal_example.chado_node.inc chado_example_delete($node)

Implementation of hook_delete(). This function runs after the node has been deleted from the Drupal schema and allows us to delete the corresponding 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 545
This file should contain all Drupal hooks for interacting with nodes.

Code

function chado_example_delete($node) {

  // get the example id from the node
  $example_id = chado_get_id_from_nid('example', $node->nid);

  // if we don't have a example id for this node then this isn't a node of type
  // chado_example or the entry in the chado_example table was lost.
  if (!$example_id) {
    return;
  }

  // remove the entry in the chado_exapmle table linking the deleted
  // Drupal node with the data in Chado
  $sql_del = "DELETE FROM {chado_example} WHERE nid = :nid AND vid = :vid";
  db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));

  // Remove data from example tables of Chado database. This will
  // cause a cascade delete and remove all data in referencing tables
  // for this example
  chado_query("DELETE FROM {example} WHERE example_id = :example_id", array(':example_id' => $example_id));

  // inform the user that the data was deleted
  drupal_set_message(t("The example and all associated data were removed from Chado"));

}