Browse Source

attempt to improve logging

Stephen Ficklin 6 years ago
parent
commit
59970d8197

+ 12 - 13
tripal/api/tripal.entities.api.inc

@@ -380,15 +380,14 @@ function tripal_load_bundle_entity($values) {
  */
 function tripal_add_notification($title, $details, $type, $actions, $submitter_id) {
   $transaction = db_transaction();
-
-  // Check the notification isn't already in the admin notification table.
-  $dedup = db_select('tripal_admin_notfications', 'tan')
-    ->fields('tan')
-    ->condition('submitter_id', $submitter_id, '=')
-    ->execute()->fetchAll();
-
-  if (empty($dedup)) {
-    try {
+  try {
+    // Check the notification isn't already in the admin notification table.
+    $dedup = db_select('tripal_admin_notfications', 'tan')
+      ->fields('tan')
+      ->condition('submitter_id', $submitter_id, '=')
+      ->execute()->fetchAll();
+  
+    if (empty($dedup)) {
       $record = new stdClass;
       $record->details = $details;
       $record->title = $title;
@@ -398,10 +397,10 @@ function tripal_add_notification($title, $details, $type, $actions, $submitter_i
       $record->type = $type;
       $success = drupal_write_record('tripal_admin_notfications', $record);
     }
-    catch (Exception $e) {
-      $transaction->rollback();
-      watchdog('tripal_cron', 'Could not write notification to database.');
-    }
+  }
+  catch (Exception $e) {
+    $transaction->rollback();
+    watchdog('tripal_cron', 'Could not write notification to database.');
   }
 }
 

+ 5 - 6
tripal/api/tripal.importer.api.inc

@@ -210,10 +210,9 @@ function tripal_run_importer($import_id, TripalJob $job = NULL) {
  */
 function tripal_run_importer_run($loader, $job) {
 
+  // begin the transaction
+  $transaction = db_transaction();
   try {
-    // begin the transaction
-    $transaction = db_transaction();
-
     $loader->run();
 
     if ($job) {
@@ -244,9 +243,9 @@ function tripal_run_importer_run($loader, $job) {
  * @ingroup tripal_importer_api
  */
 function tripal_run_importer_post_run($loader, $job) {
-  try {
-    // the transaction
-    $transaction = db_transaction();
+  // the transaction
+  $transaction = db_transaction();
+  try {    
     $loader->postRun();
   }
   catch (Exception $e) {

+ 59 - 48
tripal/includes/TripalBundleController.inc

@@ -51,59 +51,70 @@ class TripalBundleController extends EntityAPIControllerExportable {
     if (!$transaction) {
       $transaction = db_transaction();
     }
-
-    if ($bundles) {
-
-      foreach ($bundles as $id => $bundle) {
-
-        // Allow modules to perform actions when the bundle is deleted.
-        $modules = module_implements('bundle_delete');
-        foreach ($modules as $module) {
-          $function = $module . '_bundle_delete';
-          $function($bundle);
+    
+    try {
+
+      if ($bundles) {
+  
+        foreach ($bundles as $id => $bundle) {
+  
+          // Allow modules to perform actions when the bundle is deleted.
+          $modules = module_implements('bundle_delete');
+          foreach ($modules as $module) {
+            $function = $module . '_bundle_delete';
+            $function($bundle);
+          }
+  
+          // Find any TripalEntity fields that are attached to this bundle and
+          // remove them.
+          $instances = field_info_instances('TripalEntity', $bundle->name);
+          foreach ($instances as $instance) {
+            // Mark the instance as deleted and purge it.
+            $field = field_info_field($instance['field_name']);
+            field_delete_instance($instance);
+            field_purge_instance($instance);
+  
+            // If the field has no more instances then purge it too.
+            if (count($field['bundles']) == 1 and
+              count($field['bundles']['TripalEntity']) == 1 and
+              in_array($bundle->name, $field['bundles']['TripalEntity'])
+            ) {
+              field_purge_field($field);
+            }
+          }
+  
+          // Remove any entities from the tripal_entity table.
+          db_delete('tripal_entity')
+            ->condition('bundle', $bundle->name)
+            ->execute();
+  
+          // Remove the terms for the bundles that are to be deleted.
+          db_delete('tripal_term')
+            ->condition('id', $bundle->term_id)
+            ->execute();
         }
-
-        // Find any TripalEntity fields that are attached to this bundle and
-        // remove them.
-        $instances = field_info_instances('TripalEntity', $bundle->name);
-        foreach ($instances as $instance) {
-          // Mark the instance as deleted and purge it.
-          $field = field_info_field($instance['field_name']);
-          field_delete_instance($instance);
-          field_purge_instance($instance);
-
-          // If the field has no more instances then purge it too.
-          if (count($field['bundles']) == 1 and
-            count($field['bundles']['TripalEntity']) == 1 and
-            in_array($bundle->name, $field['bundles']['TripalEntity'])
-          ) {
-            field_purge_field($field);
+  
+        // Use the parent function to delete the bundles.
+        parent::delete($ids, $transaction);
+  
+        // Not sure what this does, but copied from the
+        // EntityAPIControllerExportable->delete() function which this one
+        // overrides.
+        foreach ($bundles as $id => $bundle) {
+          if (entity_has_status($this->entityType, $bundle, ENTITY_IN_CODE)) {
+            entity_defaults_rebuild([$this->entityType]);
+            break;
           }
         }
-
-        // Remove any entities from the tripal_entity table.
-        db_delete('tripal_entity')
-          ->condition('bundle', $bundle->name)
-          ->execute();
-
-        // Remove the terms for the bundles that are to be deleted.
-        db_delete('tripal_term')
-          ->condition('id', $bundle->term_id)
-          ->execute();
       }
-
-      // Use the parent function to delete the bundles.
-      parent::delete($ids, $transaction);
-
-      // Not sure what this does, but copied from the
-      // EntityAPIControllerExportable->delete() function which this one
-      // overrides.
-      foreach ($bundles as $id => $bundle) {
-        if (entity_has_status($this->entityType, $bundle, ENTITY_IN_CODE)) {
-          entity_defaults_rebuild([$this->entityType]);
-          break;
-        }
+    }
+    catch (Exception $e) {
+      if ($transaction) {
+        $transaction->rollback();
       }
+      watchdog_exception('tripal', $e);
+      throw $e;
+      return FALSE;
     }
   }
 }

+ 4 - 2
tripal/includes/TripalEntityController.inc

@@ -91,7 +91,9 @@ class TripalEntityController extends EntityAPIController {
       }
     }
     catch (Exception $e) {
-      $transaction->rollback();
+      if ($transaction) {
+        $transaction->rollback();
+      }
       watchdog_exception('tripal', $e);
       throw $e;
       return FALSE;
@@ -468,7 +470,7 @@ class TripalEntityController extends EntityAPIController {
     catch (Exception $e) {
       $transaction->rollback();
       watchdog_exception('tripal', $e);
-      drupal_set_message("Could not save the entity: " . $e->getMessage(), "error");
+      drupal_set_message("Could not save the TripalEntity: " . $e->getMessage(), "error");
       return FALSE;
     }
   }

+ 1 - 1
tripal/includes/TripalTermController.inc

@@ -105,7 +105,7 @@ class TripalTermController extends EntityAPIController {
     catch (Exception $e) {
       $transaction->rollback();
       watchdog_exception('tripal_entity', $e);
-      drupal_set_message("Could not save the entity:" . $e->getMessage(), "error");
+      drupal_set_message("Could not save the TripalTerm:" . $e->getMessage(), "error");
       return FALSE;
     }
   }

+ 1 - 1
tripal/includes/TripalVocabController.inc

@@ -106,7 +106,7 @@ class TripalVocabController extends EntityAPIController {
     catch (Exception $e) {
       $transaction->rollback();
       watchdog_exception('tripal_entity', $e);
-      drupal_set_message("Could not save the entity:" . $e->getMessage(), "error");
+      drupal_set_message("Could not save the TripalVocab:" . $e->getMessage(), "error");
       return FALSE;
     }
   }

+ 2 - 1
tripal_chado/api/modules/tripal_chado.cv.api.inc

@@ -414,7 +414,8 @@ function chado_update_cvtermpath($cv_id, $job_id = NULL){
     // Rollback any database changes
     $transaction->rollback();
     throw $e;
-  } finally {
+  } 
+  finally {
     // Set the database back
     chado_set_active($prev_db);
   }

+ 6 - 6
tripal_chado/api/tripal_chado.api.inc

@@ -231,13 +231,13 @@ function chado_publish_records($values, $job_id = NULL) {
         $total_published, $count, $complete * 3, number_format(memory_get_usage()), number_format((microtime(true) - $started_at)/60, 2));
     }
 
-    // There is no need to cache transactions since Drupal handles nested transactions
-    // "by performing no transactional operations (as far as the database sees) within
-    // the inner nesting layers". Effectively, Drupal ensures nested trasactions work the
-    // same as passing a transaction through to the deepest level and not starting a new
-    // transaction if we are already in one.
+    // There is no need to cache transactions since Drupal handles nested 
+    // transactions "by performing no transactional operations (as far as the 
+    // database sees) within the inner nesting layers". Effectively, Drupal 
+    // ensures nested trasactions work the same as passing a transaction 
+    // through to the deepest level and not starting a new transaction if we 
+    // are already in one.
     $transaction = db_transaction();
-
     try {
       $i = 0;
       while($record = $records->fetchObject()) {