Просмотр исходного кода

Merge pull request #593 from tripal/533-tv3-ctype_timeout

Creation of content types times out
Bradford Condon 6 лет назад
Родитель
Сommit
6f4fa9d97e

+ 28 - 10
tripal/api/tripal.entities.api.inc

@@ -417,20 +417,31 @@ function tripal_add_notification($title, $details, $type, $actions, $submitter_i
  *     - term_name: A human-readable name for this term.  This will became
  *       the name that appears for the content type.  In practice, this
  *       should be the name of the term. (E.g. the name for SO:0000704 is gene).
- * @param $error
- *  A string, passed by reference, that is filled with the error message
- *  if the function fails.
+ * @param $job
+ *  The job ID if this is launched via a job.
  *
  * @return
  *   The bundle object or FALSE if failure.
  *
  * @ingroup tripal_entities_api
  */
-function tripal_create_bundle($args, &$error = '') {
+function tripal_create_bundle($args, $job = NULL) {
   $vocabulary = $args['vocabulary'];
   $accession = $args['accession'];
   $term_name = $args['term_name'];
   $storage_args = $args['storage_args'];
+  
+  $message_args = [
+    'job' => $job,
+    'print' => TRUE,
+    'watchdog' => TRUE,
+  ];
+  
+  tripal_report_error('tripal_entities', TRIPAL_INFO, 
+   "Creation of a content type is performed using a database transaction. " .
+    "If it fails or is terminated prematurely then all insertions and " .
+    "updates are rolled back and will not be found in the database", 
+    [], $message_args);
 
   $transaction = db_transaction();
   try {
@@ -444,7 +455,7 @@ function tripal_create_bundle($args, &$error = '') {
       else {
         $transaction->rollback();
         tripal_report_error('tripal_entities', TRIPAL_ERROR, 
-          'Unable to create TripalVocab :vocab', array(':vocab' => $vocabulary));
+          'Unable to create TripalVocab :vocab', array(':vocab' => $vocabulary), $message_args);
         return FALSE;
       }
     }
@@ -463,7 +474,7 @@ function tripal_create_bundle($args, &$error = '') {
       else {
         $transaction->rollback();
         tripal_report_error('tripal_entities', TRIPAL_ERROR,
-          'Unable to create TripalTerm :term', array(':term' => $term_name));
+          'Unable to create TripalTerm :term', array(':term' => $term_name), $message_args);
         return FALSE;
       }
     }
@@ -493,7 +504,7 @@ function tripal_create_bundle($args, &$error = '') {
     if (!$bundle) {
       $transaction->rollback();
       tripal_report_error('tripal_entities', TRIPAL_ERROR,
-        'Unable to create Tripal Bundle :name.', array(':name' => $bundle_name));
+        'Unable to create Tripal Bundle :name.', array(':name' => $bundle_name), $message_args);
       return FALSE;
     }
 
@@ -517,7 +528,7 @@ function tripal_create_bundle($args, &$error = '') {
     if (!$bundle) {
       $transaction->rollback();
       tripal_report_error('tripal_entities', TRIPAL_ERROR,
-        'Unable to load Tripal Bundle :name after cache clear.', array(':name' => $bundle_name));
+        'Unable to load Tripal Bundle :name after cache clear.', array(':name' => $bundle_name), $message_args);
       return FALSE;
     }
 
@@ -532,8 +543,9 @@ function tripal_create_bundle($args, &$error = '') {
   }
   catch (Exception $e) {
     $transaction->rollback();
-    drupal_set_message(t("Failed to create content type: %message.",
-      array('%message' => $e->getMessage())), 'error');
+    $message_args['drupal_set_message'] = TRUE;
+    tripal_report_error('tripal_entities', TRIPAL_ERROR,
+      "Failed to create content type: %message.", ['%message' => $e->getMessage()], $message_args);
     return FALSE;
   }
 
@@ -549,6 +561,12 @@ function tripal_create_bundle($args, &$error = '') {
     }
   }
 
+  // Set admin access for the new bundle.
+  tripal_admin_access($bundle);
+  
+  // Report that we're done.
+  tripal_report_error('tripal_entities', TRIPAL_INFO, "Done.", [], $message_args);
+  
   return $bundle;
 }
 

+ 6 - 5
tripal/includes/TripalBundleUIController.inc

