Преглед изворни кода

When deleting a chado entity, remove the corresponding chado record and the entry in the public.chado_entity table

Chun-Huai Cheng пре 9 година
родитељ
комит
38573f27bf

+ 15 - 2
tripal_entities/includes/tripal_entities.chado_entity.inc

@@ -47,6 +47,19 @@ function tripal_entities_entity_update($entity, $type) {
  * Implements hook_entity_delete().
  */
 function tripal_entities_entity_delete($entity, $type) {
-  // TODO: delete the record in the public.chado_entity table
-  // and delete the corresponding record in Chado.
+  $record = db_select('chado_entity', 'ce')
+   ->fields('ce', array('chado_entity_id', 'data_table', 'record_id'))
+   ->condition('entity_id', $entity->id)
+   ->execute()
+   ->fetchObject();
+  
+  // Delete the corresponding record in Chado
+  $table = $record->data_table;
+  $record_id = $record->record_id;  
+  chado_delete_record($table, array($table . '_id' => $record_id));
+  
+  //Delete the record in the public.chado_entity table
+  $sql = "DELETE FROM {chado_entity} WHERE chado_entity_id = :id";
+  db_query($sql, array(':id' => $record->chado_entity_id));
+  
 }

+ 1 - 1
tripal_entities/includes/tripal_entities.fields.inc

@@ -267,7 +267,7 @@ function tripal_entities_field_is_empty($item, $field) {
  */
 function tripal_entities_organism_select_widget_validate($element, &$form_state) {
   $field_name = $element['#field_name'];
-dpm($form_state);
+
   // If the form ID is field_ui_field_edit_form, then the user is editing the
   // field's values in the manage fields form of Drupal.  We don't want
   // to validate it as if it were being used in a data entry form.

+ 15 - 2
tripal_entities/tripal_entities.module

@@ -286,6 +286,19 @@ function tripal_entities_get_published_vocabularies_as_select_options() {
   return $options;
 }
 
+/**
+ * Get published vocabularies as select options
+ * @return multitype:NULL
+ */
+function tripal_entities_get_db_names_for_published_vocabularies() {
+  $published_vocs = chado_generate_var('tripal_vocabulary', array('publish' => 1), array('return_array' => 1));
+  $db = array();
+  foreach ($published_vocs as $voc) {
+    $db [$voc->db_id->db_id] = $voc->db_id->name;
+  }
+  return $db;
+}
+
 /**
  * Get published terms as select options
  * @return multitype:NULL
@@ -370,8 +383,8 @@ function tripal_entities_form_alter(&$form, &$form_state, $form_id) {
       // For entity fields added by Tripal Entities we don't want the
       // the end-user to change the cardinality and the required fields
       // such that record can't be saved in Chado.
-      // TODO: don't hard-code the 'SO' entity type.
-      if ($form['#instance']['entity_type'] == 'SO') {
+      $dbs = tripal_entities_get_db_names_for_published_vocabularies ();
+      if (in_array($form['#instance']['entity_type'], $dbs)) {
          $form['field']['cardinality']['#access'] = FALSE;
          $form['instance']['required']['#access'] = FALSE;
       }