浏览代码

Issue #72: Updating API to include 2.1 improvements: a48bf3b

Stephen Ficklin 7 年之前
父节点
当前提交
5cc22b9da2

+ 1 - 1
legacy/tripal_core/includes/tripal_core.toc.inc

@@ -28,7 +28,7 @@ function tripal_core_node_toc_form($form, &$form_state, $node) {
       the following order in the Table of Contents (TOC). You may rename
       the following order in the Table of Contents (TOC). You may rename
       the titles or drag and drop them to change the order.  <b>Any changes will
       the titles or drag and drop them to change the order.  <b>Any changes will
       only apply to this page</b>. If you would like to make changes apply to multiple
       only apply to this page</b>. If you would like to make changes apply to multiple
-      pages of the same tpye, please visit the $admin_link. ") . '</p>' .
+      pages of the same type, please visit the $admin_link. ") . '</p>' .
       '<p>' . t('The list below shows all possible content panes that can appear.
       '<p>' . t('The list below shows all possible content panes that can appear.
       However, those without content are automatically hidden and do not
       However, those without content are automatically hidden and do not
       appear in the TOC.' . '</p>'),
       appear in the TOC.' . '</p>'),

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

@@ -134,8 +134,9 @@ function tripal_report_error($type, $severity, $message, $variables = array(), $
  * @param $message
  * @param $message
  *   The message to be displayed to the tripal administrators
  *   The message to be displayed to the tripal administrators
  * @param $importance
  * @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_CRITICAL: Critical conditions.
  *     - TRIPAL_ERROR: Error conditions.
  *     - TRIPAL_ERROR: Error conditions.
  *     - TRIPAL_WARNING: Warning conditions.
  *     - TRIPAL_WARNING: Warning conditions.
@@ -144,9 +145,9 @@ function tripal_report_error($type, $severity, $message, $variables = array(), $
  *     - TRIPAL_DEBUG: Debug-level messages.
  *     - TRIPAL_DEBUG: Debug-level messages.
  * @param $options
  * @param $options
  *   Any options to apply to the current message. Supported options include:
  *   Any options to apply to the current message. Supported options include:
- *     - return_html: return HTML instead of setting a drupal message. This can be
- *         used to place a tripal message in a particular place in the page.
- *         The default is FALSE.
+ *     - return_html: return HTML instead of setting a drupal message. This can
+ *       be used to place a tripal message in a particular place in the page.
+ *       The default is FALSE.
  */
  */
 function tripal_set_message($message, $importance = TRIPAL_INFO, $options = array()) {
 function tripal_set_message($message, $importance = TRIPAL_INFO, $options = array()) {
   global $user;
   global $user;

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

@@ -1580,10 +1580,12 @@ function chado_select_record_check_value_type(&$op, &$value, $type) {
 }
 }
 
 
 /**
 /**
- * Use this function instead of db_query() to avoid switching databases
- * when making query to the chado database
+ * A substitute for db_query() when querying from Chado.
  *
  *
- * Will use a chado persistent connection if it already exists
+ * This function is needed to avoid switching databases when making query to
+ * the chado database.
+ *
+ * Will use a chado persistent connection if it already exists.
  *
  *
  * @param $sql
  * @param $sql
  *   The sql statement to execute
  *   The sql statement to execute
@@ -1625,11 +1627,20 @@ function chado_query($sql, $args = array()) {
   // if Chado is local to the database then prefix the Chado table
   // if Chado is local to the database then prefix the Chado table
   // names with 'chado'.
   // names with 'chado'.
   if ($is_local) {
   if ($is_local) {
-    $sql = preg_replace('/\n/', '', $sql);  // remove carriage returns
+    // Remove carriage returns from the SQL.
+    $sql = preg_replace('/\n/', '', $sql);
+
+    // 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] ).
+    // @todo: remove assumption that the chado schema is called 'chado' and the
+    // drupal schema is called 'public'.
     $sql = preg_replace('/\{(.*?)\}/', 'chado.$1', $sql);
     $sql = preg_replace('/\{(.*?)\}/', 'chado.$1', $sql);
+    $sql = preg_replace('/\[(\w+)\]/', 'public.$1', $sql);
 
 
-    // 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
+    // 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 active to find
     // must automaticaly have the chado schema set as active to find
     if (preg_match('/chado.featureloc/i', $sql) or preg_match('/chado.feature/i', $sql)) {
     if (preg_match('/chado.featureloc/i', $sql) or preg_match('/chado.feature/i', $sql)) {
       $previous_db = chado_set_active('chado') ;
       $previous_db = chado_set_active('chado') ;
@@ -1648,6 +1659,16 @@ function chado_query($sql, $args = array()) {
       $results = db_query($sql, $args);
       $results = db_query($sql, $args);
     }
     }
   }
   }
+  // Check for any cross schema joins (ie: both drupal and chado tables
+  // represented and if present don't execute the query but instead warn the
+  // administrator.
+  else if (preg_match('/\[(\w*?)\]/', $sql)) {
+    tripal_report_error('chado_query', TRIPAL_ERROR,
+      'The following query does not support external chado databases. Please file an issue with the Drupal.org Tripal Project. Query: @query',
+       array('@query' => $sql)
+    );
+    return FALSE;
+  }
   // if Chado is not local to the Drupal database then we have to
   // if Chado is not local to the Drupal database then we have to
   // switch to another database
   // switch to another database
   else {
   else {