@@ -839,15 +839,16 @@ function tripal_admin_add_type_form_submit($form, &$form_state) {
         'storage_args' => $storage_args,
       );
 
-      $bundle = tripal_create_bundle($args, $error);
-      if (!$bundle) {
+      global $user;
+      $job_id = tripal_add_job("Create content type: " . $term_name . ' ('. $vocabulary . ':' . $accession . ')', 
+        'tripal', 'tripal_create_bundle', [$args], $user->uid);
+
+      if (!$job_id) {
         drupal_set_message($error, 'error');
         $form_state['redirect'] = "admin/structure/bio_data";
       }
       else {
-        drupal_set_message('New content type created!');
-        drupal_set_message('Please ' . l("set the user permissions", "admin/people/permissions") . ' for this new content type.');
-        tripal_admin_access($bundle);
+        drupal_set_message('After the content type is created, please ' . l("set the user permissions", "admin/people/permissions") . ' for this new content type.');
         $form_state['redirect'] = "admin/structure/bio_data";
       }
     }

+ 18 - 26
tripal_chado/includes/setup/tripal_chado.setup.inc

@@ -230,7 +230,6 @@ function tripal_chado_prepare_chado($job = NULL) {
 
     // Create the 'Organism' entity type. This uses the obi:organism term.
     drush_print("Creating Organism...");
-    $error = '';
     $args = array(
       'vocabulary' => 'OBI',
       'accession' => '0100026',
@@ -244,8 +243,8 @@ function tripal_chado_prepare_chado($job = NULL) {
       $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
     }
     if (!$term or !$bundle) {
-      if (!tripal_create_bundle($args, $error)) {
-        $msg = (isset($error['!message'])) ? $error['!message'] : 'Error Encountered creating "Organism" Tripal Content Type.';
+      if (!tripal_create_bundle($args)) {
+        $msg = 'Error Encountered creating "Organism" Tripal Content Type.';
         throw new Exception($msg);
       }
     }
@@ -255,7 +254,6 @@ function tripal_chado_prepare_chado($job = NULL) {
 
     // Create the 'Analysis' entity type. This uses the local:analysis term.
     drush_print("Creating Analysis...");
-    $error = '';
     $args = array(
       'vocabulary' => 'operation',
       'accession' => '2945',
@@ -269,8 +267,8 @@ function tripal_chado_prepare_chado($job = NULL) {
       $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
     }
     if (!$term or !$bundle) {
-      if (!tripal_create_bundle($args, $error)) {
-        $msg = (isset($error['!message'])) ? $error['!message'] : 'Error Encountered creating "Analysis" Tripal Content Type.';
+      if (!tripal_create_bundle($args)) {
+        $msg = 'Error Encountered creating "Analysis" Tripal Content Type.';
         throw new Exception($msg);
       }
     }
@@ -280,7 +278,6 @@ function tripal_chado_prepare_chado($job = NULL) {
 
     // Create the 'Project' entity type. This uses the local:project term.
     drush_print("Creating Project...");
-    $error = '';
     $args = array(
       'vocabulary' => 'local',
       'accession' => 'project',
@@ -294,8 +291,8 @@ function tripal_chado_prepare_chado($job = NULL) {
       $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
     }
     if (!$term or !$bundle) {
-      if (!tripal_create_bundle($args, $error)) {
-        $msg = (isset($error['!message'])) ? $error['!message'] : 'Error Encountered creating "Project" Tripal Content Type.';
+      if (!tripal_create_bundle($args)) {
+        $msg = 'Error Encountered creating "Project" Tripal Content Type.';
         throw new Exception($msg);
       }
     }
@@ -305,7 +302,6 @@ function tripal_chado_prepare_chado($job = NULL) {
 
     // Create the 'Map' entity type. This uses the local:project term.
     drush_print("Creating Map...");
-    $error = '';
     $args = array(
       'vocabulary' => 'data',
       'accession' => '1274',
@@ -319,8 +315,8 @@ function tripal_chado_prepare_chado($job = NULL) {
       $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
     }
     if (!$term or !$bundle) {
-      if (!tripal_create_bundle($args, $error)) {
-        $msg = (isset($error['!message'])) ? $error['!message'] : 'Error Encountered creating "Map" Tripal Content Type.';
+      if (!tripal_create_bundle($args)) {
+        $msg = 'Error Encountered creating "Map" Tripal Content Type.';
         throw new Exception($msg);
       }
     }
@@ -355,8 +351,8 @@ function tripal_chado_prepare_chado($job = NULL) {
         $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
     }
     if (!$term or !$bundle) {
-      if (!tripal_create_bundle($args, $error)) {
-        $msg = (isset($error['!message'])) ? $error['!message'] : 'Error Encountered creating "Publication" Tripal Content Type.';
+      if (!tripal_create_bundle($args)) {
+        $msg = 'Error Encountered creating "Publication" Tripal Content Type.';
         throw new Exception($msg);
       }
     }
@@ -385,7 +381,6 @@ function tripal_chado_prepare_chado($job = NULL) {
 
     // Create the 'Gene' entity type.
     drush_print("Creating Gene...");
-    $error = '';
     $args = array(
       'vocabulary' => 'SO',
       'accession' => '0000704',
@@ -400,8 +395,8 @@ function tripal_chado_prepare_chado($job = NULL) {
       $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
     }
     if (!$term or !$bundle) {
-      if (!tripal_create_bundle($args, $error)) {
-        $msg = (isset($error['!message'])) ? $error['!message'] : 'Error Encountered creating "Gene" Tripal Content Type.';
+      if (!tripal_create_bundle($args)) {
+        $msg = 'Error Encountered creating "Gene" Tripal Content Type.';
         throw new Exception($msg);
       }
     }
@@ -411,7 +406,6 @@ function tripal_chado_prepare_chado($job = NULL) {
 
     // Create the 'mRNA' entity type.
     drush_print("Creating mRNA...");
-    $error = '';
     $args = array(
       'vocabulary' => 'SO',
       'accession' => '0000234',
@@ -426,8 +420,8 @@ function tripal_chado_prepare_chado($job = NULL) {
       $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
     }
     if (!$term or !$bundle) {
-      if (!tripal_create_bundle($args, $error)) {
-        $msg = (isset($error['!message'])) ? $error['!message'] : 'Error Encountered  creating "mRNA" Tripal Content Type.';
+      if (!tripal_create_bundle($args)) {
+        $msg = 'Error Encountered  creating "mRNA" Tripal Content Type.';
         throw new Exception($msg);
       }
     }
@@ -437,7 +431,6 @@ function tripal_chado_prepare_chado($job = NULL) {
 
     // Create the 'biological sample' entity type.
     drush_print("Creating Biological Sample...");
-    $error = '';
     $args = array(
       'vocabulary' => 'sep',
       'accession' => '00195',
@@ -451,8 +444,8 @@ function tripal_chado_prepare_chado($job = NULL) {
         $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
     }
     if (!$term or !$bundle) {
-      if (!tripal_create_bundle($args, $error)) {
-        $msg = (isset($error['!message'])) ? $error['!message'] : 'Error Encountered creating "Biological Sample" Tripal Content Type.';
+      if (!tripal_create_bundle($args)) {
+        $msg = 'Error Encountered creating "Biological Sample" Tripal Content Type.';
         throw new Exception($msg);
       }
     }
@@ -462,7 +455,6 @@ function tripal_chado_prepare_chado($job = NULL) {
 
     // Create the 'Phylogenetic tree' entity type.
     drush_print("Creating Phylogenetic tree...");
-    $error = '';
     $args = array(
       'vocabulary' => 'data',
       'accession' => '0872',
@@ -476,8 +468,8 @@ function tripal_chado_prepare_chado($job = NULL) {
       $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
     }
     if (!$term or !$bundle) {
-      if (!tripal_create_bundle($args, $error)) {
-        $msg = (isset($error['!message'])) ? $error['!message'] : 'Error Encountered creating "Phylogenetic tree" Tripal Content Type';
+      if (!tripal_create_bundle($args)) {
+        $msg = 'Error Encountered creating "Phylogenetic tree" Tripal Content Type';
         throw new Exception($msg);
       }
     }

+ 2 - 2
tripal_chado/tripal_chado.install

@@ -1380,8 +1380,8 @@ function tripal_chado_update_7320() {
       $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
     }
     if (!$term or !$bundle) {
-      if (!tripal_create_bundle($args, $error)) {
-        throw new Exception($error['!message']);
+      if (!tripal_create_bundle($args)) {
+        throw new Exception('Error Encountered creating "Phylogenetic tree" Tripal Content Type.');
       }
     }
   }