Ver Fonte

Merge branch '7.x-3.x' into 427-Tv3-prop_content_types

Stephen Ficklin há 6 anos atrás
pai
commit
155583fccf

+ 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

@@ -853,15 +853,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";
       }
     }

+ 28 - 13
tripal_chado/api/modules/tripal_chado.phylotree.api.inc

@@ -3,7 +3,7 @@
 /**
  * @file
  * Provides API functions specificially for managing phylogenetic and taxonomic
- * tree records in Chado.  
+ * tree records in Chado.
  */
 
 /**
@@ -11,8 +11,8 @@
  * @ingroup tripal_chado_api
  * @{
  * Provides API functions specificially for managing phylogenetic and taxonomic
- * tree records in Chado.  The API consists of functions for creation, 
- * retrieval, update and deltion (CRUD) for phylogenetic tree records as 
+ * tree records in Chado.  The API consists of functions for creation,
+ * retrieval, update and deltion (CRUD) for phylogenetic tree records as
  * well as importing of trees in the newick file format.
  * @}
  */
@@ -85,10 +85,6 @@ function chado_validate_phylotree($val_type, &$options, &$errors, &$warnings) {
       $errors['description'] = t('Please provide a description for this tree.');
       return FALSE;
     }
-    if (!array_key_exists('tree_file', $options)) {
-      $errors['tree_file'] = t('Please provide either the full path to the tree_file or a Drupal managed file ID number.');
-      return FALSE;
-    }
     if (!array_key_exists('format', $options) or !$options['format']) {
       $errors['format'] = t('Please provide a file format for the tree file.');
       return FALSE;
@@ -202,12 +198,30 @@ function chado_validate_phylotree($val_type, &$options, &$errors, &$warnings) {
       ),
     );
     $dbxref = chado_generate_var('dbxref', $values);
