Forráskód Böngészése

Applied fixes for the D6 -> D7 upgrade

Stephen Ficklin 9 éve
szülő
commit
f5f7195ef5

+ 3 - 0
tripal_contact/tripal_contact.install

@@ -244,6 +244,8 @@ function tripal_contact_update_7200() {
   // site upgrade when the tripal_core module is disabled.
   module_load_include('module', 'tripal_core', 'tripal_core');
   tripal_core_import_api();
+  module_load_include('inc', 'tripal_cv', 'api/tripal_cv.api');
+
 
   // add the contact_type CV
   try {
@@ -440,6 +442,7 @@ function tripal_contact_update_7202() {
   // site upgrade when the tripal_core module is disabled.
   module_load_include('module', 'tripal_core', 'tripal_core');
   tripal_core_import_api();
+  module_load_include('inc', 'tripal_cv', 'api/tripal_cv.api');
 
   try {
     // Remove duplicates.

+ 13 - 1
tripal_core/api/tripal_core.chado_schema.api.inc

@@ -367,7 +367,19 @@ function chado_get_schema($table) {
 
   // get the table array from the proper chado schema
   $v = preg_replace("/\./", "_", $v); // reformat version for hook name
-  $table_arr = module_invoke_all("chado_schema_v" . $v . "_" . $table);
+
+  // Call the module_invoke_all.
+  $hook_name = "chado_schema_v" . $v . "_" . $table;
+  $table_arr = module_invoke_all($hook_name);
+
+  // If the module_invoke_all returned nothing then let's make sure there isn't
+  // An API call we can call directly.  The only time this occurs is
+  // during an upgrade of a major Drupal version and tripal_core is disabled.
+  if ((!$table_arr or count(array_keys(table_array) == 0)) and
+        function_exists('tripal_core_' . $hook_name)) {
+    $api_hook = "tripal_core_" . $hook_name;
+    $table_arr = $api_hook();
+  }
 
   // if the table_arr is empty then maybe this is a custom table
   if (!is_array($table_arr) or count($table_arr) == 0) {

+ 30 - 23
tripal_core/api/tripal_core.tripal.api.inc

@@ -3,13 +3,15 @@
  * @file
  * Provides an application programming interface (API) for Tripal
  *
- * The Tripal API currently provides generic insert/update/select functions for all chado content as
- * well as some module specific functions that insert/update/delete/select specific chado content.
+ * The Tripal API currently provides generic insert/update/select functions for
+ * all chado content as well as some module specific functions that
+ * insert/update/delete/select specific chado content.
  *
- * This API is currently in its infancy and some necessary functions might be missing. If you find
- * a missing function that you think should be included go to the sourceforge feature request
- * page and request it's inclusion in the API. Such feature requests with a working function
- * definition will be given priority.
+ * This API is currently in its infancy and some necessary functions might be
+ * missing. If you find a missing function that you think should be included
+ * go to the sourceforge feature request page and request it's inclusion in
+ * the API. Such feature requests with a working function definition will be
+ * given priority.
  */
 
 /**
@@ -17,13 +19,15 @@
  * @{
  * Provides an application programming interface (API) for Tripal
  *
- * The Tripal API currently provides generic insert/update/select functions for all chado content as
- * well as some module specific functions that insert/update/delete/select specific chado content.
+ * The Tripal API currently provides generic insert/update/select functions for
+ * all chado content as well as some module specific functions that
+ * insert/update/delete/select specific chado content.
  *
- * This API is currently in its infancy and some necessary functions might be missing. If you find
- * a missing function that you think should be included go to the sourceforge feature request
- * page and request it's inclusion in the API. Such feature requests with a working function
- * definition will be given priority.
+ * This API is currently in its infancy and some necessary functions might be
+ * missing. If you find a missing function that you think should be included
+ * go to the sourceforge feature request page and request it's inclusion in
+ * the API. Such feature requests with a working function definition will be
+ * given priority.
  * @}
  */
 
@@ -42,8 +46,8 @@ define('TRIPAL_DEBUG',7);
  * information to the message.
  *
  * @param $type
- *   The catagory to which this message belongs. Can be any string, but the general
- *   practice is to use the name of the module.
+ *   The catagory to which this message belongs. Can be any string, but the
+ *   general practice is to use the name of the module.
  * @param $severity
  *   The severity of the message; one of the following values:
  *     - TRIPAL_CRITICAL: Critical conditions.
@@ -53,16 +57,18 @@ define('TRIPAL_DEBUG',7);
  *     - TRIPAL_INFO: Informational messages.
  *     - TRIPAL_DEBUG: Debug-level messages.
  * @param $message
- *   The message to store in the log. Keep $message translatable by not concatenating
- *   dynamic values into it! Variables in the message should be added by using placeholder
- *   strings alongside the variables argument to declare the value of the placeholders.
- *   See t() for documentation on how $message and $variables interact.
+ *   The message to store in the log. Keep $message translatable by not
+ *   concatenating dynamic values into it! Variables in the message should be
+ *   added by using placeholder strings alongside the variables argument to
+ *   declare the value of the placeholders. See t() for documentation on how
+ *   $message and $variables interact.
  * @param $variables
- *   Array of variables to replace in the message on display or NULL if message is
- *   already translated or not possible to translate.
+ *   Array of variables to replace in the message on display or NULL if message
+ *   is already translated or not possible to translate.
  * @param $options
  *   An array of options. Some available options include:
- *     - print: prints the error message to the terminal screen. Useful when display is the command-line
+ *     - print: prints the error message to the terminal screen. Useful when
+ *         display is the command-line
  *
  * @ingroup tripal_api
  */
@@ -137,8 +143,9 @@ function tripal_report_error($type, $severity, $message, $variables = array(), $
  * @param $message
  *   The message to be displayed to the tripal administrators
  * @param $importance
- *   The level of importance for this message. In the future this will be used to allow
- *   administrators to filter some of these messages. It can be one of the following:
+ *   The level of importance for this message. In the future this will be used
+ *   to allow  administrators to filter some of these messages. It can be one
+ *   of the following:
  *     - TRIPAL_CRITICAL: Critical conditions.
  *     - TRIPAL_ERROR: Error conditions.
  *     - TRIPAL_WARNING: Warning conditions.

+ 2 - 1
tripal_core/tripal_core.module

@@ -687,7 +687,8 @@ function tripal_core_import_api() {
   module_load_include('inc', 'tripal_core', 'api/tripal_core.files.api');
   module_load_include('inc', 'tripal_core', 'api/tripal_core.jobs.api');
   module_load_include('inc', 'tripal_core', 'api/tripal_core.mviews.api');
-  module_load_include('inc', 'tripal_core', 'api/tripal_core.schema_V1.11.api');
+  module_load_include('inc', 'tripal_core', 'api/tripal_core.schema_v1.11.api');
   module_load_include('inc', 'tripal_core', 'api/tripal_core.schema_v1.2.api');
   module_load_include('inc', 'tripal_core', 'api/tripal_core.tripal_variables.api');
+  module_load_include('inc', 'tripal_core', 'api/tripal_core.tripal.api');
 }

+ 0 - 14
tripal_cv/api/tripal_cv.api.inc

@@ -96,20 +96,6 @@ function tripal_get_cv($identifiers, $options = array()) {
     );
   }
 
-  // Report an error if $cv is FALSE since then chado_generate_var has failed
-  elseif ($cv === FALSE) {
-    tripal_report_error(
-      'tripal_cv_api',
-      TRIPAL_ERROR,
-      "tripal_get_cv: chado_generate_var() failed to return a cv based on the identifiers
-        you passed in. You should check that your identifiers are correct, as well as, look
-        for a chado_generate_var error for additional clues. You passed in %identifier.",
-      array(
-        '%identifier'=> print_r($identifiers, TRUE)
-      )
-    );
-  }
-
   // Else, as far we know, everything is fine so give them their cv :)
   else {
     return $cv;

+ 23 - 82
tripal_feature/tripal_feature.install

@@ -340,6 +340,7 @@ function tripal_feature_update_7200() {
   // site upgrade when the tripal_core module is disabled.
   module_load_include('module', 'tripal_core', 'tripal_core');
   tripal_core_import_api();
+  module_load_include('inc', 'tripal_cv', 'api/tripal_cv.api');
 
   // During the upgrade from D6 to D7 the vocabulary terms assigned to features were
   // copied to the field_data_taxonomyextra table rather than to the correct
@@ -381,90 +382,30 @@ function tripal_feature_update_7200() {
 
   // set the default feature property vocabulary
   try {
-    $cv_id = db_query("SELECT cv_id FROM chado.cv WHERE name = 'feature_property'")->fetchField();
-    $cdi = db_select('tripal_cv_defaults', 't')
-      ->fields('t', array('cv_default_id'))
-      ->condition('table_name', 'featureprop')
-      ->condition('field_name', 'type_id')
-      ->execute()
-      ->fetchField();
-    if (!$cdi) {
-      db_insert('tripal_cv_defaults')
-        ->fields(array(
-          'table_name' => 'featureprop',
-          'field_name' => 'type_id',
-          'cv_id' => $cv_id
-          ))
-        ->execute();
-    }
-  }
-  catch (\PDOException $e) {
-    $error = $e->getMessage();
-    throw new DrupalUpdateException('Failed to set feature_property vocabulary as default: '. $error);
-  }
-
-  // add the feature_relationshp CV
-  try {
-    $cv_id = db_query("SELECT cv_id FROM chado.cv WHERE name = 'feature_relationship'")->fetchField();
-    if (!$cv_id) {
-      // add the vocabulary
-      $cv_id = db_insert('chado.cv')
-      ->fields(array(
-        'name' => 'feature_relationship',
-        'definition' => 'Contains types of relationships between features.'
-      ))
-      ->execute();
-    }
-    // use the new featureprop CV we just added
-    $cdi = db_select('tripal_cv_defaults', 't')
-      ->fields('t', array('cv_default_id'))
-      ->condition('table_name', 'feature_relationship')
-      ->condition('field_name', 'type_id')
-      ->execute()
-      ->fetchField();
-    if (!$cdi) {
-      db_insert('tripal_cv_defaults')
-        ->fields(array(
-          'table_name' => 'feature_relationship',
-          'field_name' => 'type_id',
-          'cv_id' => $cv_id
-        ))
-        ->execute();
-    }
-  }
-  catch (\PDOException $e) {
-    $error = $e->getMessage();
-    throw new DrupalUpdateException('Failed to add feature_relationship vocabulary: '. $error);
+    tripal_insert_cv(
+      'feature_relationship',
+      'Contains types of relationships between features.'
+    );
+
+    // the feature_property CV already exists... it comes with chado, but we need to
+    // add it just in case it doesn't get added before the feature module is installed
+    tripal_insert_cv(
+      'feature_property',
+      'Stores properties about features'
+    );
+
+    // the feature type vocabulary should be the sequence ontology, and even though
+    // this ontology should get loaded we will create it here just so that we can
+    // set the default vocabulary for the feature.type_id field
+    tripal_insert_cv(
+      'sequence',
+      'The Sequence Ontology'
+    );
+    tripal_set_default_cv('feature', 'type_id', 'sequence');
+    tripal_set_default_cv('featureprop', 'type_id', 'feature_property');
+    tripal_set_default_cv('feature_relationship', 'type_id', 'feature_relationship');
   }
 
-  // set the feature_type as the 'sequence' ontology
-  try {
-    $cv_id = db_query("SELECT cv_id FROM chado.cv WHERE name = 'sequence'")->fetchField();
-    if (!$cv_id) {
-      // add the vocabulary
-      $cv_id = db_insert('chado.cv')
-      ->fields(array(
-        'name' => 'sequence',
-        'definition' => 'The Sequence Ontology.'
-      ))
-      ->execute();
-    }
-    $cdi = db_select('tripal_cv_defaults', 't')
-      ->fields('t', array('cv_default_id'))
-      ->condition('table_name', 'feature')
-      ->condition('field_name', 'type_id')
-      ->execute()
-      ->fetchField();
-    if (!$cdi) {
-      db_insert('tripal_cv_defaults')
-        ->fields(array(
-          'table_name' => 'feature',
-          'field_name' => 'type_id',
-          'cv_id' => $cv_id
-        ))
-        ->execute();
-    }
-  }
   catch (\PDOException $e) {
     $error = $e->getMessage();
     throw new DrupalUpdateException('Failed to add sequence vocabulary which will be used for the sequence ontology: '. $error);

+ 5 - 64
tripal_featuremap/tripal_featuremap.install

@@ -495,74 +495,14 @@ function tripal_featuremap_update_7200() {
   // site upgrade when the tripal_core module is disabled.
   module_load_include('module', 'tripal_core', 'tripal_core');
   tripal_core_import_api();
+  module_load_include('inc', 'tripal_cv', 'api/tripal_cv.api');
 
   // set the default vocabularies
   // featuremap_units
   try {
-    $cv_id = db_query("SELECT cv_id FROM chado.cv WHERE name = 'featuremap_units'")->fetchField();
-    $cdi = db_select('tripal_cv_defaults', 't')
-      ->fields('t', array('cv_default_id'))
-      ->condition('table_name', 'featuremap')
-      ->condition('field_name', 'type_id')
-      ->execute()
-      ->fetchField();
-    if (!$cdi) {
-      db_insert('tripal_cv_defaults')
-        ->fields(array(
-          'table_name' => 'featuremap',
-          'field_name' => 'unittype_id',
-          'cv_id' => $cv_id
-        ))
-        ->execute();
-    }
-  }
-  catch (\PDOException $e) {
-    $error = $e->getMessage();
-    throw new DrupalUpdateException('Failed to set featuremap_units vocabulary as default: '. $error);
-  }
-
-  // featurepos_property
-  try {
-    $cv_id = db_query("SELECT cv_id FROM chado.cv WHERE name = 'featurepos_property'")->fetchField();
-    $cdi = db_select('tripal_cv_defaults', 't')
-      ->fields('t', array('cv_default_id'))
-      ->condition('table_name', 'featureposprop')
-      ->condition('field_name', 'type_id')
-      ->execute()
-      ->fetchField();
-    if (!$cdi) {
-      db_insert('tripal_cv_defaults')
-        ->fields(array(
-          'table_name' => 'featureposprop',
-          'field_name' => 'type_id',
-          'cv_id' => $cv_id
-        ))
-        ->execute();
-    }
-  }
-  catch (\PDOException $e) {
-    $error = $e->getMessage();
-    throw new DrupalUpdateException('Failed to set featurepos_property vocabulary as default: '. $error);
-  }
-
-  // featuremap_property
-  try {
-    $cv_id = db_query("SELECT cv_id FROM chado.cv WHERE name = 'featuremap_property'")->fetchField();
-    $cdi = db_select('tripal_cv_defaults', 't')
-      ->fields('t', array('cv_default_id'))
-      ->condition('table_name', 'featuremapprop')
-      ->condition('field_name', 'type_id')
-      ->execute()
-      ->fetchField();
-    if (!$cdi) {
-      db_insert('tripal_cv_defaults')
-       ->fields(array(
-         'table_name' => 'featuremapprop',
-         'field_name' => 'type_id',
-         'cv_id' => $cv_id
-        ))
-        ->execute();
-    }
+    tripal_set_default_cv('featuremap', 'unittype_id', 'featuremap_units');
+    tripal_set_default_cv('featureposprop', 'type_id', 'featurepos_property');
+    tripal_set_default_cv('featuremapprop', 'type_id', 'featuremap_property');
   }
   catch (\PDOException $e) {
     $error = $e->getMessage();
@@ -691,6 +631,7 @@ function tripal_featuremap_update_7202() {
   // site upgrade when the tripal_core module is disabled.
   module_load_include('module', 'tripal_core', 'tripal_core');
   tripal_core_import_api();
+  module_load_include('inc', 'tripal_cv', 'api/tripal_cv.api');
 
   try {
     tripal_set_default_cv('featuremap', 'unittype_id', 'featuremap_units');

+ 5 - 25
tripal_organism/tripal_organism.install

@@ -134,37 +134,17 @@ function tripal_organism_update_7200() {
   // site upgrade when the tripal_core module is disabled.
   module_load_include('module', 'tripal_core', 'tripal_core');
   tripal_core_import_api();
+  module_load_include('inc', 'tripal_cv', 'api/tripal_cv.api');
 
   // Add the new organism_property vocabulary
   // We cannot use the Tripal API calls in the 7000 update
   // because during upgrade the tripal_core should also be disabled
   try {
-    $cv_id = db_query("SELECT cv_id FROM chado.cv WHERE name = 'organism_property'")->fetchField();
-    if (!$cv_id) {
-      $sql = "INSERT INTO chado.cv (name, definition) VALUES (
+    tripal_insert_cv(
         'organism_property',
-        'Contains properties for organisms.')
-      ";
-      db_query($sql);
-    }
-    // If a record already exists then don't change it.
-    $cdi = db_select('tripal_cv_defaults', 't')
-      ->fields('t', array('cv_default_id'))
-      ->condition('table_name', 'organismprop')
-      ->condition('field_name', 'type_id')
-      ->execute()
-      ->fetchField();
-
-    // Add in the default vocabulary.
-    if (!$cdi) {
-      db_insert('tripal_cv_defaults')
-        ->fields(array(
-          'table_name' => 'organismprop',
-          'field_name' => 'type_id',
-          'cv_id' => $cv_id
-        ))
-        ->execute();
-    }
+        'Contains properties for organisms'
+    );
+    tripal_set_default_cv('organismprop', 'type_id', 'organism_property');
   }
   catch (\PDOException $e) {
     $error = $e->getMessage();

+ 1 - 0
tripal_pub/tripal_pub.install

@@ -479,6 +479,7 @@ function tripal_pub_update_7202() {
   // site upgrade when the tripal_core module is disabled.
   module_load_include('module', 'tripal_core', 'tripal_core');
   tripal_core_import_api();
+  module_load_include('inc', 'tripal_cv', 'api/tripal_cv.api');
 
   try {
     // Remove duplicates.