Quellcode durchsuchen

Update tripal_chado.db.inc

prevent trying to delete active dbs
Bradford Condon vor 5 Jahren
Ursprung
Commit
35845adc16
1 geänderte Dateien mit 17 neuen und 7 gelöschten Zeilen
  1. 17 7
      tripal_chado/includes/tripal_chado.db.inc

+ 17 - 7
tripal_chado/includes/tripal_chado.db.inc

@@ -84,7 +84,8 @@ function tripal_chado_db_edit_form($form, &$form_state) {
   ];
 
 
-  // if we don't have a db_id then we can  return the form, otherwise
+  // if 
+  we don't have a db_id then we can  return the form, otherwise
   // add in the other fields
   if ($dbid) {
     tripal_chado_add_db_form_fields($form, $form_state, $dbid);
@@ -93,11 +94,20 @@ function tripal_chado_db_edit_form($form, &$form_state) {
       '#type' => 'submit',
       '#value' => t('Update'),
     ];
-    $form['delete'] = [
-      '#type' => 'submit',
-      '#value' => t('Delete'),
-      '#attributes' => ['onclick' => 'if(!confirm("Really Delete?")){return false;}'],
-    ];
+  
+  
+    // Assert we have some configuration in our database.
+  $dbxref_count = chado_query('select count(dbxref_id) from {dbxref_id} WHERE db_id = :db_id', [':db_id'] => $dbid);  
+  
+    if ($dbxref_count == 0) {
+      $form['delete'] = [
+        '#type' => 'submit',
+        '#value' => t('Delete'),
+        '#attributes' => ['onclick' => 'if(!confirm("Really Delete?")){return false;}'],
+      ];
+    } else {
+      tripal_set_message('You cannot delete this db without first deleting the ${dbxref_count} dbxrefs associated with it.', TRIPAL_NOTICE);
+    }
   }
   else {
     // if we don't have a dbid then this is the first time the form has
@@ -346,4 +356,4 @@ function tripal_chado_db_edit_form_ajax($form, $form_state) {
   //drupal_set_message('<pre>' . print_r($elements, TRUE) . '</pre>', "status");
 
   return $elements;
-}
+}