Browse Source

Merge branch '7.x-3.x' into 759_3x_tripal-registration-form

Shawna Spoor 5 years ago
parent
commit
602b1f2aeb

+ 103 - 0
.all-contributorsrc

@@ -0,0 +1,103 @@
+{
+  "files": [
+    "README.md"
+  ],
+  "imageSize": 100,
+  "commit": false,
+  "contributors": [
+    {
+      "login": "spficklin",
+      "name": "Stephen Ficklin",
+      "avatar_url": "https://avatars0.githubusercontent.com/u/1719352?v=4",
+      "profile": "https://github.com/spficklin",
+      "contributions": [
+        "code",
+        "doc",
+        "projectManagement",
+        "fundingFinding"
+      ]
+    },
+    {
+      "login": "bradfordcondon",
+      "name": "Bradford Condon",
+      "avatar_url": "https://avatars2.githubusercontent.com/u/7063154?v=4",
+      "profile": "http://www.bradfordcondon.com/",
+      "contributions": [
+        "code",
+        "doc",
+        "projectManagement"
+      ]
+    },
+    {
+      "login": "laceysanderson",
+      "name": "Lacey-Anne Sanderson",
+      "avatar_url": "https://avatars3.githubusercontent.com/u/1566301?v=4",
+      "profile": "https://laceysanderson.github.io/",
+      "contributions": [
+        "code",
+        "doc",
+        "projectManagement"
+      ]
+    },
+    {
+      "login": "chunhuaicheng",
+      "name": "chunhuaicheng",
+      "avatar_url": "https://avatars2.githubusercontent.com/u/14333886?v=4",
+      "profile": "https://github.com/chunhuaicheng",
+      "contributions": [
+        "code"
+      ]
+    },
+    {
+      "login": "shawnawsu",
+      "name": "Shawna",
+      "avatar_url": "https://avatars1.githubusercontent.com/u/24374002?v=4",
+      "profile": "https://github.com/shawnawsu",
+      "contributions": [
+        "code"
+      ]
+    },
+    {
+      "login": "mboudet",
+      "name": "mboudet",
+      "avatar_url": "https://avatars0.githubusercontent.com/u/17642511?v=4",
+      "profile": "https://github.com/mboudet",
+      "contributions": [
+        "bug"
+      ]
+    },
+    {
+      "login": "guignonv",
+      "name": "Valentin Guignon",
+      "avatar_url": "https://avatars1.githubusercontent.com/u/7290244?v=4",
+      "profile": "https://github.com/guignonv",
+      "contributions": [
+        "bug"
+      ]
+    },
+    {
+      "login": "mestato",
+      "name": "Meg Staton",
+      "avatar_url": "https://avatars1.githubusercontent.com/u/508122?v=4",
+      "profile": "https://github.com/mestato",
+      "contributions": [
+        "fundingFinding"
+      ]
+    },
+    {
+      "login": "abretaud",
+      "name": "Anthony Bretaudeau",
+      "avatar_url": "https://avatars3.githubusercontent.com/u/238755?v=4",
+      "profile": "https://github.com/abretaud",
+      "contributions": [
+        "code"
+      ]
+    }
+  ],
+  "contributorsPerLine": 7,
+  "projectName": "tripal",
+  "projectOwner": "tripal",
+  "repoType": "github",
+  "repoHost": "https://github.com",
+  "commitConvention": "none"
+}

File diff suppressed because it is too large
+ 8 - 0
README.md


+ 0 - 8
tripal/includes/TripalFields/TripalField.inc

@@ -208,14 +208,6 @@ class TripalField {
     return $this->instance;
   }
 
-  /**
-   * When constructing a pager for use by a field, all pagers must have
-   * a unique ID
-   */
-  protected function getPagerElementID() {
-    return $this->field['id'];
-  }
-
   public function getFieldTerm() {
     return $this->term;
   }

+ 0 - 8
tripal/includes/TripalFields/TripalFieldFormatter.inc

@@ -167,14 +167,6 @@ class TripalFieldFormatter {
 
   }
 