+
     if (!$dbxref) {
-      $errors['dbxref'] = t('The dbxref provided does not exist in the database: %dbxref.', array('%dbxref' => $dbxref));
-      return FALSE;
+
+      $db = chado_generate_var('db', array( 'name' => $db_name));
+
+      if (!$db){
+              $errors['dbxref'] = t('
+              dbxref could not be created for db: %dbxref.', array('%dbxref' => $dbxref));
+              return FALSE;
+      }
+    $dbxref =  chado_insert_record('dbxref', $values);
+
+    if (!$dbxref){
+            $errors['dbxref'] = t('
+            dbxref could not be created for db: %dbxref.', array('%dbxref' => $dbxref));
+            return FALSE;
     }
+  }
+  if (is_array($dbxref)){
+    $options['dbxref_id'] = $dbxref['dbxref_id'];
+    }else {
     $options['dbxref_id'] = $dbxref->dbxref_id;
   }
+  }
 
   // Make sure the tree name is unique.
   if (array_key_exists('name', $options) and $options['name']) {
@@ -254,7 +268,7 @@ function chado_validate_phylotree($val_type, &$options, &$errors, &$warnings) {
  *     'tree_file':  The path of the file containing the phylogenetic tree to
  *                   import or a Drupal managed_file numeric ID.
  *     'format':     The file format. Currently only 'newick is supported'.
- * 
+ *
  *  Optional keys:
  *     'dbxref':     A database cross-reference of the form DB:ACCESSION.
  *                   Where DB is the database name, which is already present
@@ -312,6 +326,7 @@ function chado_insert_phylotree(&$options, &$errors, &$warnings) {
     'comment' => $options['description'],
     'type_id' => $options['type_id'],
   );
+
   $phylotree = chado_insert_record('phylotree', $values);
   if (!$phylotree) {
     drupal_set_message(t('Unable to add phylotree.'), 'warning');
@@ -675,7 +690,7 @@ function chado_phylogeny_import_tree(&$tree, $phylotree, $options, $vocab = arra
       if (!empty($tree['name']) and $tree['name'] != '') {
         if (!$options['taxonomy']) {
 
-          // This is a sequence-based tree. Try to match leaf nodes with 
+          // This is a sequence-based tree. Try to match leaf nodes with
           // features.
           // First, Get the Name and uniquename for the feature.
           $matches = array();
@@ -751,9 +766,9 @@ function chado_phylogeny_import_tree(&$tree, $phylotree, $options, $vocab = arra
 /**
  * Get the vocabulary terms used to describe nodes in the tree.
  *
- * @return 
+ * @return
  *  Array of vocab info or FALSE on failure.
- * 
+ *
  * @ingroup tripal_phylotree_api
  */
 function chado_phylogeny_get_node_types_vocab() {

+ 6 - 1
tripal_chado/includes/TripalFields/so__cds/so__cds.inc

@@ -79,6 +79,11 @@ class so__cds extends ChadoField {
     $feature = chado_expand_var($feature, 'table', 'featureloc', $options);
     $featurelocs = $feature->featureloc->feature_id;
 
+    // Verify that we have featurelocs before entering the loop
+    if(!is_array($featurelocs)) {
+      return;
+    }
+
     foreach($featurelocs as $featureloc){
       // Generate a CDS sequence if one exsits for this feature alignment.
       $cds_sequence = chado_get_feature_sequences(
@@ -111,4 +116,4 @@ class so__cds extends ChadoField {
       }
     }
   }
-}
+}

+ 9 - 11
tripal_chado/includes/TripalImporter/NewickImporter.inc

@@ -29,7 +29,7 @@ class NewickImporter extends TripalImporter {
    * Provides information to the user about the file upload.  Typically this
    * may include a description of the file types allowed.
    */
-  public static $upload_description = 'Please provide the Newick formatted tree file.  The file must have a .txt or .tree extension.';
+  public static $upload_description = 'Please provide the Newick formatted tree file (one tree per file only).  The file must have a .txt or .tree extension.';
 
   /**
    * The title that should appear above the file upload section.
@@ -125,7 +125,7 @@ class NewickImporter extends TripalImporter {
         tree. In this case, the word 'taxonomy' should be used."),
       '#required' => TRUE,
       '#default_value' => $leaf_type,
-      '#autocomplete_path' => "admin/tripal/legacy/tripal_cv/cvterm/auto_name/$cv_id",
+      '#autocomplete_path' => "admin/tripal/storage/chado/auto_name/cvterm/$cv_id",
     ];
 
     $form['dbxref'] = [
@@ -173,13 +173,11 @@ class NewickImporter extends TripalImporter {
   public function formValidate($form, &$form_state) {
 
     $values = $form_state['values'];
-
     $options = [
       'name' => trim($values["tree_name"]),
       'description' => trim($values["description"]),
       'analysis_id' => $values["analysis_id"],
       'leaf_type' => $values["leaf_type"],
-      'tree_file'    => $this->arguments['files'][0]['file_path'],
       'format' => 'newick',
       'dbxref' => trim($values["dbxref"]),
       'match' => $values["match"],
@@ -216,15 +214,15 @@ class NewickImporter extends TripalImporter {
     $arguments = $this->arguments['run_args'];
 
     $options = array(
-      'name'         => $this->arguments["tree_name"],
-      'description'  => $this->arguments["description"],
-      'analysis_id'  => $this->arguments["analysis_id"],
-      'leaf_type'    => $this->arguments["leaf_type"],
+      'name'         => $arguments["tree_name"],
+      'description'  => $arguments["description"],
+      'analysis_id'  => $arguments["analysis_id"],
+      'leaf_type'    => $arguments["leaf_type"],
       'tree_file'    => $this->arguments['files'][0]['file_path'],
       'format'       => 'newick',
-      'dbxref'       => $this->arguments["dbxref"],
-      'match'        => $this->arguments["match"],
-      'name_re'      => $this->arguments["name_re"],
+      'dbxref'       => $arguments["dbxref"],
+      'match'        => $arguments["match"],
+      'name_re'      => $arguments["name_re"],
     );
     $errors = array();
     $warnings = array();

+ 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

@@ -1387,8 +1387,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.');
       }
     }
   }