-  /**
-   * When constructing a pager for use by a field, all pagers must have
-   * a unique ID
-   */
-  protected function getPagerElementID() {
-    return $this->field['id'];
-  }
-
   /**
    * Updates a pager generated by theme('pager') for use with AJAX.
    *

+ 2 - 5
tripal/theme/js/tripal.js

@@ -208,18 +208,15 @@
 
 // Used for ajax update of fields by links in a pager.
 function tripal_navigate_field_pager(id, page) {
-  jQuery(document).ajaxStart(function () {
-    jQuery('#' + id + '-spinner').show();
-  }).ajaxComplete(function () {
-    jQuery('#' + id + '-spinner').hide();
-  });
 
+  jQuery('#' + id + '-spinner').show();
   jQuery.ajax({
     type   : 'GET',
     url    : Drupal.settings['basePath'] + 'bio_data/ajax/field_attach/' + id,
     data   : {'page': page},
     success: function (response) {
       jQuery('#' + id + ' .field-items').replaceWith(response['content']);
+      jQuery('#' + id + '-spinner').hide();
     }
   });
 }

+ 46 - 25
tripal_chado/api/tripal_chado.query.api.inc

@@ -349,9 +349,9 @@ function chado_set_active($dbname = 'default') {
   $search_path = chado_get_schema_name('drupal');
 
   // Change only if 'chado' has been specified.
-  // Notice that we leave the active_db set as chado but use the possibly 
-  // user-altered  schema name for the actual search path. This is to keep 
-  // outward facing mentions of chado as "chado" while still allowing the user 
+  // Notice that we leave the active_db set as chado but use the possibly
+  // user-altered  schema name for the actual search path. This is to keep
+  // outward facing mentions of chado as "chado" while still allowing the user
   // to alter the schema name used.
   if ($dbname == 'chado') {
     $active_db = 'chado';
@@ -490,7 +490,7 @@ function chado_insert_record($table, $values, $options = []) {
   // that has all the values needed for insert with all foreign relationsihps
   // resolved.
   foreach ($values as $field => $value) {
-    // Make sure the field is in the table description. If not then return an 
+    // Make sure the field is in the table description. If not then return an
     // error message.
     if (!array_key_exists($field, $table_desc['fields'])) {
       tripal_report_error('tripal_chado', TRIPAL_ERROR,
@@ -640,7 +640,7 @@ function chado_insert_record($table, $values, $options = []) {
   if ($options['return_record'] == TRUE and $result) {
     if (array_key_exists('primary key', $table_desc) and is_array($table_desc['primary key'])) {
       foreach ($table_desc['primary key'] as $field) {
-        $sql = "SELECT CURRVAL('{" . $table . "_" . $field . "_seq}')";
+        $sql = "SELECT CURRVAL('{" . $table . "}_" . $field . "_seq')";
         $results = chado_query($sql);
         $value = $results->fetchField();
         if (!$value) {
@@ -910,7 +910,7 @@ function chado_update_record($table, $match, $values, $options = NULL) {
 
   // If we have a result then add primary keys to return array.
   if ($options['return_record'] == TRUE and $result) {
-    // Only if we have a single result do we want to add the primary keys to the 
+    // Only if we have a single result do we want to add the primary keys to the
     // values array.  If the update matched many records we can't add the pkeys.
 
     if (count($pkeys) == 1) {
@@ -1430,7 +1430,7 @@ function chado_select_record($table, $columns, $values, $options = NULL) {
         $where[] = $value;
       }
       // CASE 1c: If we have an integer indexed array and the first element is
-      // not an array then we have a simple array of values to be used for an 
+      // not an array then we have a simple array of values to be used for an
       // IN clause.
       elseif (is_int(key($value)) AND !is_array(current($value))) {
 
@@ -1453,7 +1453,7 @@ function chado_select_record($table, $columns, $values, $options = NULL) {
             $where[] = $subvalue;
           }
         }
-        // CASE 1e: We have a multi-dimensional array that doesn't fit any of 
+        // CASE 1e: We have a multi-dimensional array that doesn't fit any of
         // the above cases then we have a foreign key definition to follow.
         else {
 
@@ -1701,7 +1701,7 @@ function chado_select_record_check_value_type(&$op, &$value, $type) {
  * $args = array( ':feature_uniquename' => $form_state['values']['uniquename']
  *   );
  * $result = chado_query($sql, $args);
- * while ($r = $results->fetchObject()) { 
+ * while ($r = $results->fetchObject()) {
  *   // Do something with the record object $r
  * }
  * @endcode
@@ -1728,30 +1728,51 @@ function chado_query($sql, $args = []) {
     // Remove carriage returns from the SQL.
     $sql = preg_replace('/\n/', ' ', $sql);
 
+    // Get the current default Chado and Drupal schema prefixes.
+    $chado_schema_name = chado_get_schema_name('chado');
+    $drupal_schema_name = chado_get_schema_name('drupal');
+
     // Prefix the tables with their correct schema.
     // Chado tables should be enclosed in curly brackets (ie: {feature} )
     // and Drupal tables should be enclosed in square brackets
     // (ie: [tripal_jobs] ).
-    $chado_schema_name = chado_get_schema_name('chado');
-    $drupal_schema_name = chado_get_schema_name('drupal');
-    $sql = preg_replace('/\{(.*?)\}/', $chado_schema_name . '.$1', $sql);
-    $sql = preg_replace('/\[(\w+)\]/', $drupal_schema_name . '.$1', $sql);
+    $matches = [];
+    if (preg_match_all('/\{(.*?)\}/', $sql, $matches)) {
+      $matches = $matches[1];
+      $chado_tables = array_unique(array_keys(chado_get_table_names(TRUE)));
+      foreach ($matches as $match) {
+        if (in_array($match, $chado_tables)) {
+          $sql = preg_replace("/\{$match\}/", $chado_schema_name . '.' . $match, $sql);
+        }
+      }
+    }
+
+    // Now set the Drupal prefix if the table is surrounded by square brackets.
+    if (preg_match_all('/\[(.*?)\]/', $sql, $matches)) {
+      $matches = $matches[1];
+      $drupal_tables = array_unique(array_keys(drupal_get_schema()));
+      foreach ($matches as $match) {
+        if (in_array($match, $drupal_tables)) {
+          $sql = preg_replace("/\[$match\]/", $drupal_schema_name . '.' . $match, $sql);
+        }
+      }
+    }
 
-    // Add an alter hook to allow module developers to change the query right 
+    // Add an alter hook to allow module developers to change the query right
     // before it's  executed. Since all queriying of chado by Tripal eventually
     // goes through this function, we only need to provide an alter hook at this
-    // point in order to ensure developers have complete control over the query 
-    // being executed. For example, a module developer might want to remove 
-    // schema prefixing from queries and rely on the search path. This alter 
+    // point in order to ensure developers have complete control over the query
+    // being executed. For example, a module developer might want to remove
+    // schema prefixing from queries and rely on the search path. This alter
     // hook would allow them to do that by implementing
-    // mymodule_chado_query_alter($sql, $args) and using a regular expression 
+    // mymodule_chado_query_alter($sql, $args) and using a regular expression
     // to remove table prefixing from the query.
     // @see hook_chado_query_alter().
     drupal_alter('chado_query', $sql, $args);
 
     // The featureloc table has some indexes that use function that call other
-    // functions and those calls do not reference a schema, therefore, any 
-    // tables with featureloc must automaticaly have the chado schema set as 
+    // functions and those calls do not reference a schema, therefore, any
+    // tables with featureloc must automaticaly have the chado schema set as
     // active to find.
     if (preg_match('/' . $chado_schema_name . '.featureloc/i', $sql) or preg_match('/' . $chado_schema_name . '.feature/i', $sql)) {
       $previous_db = chado_set_active('chado');
@@ -1763,7 +1784,7 @@ function chado_query($sql, $args = []) {
         throw $e;
       }
     }
-    // For all other tables we should have everything in scope so just run the 
+    // For all other tables we should have everything in scope so just run the
     // query.
     else {
       $results = db_query($sql, $args);
@@ -1817,11 +1838,11 @@ function hook_chado_query_alter(&$sql, &$args) {
 
   // The following code is an example of how this alter function might be used.
   // Say you would like only a portion of node => feature connections available
-  // for a period of time or under a specific condition. To "hide" the other 
-  // connections you might create a temporary view of the chado_feature table 
+  // for a period of time or under a specific condition. To "hide" the other
+  // connections you might create a temporary view of the chado_feature table
   // that only includes the connections you would like to be available. In order
-  // to ensure this view is used rather than the original chado_feature table 
-  // you could alter all Tripal queries referring to chado_feature to instead 
+  // to ensure this view is used rather than the original chado_feature table
+  // you could alter all Tripal queries referring to chado_feature to instead
   //refer to your view.
   if (preg_match('/(\w+)\.chado_feature/', $sql, $matches)) {
 

+ 10 - 5
tripal_chado/api/tripal_chado.schema.api.inc

@@ -392,11 +392,16 @@ function chado_get_version($exact = FALSE, $warn_if_unsupported = FALSE) {
     $version = "1.11 or older";
   }
   else {
+    // We need to hardcode the schema here rather than rely on the db_query
+    // function to settle it because the db_query function needs to know the
+    // Chado version to make the table prefixes set properly (chicken and
+    // egg problem).
+    $chado_schema = chado_get_schema_name('chado');
     $sql = "
       SELECT value
-      FROM {chadoprop} CP
-        INNER JOIN {cvterm} CVT on CVT.cvterm_id = CP.type_id
-        INNER JOIN {cv} CV on CVT.cv_id = CV.cv_id
+      FROM $chado_schema.chadoprop CP
+        INNER JOIN $chado_schema.cvterm CVT on CVT.cvterm_id = CP.type_id
+        INNER JOIN $chado_schema.cv CV on CVT.cv_id = CV.cv_id
       WHERE CV.name = 'chado_properties' and CVT.name = 'version'
     ";
     if (!$is_local) {
@@ -498,7 +503,7 @@ function chado_get_table_names($include_custom = NULL) {
     }
   }
 
-  // now add in the custom tables too if requested
+  // Now add in the custom tables too if requested
   if ($include_custom) {
     $sql = "SELECT table_name FROM {tripal_custom_tables}";
     $resource = db_query($sql);
@@ -633,7 +638,7 @@ function chado_get_base_tables() {
   // whose foreign key constraints link to two or more base table.
   $final_list = [];
   foreach ($base_tables as $i => $tablename) {
-    // A few tables break our rule and seems to look 
+    // A few tables break our rule and seems to look
     // like a linking table, but we want to keep it as a base table.
     if ($tablename == 'biomaterial' or $tablename == 'assay' or $tablename == 'arraydesign') {
       $final_list[] = $tablename;

+ 8 - 13
tripal_chado/includes/TripalFields/sbo__relationship/sbo__relationship.inc

@@ -239,34 +239,29 @@ class sbo__relationship extends ChadoField {
     $this->base_type_column = 'table_name';
     switch ($instance['settings']['chado_table']) {
 
+      // TODO: note that Chado 1.4 will add types to, at least,
+      // project and analysis, at which point you should use the default instead.
       case 'acquisition_relationship':
       case 'analysis_relationship':
       case 'biomaterial_relationship':
       case 'cell_line_relationship':
       case 'quantification_relationship':
-        $this->base_type_column = 'table_name';
-        break;
       case 'element_relationship':
-        // RELATIONSHIP->subject_id_key->feature_id->name;
-        $this->base_name_columns = ['name'];
+      case 'project_relationship':
+      case 'pub_relationship':
         $this->base_type_column = 'table_name';
-        break;
+        $this->base_name_columns = ['name'];
+      break;
+
       case 'organism_relationship':
         $this->base_name_columns = ['genus', 'species'];
         $this->base_type_column = 'table_name';
         break;
-      case 'project_relationship':
-        $this->base_name_columns = ['name'];
-        $this->base_type_column = 'table_name';
-        break;
       case 'phylonode_relationship':
         $this->base_name_columns = ['label'];
         $this->base_type_column = 'table_name';
         break;
-      case 'pub_relationship':
-        $this->base_name_columns = ['name'];
-        $this->base_type_column = 'table_name';
-        break;
+
       case 'contact':
         $this->base_name_columns = ['name'];
         $this->base_type_column = 'type_id';

+ 4 - 3
tripal_chado/includes/TripalFields/sbo__relationship/sbo__relationship_formatter.inc

@@ -96,16 +96,17 @@ class sbo__relationship_formatter extends ChadoFieldFormatter {
       // Convert the object/subject to a link if an entity exists for it.
       if (array_key_exists('entity', $item['value']['local:relationship_object'])) {
         list($entity_type, $object_entity_id) = explode(':', $item['value']['local:relationship_object']['entity']);
+
         if ($object_entity_id != $entity->id) {
           $link = l($object_name, 'bio_data/' . $object_entity_id);
-          $phrase = preg_replace("/$object_name/", $link, $phrase);
+          $phrase = str_replace($object_name, $link, $phrase);
         }
       }
       if (array_key_exists('entity', $item['value']['local:relationship_subject'])) {
         list($entity_type, $subject_entity_id) = explode(':', $item['value']['local:relationship_subject']['entity']);
         if ($subject_entity_id != $entity->id) {
           $link = l($subject_name, 'bio_data/' . $subject_entity_id);
-          $phrase = preg_replace("/$subject_name/", $link, $phrase);
+          $phrase = str_replace($subject_name, $link, $phrase);
         }
       }
 
@@ -119,7 +120,7 @@ class sbo__relationship_formatter extends ChadoFieldFormatter {
     $items_per_page = array_key_exists('items_per_page', $this->instance['settings']) ? $this->instance['settings']['items_per_page'] : 10;
     $total_records = count($rows);
     $total_pages = (int) ($total_records / $items_per_page) + 1;
-    $pelement = 0; //$this->getPagerElementID();
+    $pelement = 0;
     $current_page = pager_default_initialize($total_records, $items_per_page, $pelement);
     $pager = theme('pager', [
       'tags' => [],

+ 80 - 1
tripal_chado/tripal_chado.install

@@ -29,6 +29,10 @@ function tripal_chado_install() {
       )
     ";
     chado_query($sql);
+
+    // Fix the SOFP feature_property issue from the legacy feature_property.
+    tripal_chado_fix_legacy_SOFP_7338();
+
   }
 
   tripal_insert_variable('bundle_category', 'Bundles can be categorized to allow for grouping');
@@ -683,6 +687,63 @@ function tripal_chado_chado_cvterm_mapping_schema() {
   return $schema;
 }
 
+
+
+/**
+ * Fixes a problem with the legacy feature_property/SOFP
+ * ontology loaded with previous verions of Chado and all terms are
+ * relationships.
+ *
+ * This function is called by the tripal_chado_install() for a
+ * new Tripal setup, and the tripal_chado_update_7338 for an existing
+ * site.
+ */
+
+function tripal_chado_fix_legacy_SOFP_7338() {
+
+  $sofp =  chado_get_db(['name' => 'SOFP']);
+  $fp = chado_get_cv(['name' => 'feature_property']);
+
+  // No need to update unless the SOFP db exists
+  if (!$sofp || !$fp) {
+    return;
+  }
+  $terms = chado_select_record('cvterm', ['cvterm_id', 'name'], [
+    'dbxref_id' => [
+      'db_id' => [
+        'name' => 'SOFP',
+      ],
+    ],
+    'cv_id' => ['name' => 'feature_property'],
+  ]);
+
+  if (empty($terms)) {
+    return;
+  }
+
+  foreach ($terms as $term) {
+
+    $id = $term->cvterm_id;
+    $name = $term->name;
+
+    if ($name == 'linked_to') {
+      continue;
+    }
+    chado_update_record('cvterm', ['cvterm_id' => $id], ['is_relationshiptype' => 0]);
+  }
+
+  // Repopulate the mview.
+  $mview_id = chado_get_mview_id('db2cv_mview');
+  global $user;
+  tripal_add_job(
+    'Repopulating db2cv to fix legacy SOFP',
+    'tripal_chado',
+    'chado_populate_mview',
+    [$mview_id],
+    $user->uid
+  );
+}
+
 /**
  * Fixes the phase on the tripal_gffcds_temp table used for importing GFF files, and fixes the db.name term mapping.
  *
@@ -1859,7 +1920,7 @@ function tripal_chado_update_7336() {
 /**
  * Update the NCBITaxon DB entry.
  */
-function tripal_chado_update_7337(){
+function tripal_chado_update_7337() {
 
   chado_insert_db(array(
     'name' => 'NCBITaxon',
@@ -1868,3 +1929,21 @@ function tripal_chado_update_7337(){
     'urlprefix' => 'https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?id={accession}',
   ));
 }
+
+/**
+ * Correctly flag SOFP terms as "not" relationships, allowing the mview to
+ * populate them.
+ */
+function tripal_chado_update_7338() {
+
+  try {
+    // Get all SOFP terms and set their is_relationshiptype to 0
+
+    tripal_chado_fix_legacy_SOFP_7338();
+
+  } catch (\PDOException $e) {
+    $error = $e->getMessage();
+    throw new DrupalUpdateException('Could not perform update: ' . $error);
+  }
+
+}

Some files were not shown because too many files changed in this diff