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

Start converting tripal_core from 6.x to 7.x

spficklin 12 éve
szülő
commit
55d6ec58ba

+ 2 - 1
tripal_core/api/tripal_core_ahah.api.inc

@@ -110,7 +110,8 @@ function tripal_core_ahah_prepare_form() {
 function tripal_core_ahah_bind_events() {
 function tripal_core_ahah_bind_events() {
   
   
   // Get the JS settings so we can merge them.
   // Get the JS settings so we can merge them.
-  $javascript = drupal_add_js(NULL, NULL, 'header');
+  $options = array('scope' => 'header'); 
+  $javascript = drupal_add_js(NULL, $options);
   $settings = call_user_func_array('array_merge_recursive', $javascript['setting']);
   $settings = call_user_func_array('array_merge_recursive', $javascript['setting']);
   
   
   return array('ahah' => $settings['ahah']);
   return array('ahah' => $settings['ahah']);

+ 106 - 172
tripal_core/api/tripal_core_chado.api.inc

@@ -176,7 +176,7 @@ function tripal_core_chado_insert($table, $values, $options = array()) {
     // make sure the field is in the table description. If not then return an error
     // make sure the field is in the table description. If not then return an error
     // message
     // message
     if (!array_key_exists($field, $table_desc['fields'])) {
     if (!array_key_exists($field, $table_desc['fields'])) {
-      watchdog('tripal_core', "tripal_core_chado_insert: The field '%field' does not exist ".
+      watchdog('tripal_core', "tripal_core_chado_insert: The field '%field' does not exist " .
         "for the table '%table'.  Cannot perform insert. Values: %array",
         "for the table '%table'.  Cannot perform insert. Values: %array",
         array('%field' => $field, '%table' => $table, '%array' => print_r($values, 1)), WATCHDOG_ERROR);
         array('%field' => $field, '%table' => $table, '%array' => print_r($values, 1)), WATCHDOG_ERROR);
       return FALSE;
       return FALSE;
@@ -351,7 +351,7 @@ function tripal_core_chado_insert($table, $values, $options = array()) {
         $is_prepared = tripal_core_chado_prepare("currval_" . $table . "_" . $field, $psql, array());
         $is_prepared = tripal_core_chado_prepare("currval_" . $table . "_" . $field, $psql, array());
         $value = '';
         $value = '';
         if ($is_prepared) {
         if ($is_prepared) {
-           $value = db_result(chado_query("EXECUTE currval_". $table . "_" . $field));
+           $value = db_result(chado_query("EXECUTE currval_" . $table . "_" . $field));
            if (!$value) {
            if (!$value) {
             watchdog('tripal_core', "tripal_core_chado_insert: not able to retrieve primary key after insert: %sql",
             watchdog('tripal_core', "tripal_core_chado_insert: not able to retrieve primary key after insert: %sql",
               array('%sql' => $psql), WATCHDOG_ERROR);
               array('%sql' => $psql), WATCHDOG_ERROR);
@@ -786,7 +786,7 @@ function tripal_core_chado_update($table, $match, $values, $options = NULL) {
     return TRUE;
     return TRUE;
   }
   }
   else {
   else {
-    watchdog('tripal_core', "Cannot update record in $table table.  \nMatch:" . print_r($match, 1) . "\nValues: ". print_r($values, 1), array(), 'WATCHDOG_ERROR');
+    watchdog('tripal_core', "Cannot update record in $table table.  \nMatch:" . print_r($match, 1) . "\nValues: " . print_r($values, 1), array(), 'WATCHDOG_ERROR');
     return FALSE;
     return FALSE;
   }
   }
 
 
@@ -1050,7 +1050,7 @@ function tripal_core_chado_delete($table, $match, $options = NULL) {
     return TRUE;
     return TRUE;
   }
   }
   else {
   else {
-    watchdog('tripal_core', "Cannot delete record in $table table.  Match:" . print_r($match, 1) . ". Values: ". print_r($values, 1), array(), 'WATCHDOG_ERROR');
+    watchdog('tripal_core', "Cannot delete record in $table table.  Match:" . print_r($match, 1) . ". Values: " . print_r($values, 1), array(), 'WATCHDOG_ERROR');
     return FALSE;
     return FALSE;
   }
   }
   return FALSE;
   return FALSE;
@@ -1295,8 +1295,8 @@ function tripal_core_chado_select($table, $columns, $values, $options = NULL) {
         // if there is no value (default or otherwise) check if this field is
         // if there is no value (default or otherwise) check if this field is
         // allowed to be null
         // allowed to be null
         elseif (!$table_desc['fields'][$field]['not null']) {
         elseif (!$table_desc['fields'][$field]['not null']) {
-        	$new_values[$field] = NULL;
-          $uq_sname .= "n".substr($field, 0, 2);
+          $new_values[$field] = NULL;
+          $uq_sname .= "n" . substr($field, 0, 2);
           if (!$has_pkey) {
           if (!$has_pkey) {
             array_push($new_columns, $field);
             array_push($new_columns, $field);
           }
           }
@@ -1305,9 +1305,9 @@ function tripal_core_chado_select($table, $columns, $values, $options = NULL) {
         // and there is no default value then we cannot check if the record
         // and there is no default value then we cannot check if the record
         // is a duplicate so return FALSE
         // is a duplicate so return FALSE
         else {
         else {
-        	watchdog('tripal_core', "tripal_core_chado_select: There is no value for %field"
-        		." thus we cannot check if this record is unique",
-        		array('%field' => $field), WATCHDOG_ERROR);
+          watchdog('tripal_core', "tripal_core_chado_select: There is no value for %field"
+            . " thus we cannot check if this record is unique",
+            array('%field' => $field), WATCHDOG_ERROR);
           return FALSE;
           return FALSE;
         }
         }
       }
       }
@@ -1334,7 +1334,7 @@ function tripal_core_chado_select($table, $columns, $values, $options = NULL) {
     // make sure the field is in the table description. If not then return an error
     // make sure the field is in the table description. If not then return an error
     // message
     // message
     if (!array_key_exists($field, $table_desc['fields'])) {
     if (!array_key_exists($field, $table_desc['fields'])) {
-      watchdog('tripal_core', "tripal_core_chado_select: The field '%field' does not exist ".
+      watchdog('tripal_core', "tripal_core_chado_select: The field '%field' does not exist " .
         "for the table '%table'.  Cannot perform query. Values: %array",
         "for the table '%table'.  Cannot perform query. Values: %array",
         array('%field' => $field, '%table' => $table, '%array' => print_r($values, 1)), WATCHDOG_ERROR);
         array('%field' => $field, '%table' => $table, '%array' => print_r($values, 1)), WATCHDOG_ERROR);
       return array();
       return array();
@@ -1378,7 +1378,7 @@ function tripal_core_chado_select($table, $columns, $values, $options = NULL) {
       // need to catch a 0 and make int if integer field
       // need to catch a 0 and make int if integer field
       // but we don't want to catch a NULL
       // but we don't want to catch a NULL
       if ($value === NULL) {
       if ($value === NULL) {
-      	$where[$field] = NULL;
+        $where[$field] = NULL;
       }
       }
       elseif ($table_desc['fields'][$field]['type'] == 'int') {
       elseif ($table_desc['fields'][$field]['type'] == 'int') {
         $where[$field][] = (int) $value;
         $where[$field][] = (int) $value;
@@ -1427,10 +1427,10 @@ function tripal_core_chado_select($table, $columns, $values, $options = NULL) {
       }
       }
       // if we have a null value then we need an IS NULL in our where statement
       // if we have a null value then we need an IS NULL in our where statement
       elseif ($value === NULL) {
       elseif ($value === NULL) {
-				$sql .= "$field IS NULL AND ";
-				$psql .= "$field IS NULL AND ";
-				// Need to remove one from the argument count b/c nulls don't add an argument
-				$i--;
+        $sql .= "$field IS NULL AND ";
+        $psql .= "$field IS NULL AND ";
+        // Need to remove one from the argument count b/c nulls don't add an argument
+        $i--;
       }
       }
       // if we have a single value then we need an = in our where statement
       // if we have a single value then we need an = in our where statement
       else {
       else {
@@ -1493,7 +1493,7 @@ function tripal_core_chado_select($table, $columns, $values, $options = NULL) {
     $sql = drupal_substr($sql, 0, -4);  // get rid of the trailing 'AND '
     $sql = drupal_substr($sql, 0, -4);  // get rid of the trailing 'AND '
     $psql = drupal_substr($psql, 0, -4);  // get rid of the trailing 'AND '
     $psql = drupal_substr($psql, 0, -4);  // get rid of the trailing 'AND '
 
 
-  } // end if(empty($where)){ } else {
+  } // end if (empty($where)){ } else {
 
 
   // finally add any ordering of the results to the SQL statement
   // finally add any ordering of the results to the SQL statement
   if (count($options['order_by']) > 0) {
   if (count($options['order_by']) > 0) {
@@ -1625,9 +1625,9 @@ function tripal_core_chado_get_foreign_key($table_desc, $field, $values, $option
       if (is_array($def['table'])) {
       if (is_array($def['table'])) {
         //foreign key was described 2X
         //foreign key was described 2X
         $message = "The foreign key " . $name . " was defined twice. Please check modules "
         $message = "The foreign key " . $name . " was defined twice. Please check modules "
-          ."to determine if hook_chado_schema_<version>_" . $table_desc['table'] . "() was "
-          ."implemented and defined this foreign key when it wasn't supposed to. Modules "
-          ."this hook was implemented in: " . implode(', ',
+          . "to determine if hook_chado_schema_<version>_" . $table_desc['table'] . "() was "
+          . "implemented and defined this foreign key when it wasn't supposed to. Modules "
+          . "this hook was implemented in: " . implode(', ',
         module_implements("chado_" . $table_desc['table'] . "_schema")) . ".";
         module_implements("chado_" . $table_desc['table'] . "_schema")) . ".";
         watchdog('tripal_core', $message);
         watchdog('tripal_core', $message);
         drupal_set_message(check_plain($message), 'error');
         drupal_set_message(check_plain($message), 'error');
@@ -1660,7 +1660,7 @@ function tripal_core_chado_get_foreign_key($table_desc, $field, $values, $option
     // relationship expected but we don't have any definition for one in the
     // relationship expected but we don't have any definition for one in the
     // table schema??
     // table schema??
     $version = tripal_core_get_chado_version(TRUE);
     $version = tripal_core_get_chado_version(TRUE);
-    $message = t("There is no foreign key relationship defined for " . $field . ".
+    $message = t("There is no foreign key relationship defined for " . $field . " .
        To define a foreign key relationship, determine the table this foreign
        To define a foreign key relationship, determine the table this foreign
        key referrs to (<foreign table>) and then implement
        key referrs to (<foreign table>) and then implement
        hook_chado_chado_schema_v<version>_<foreign table>(). See
        hook_chado_chado_schema_v<version>_<foreign table>(). See
@@ -1781,8 +1781,8 @@ function tripal_core_generate_chado_var($table, $values, $base_options = array()
   // get description for the current table----------------------------------------------------------
   // get description for the current table----------------------------------------------------------
   $table_desc = tripal_core_get_chado_table_schema($table);
   $table_desc = tripal_core_get_chado_table_schema($table);
   if (!$table_desc or count($table_desc) == 0) {
   if (!$table_desc or count($table_desc) == 0) {
-    watchdog('tripal_core', "tripal_core_generate_chado_var: The table '%table' has not been defined. ".
-             "and cannot be expanded. If this is a custom table, please add it using the Tripal ".
+    watchdog('tripal_core', "tripal_core_generate_chado_var: The table '%table' has not been defined. " .
+             "and cannot be expanded. If this is a custom table, please add it using the Tripal " .
              "custom table interface.", array('%table' => $table), WATCHDOG_ERROR);
              "custom table interface.", array('%table' => $table), WATCHDOG_ERROR);
     if ($return_array) {
     if ($return_array) {
       return array();
       return array();
@@ -1814,7 +1814,7 @@ function tripal_core_generate_chado_var($table, $values, $base_options = array()
 
 
     //if criteria then remove from query
     //if criteria then remove from query
     // @coder-ignore: only module designers can populate $criteria -not security risk
     // @coder-ignore: only module designers can populate $criteria -not security risk
-    $success = drupal_eval('<?php return ' . $criteria . '; ?>');
+    $success = php_eval('<?php return ' . $criteria . '; ?>');
     //    watchdog('tripal_core',
     //    watchdog('tripal_core',
     //      'Evaluating criteria (%criteria) for field %field in tripal_core_generate_chado_var for %table evaluated to %success',
     //      'Evaluating criteria (%criteria) for field %field in tripal_core_generate_chado_var for %table evaluated to %success',
     //      array('%table' => $table, '%criteria'=>$criteria, '%field' => $field_name, '%success'=>$success),
     //      array('%table' => $table, '%criteria'=>$criteria, '%field' => $field_name, '%success'=>$success),
@@ -1850,7 +1850,7 @@ function tripal_core_generate_chado_var($table, $values, $base_options = array()
         }
         }
         //if criteria then remove from query
         //if criteria then remove from query
         // @coder-ignore: only module designers can populate $criteria -not security risk
         // @coder-ignore: only module designers can populate $criteria -not security risk
-        $success = drupal_eval('<?php return ' . $criteria . '; ?>');
+        $success = php_eval('<?php return ' . $criteria . '; ?>');
         //        watchdog('tripal_core',
         //        watchdog('tripal_core',
         //          'Evaluating criteria (%criteria) for field %field of $type in tripal_core_generate_chado_var for %table evaluated to %success',
         //          'Evaluating criteria (%criteria) for field %field of $type in tripal_core_generate_chado_var for %table evaluated to %success',
         //          array('%table'=>$table, '%criteria'=>$criteria, '%field'=>$field_name, '%type'=>$field_type, '%success'=>$success),
         //          array('%table'=>$table, '%criteria'=>$criteria, '%field'=>$field_name, '%type'=>$field_type, '%success'=>$success),
@@ -1897,7 +1897,7 @@ function tripal_core_generate_chado_var($table, $values, $base_options = array()
         $criteria = preg_replace('/&gt;field_value&lt; /', addslashes($object->{$field_name}), $criteria);
         $criteria = preg_replace('/&gt;field_value&lt; /', addslashes($object->{$field_name}), $criteria);
         //if criteria then remove from query
         //if criteria then remove from query
         // @coder-ignore: only module designers can populate $criteria -not security risk
         // @coder-ignore: only module designers can populate $criteria -not security risk
-        $success = drupal_eval('<?php return ' . $criteria . '; ?>');
+        $success = php_eval('<?php return ' . $criteria . '; ?>');
         //      watchdog('tripal_core',
         //      watchdog('tripal_core',
         //        'Evaluating criteria (%criteria) for field %field in tripal_core_generate_chado_var for   %table evaluated to %success',
         //        'Evaluating criteria (%criteria) for field %field in tripal_core_generate_chado_var for   %table evaluated to %success',
         //        array('%table' => $table, '%criteria'=>$criteria, '%field' => $field_name, '%success'=>$success),
         //        array('%table' => $table, '%criteria'=>$criteria, '%field' => $field_name, '%success'=>$success),
@@ -2117,7 +2117,7 @@ function tripal_core_expand_chado_vars($object, $type, $to_expand, $table_option
         }
         }
       }
       }
       else {
       else {
-        watchdog('tripal_core', 'tripal_core_expand_chado_vars: Field (%field) not in the right format. ".
+        watchdog('tripal_core', 'tripal_core_expand_chado_vars: Field (%field) not in the right format. " .
           "It should be <tablename>.<fieldname>', WATCHDOG_ERROR);
           "It should be <tablename>.<fieldname>', WATCHDOG_ERROR);
       }
       }
       break;
       break;
@@ -2420,95 +2420,34 @@ function chado_query_range($query) {
  *
  *
  * @param $sql
  * @param $sql
  *   The sql statement to execute
  *   The sql statement to execute
+ *   
+ * @param $args
+ *   The array of arguments, with the same structure as passed to 
+ *   the db_query() function of Drupal.
  *
  *
- * @returns
- *   A database query result resource or FALSE if the query was not
- *   executed correctly
+ * @return
+ *   DatabaseStatementInterface A prepared statement object, already executed.
  *
  *
  * @ingroup tripal_chado_api
  * @ingroup tripal_chado_api
  */
  */
-function chado_query($sql) {
-  global $persistent_chado;
-
-  $is_local = tripal_core_is_chado_local();
-
-  $args = func_get_args();
-  array_shift($args); // remove the $sql from the argument list
-  if (isset($args[0]) and is_array($args[0])) { // 'All arguments in one array' syntax
-    $args = $args[0];
-  }
-
-  // run the Drupal command to clean up the SQL
-  _db_query_callback($args, TRUE);
-  $sql = preg_replace_callback(DB_QUERY_REGEXP, '_db_query_callback', $sql);
-
-  // add the chado schema to the table names if Chado is local to the Drupal database
+function chado_query($sql, $args = array()) {
+  global $_tripal_core_persistent_chado;
+  
+  // if Chado is local to the database then prefix the Chado table
+  // names with 'chado'.
   if ($is_local) {
   if ($is_local) {
-    $sql = preg_replace('/\n/', '', $sql);  // remove carriage returns
+  	$sql = preg_replace('/\n/', '', $sql);  // remove carriage returns
     $sql = preg_replace('/\{(.*?)\}/', 'chado.$1', $sql);
     $sql = preg_replace('/\{(.*?)\}/', 'chado.$1', $sql);
+    $results = db_query($sql, $args);
   }
   }
-
-  // let Drupal add any prefixes to tables
-  $sql = db_prefix_tables($sql);
-
-  // Execute the query on the chado database/schema
-  // Use the persistent chado connection if it already exists
-  if ($persistent_chado) {
-
-    $query = $sql;
-    // Duplicate the _db_query code in order to ensure that the drupal
-    // $active_db variable is not used in the pg_query command
-    // thus changed $active_db to $persistent_chado
-    // START COPY FROM _db_query in database.pgsql.inc
-    if (variable_get('dev_query', 0)) {
-      list($usec, $sec) = explode(' ', microtime());
-      $timer = (float) $usec + (float) $sec;
-    }
-    // if we're local we can just run the query
-    if ($is_local) {
-      //dpm($query);
-      $last_result = pg_query($persistent_chado, $query);
-    }
-    else {
-      $previous_db = tripal_db_set_active('chado');
-      $last_result = pg_query($persistent_chado, $query);
-      tripal_db_set_active($previous_db);
-    }
-
-    if (variable_get('dev_query', 0)) {
-      $bt = debug_backtrace();
-      $query = $bt[2]['function'] . "\n" . $query;
-      list($usec, $sec) = explode(' ', microtime());
-      $stop = (float) $usec + (float) $sec;
-      $diff = $stop - $timer;
-      $queries[] = array($query, $diff);
-    }
-
-    if ($last_result !== FALSE) {
-      return $last_result;
-    }
-    else {
-      // Indicate to drupal_error_handler that this is a database error.
-      ${DB_ERROR} = TRUE;
-      trigger_error(check_plain(pg_last_error($persistent_chado) . "\nquery: " . $query), E_USER_WARNING);
-      return FALSE;
-    }
-    // END COPY FROM _db_query in database.pgsql.inc
-  }
+  // if Chado is not local to the Drupal database then we have to 
+  // switch to another database
   else {
   else {
-    // before running the query we want to prefix the table names with
-    // the chado schema.  Previously use had to make changes to the
-    // search_path but that caused a lot of database calls and wasted
-    // resources during long jobs.
-    if ($is_local) {
-      $results = _db_query($sql);
-    }
-    else {
-      $previous_db = tripal_db_set_active('chado') ;
-      $results = _db_query($sql);
-      tripal_db_set_active($previous_db);
-    }
+    $previous_db = tripal_db_set_active('chado') ;
+    $results = _db_query($sql);
+    tripal_db_set_active($previous_db);
   }
   }
+  
   return $results;
   return $results;
 }
 }
 
 
@@ -2656,7 +2595,7 @@ $cv_name, $value, $update_if_present = 0) {
   
   
   $options = array('statement_name' => 'sel_cvterm_cv');
   $options = array('statement_name' => 'sel_cvterm_cv');
   $term = tripal_core_chado_select('cvterm', array('cvterm_id'), $values, $options);  
   $term = tripal_core_chado_select('cvterm', array('cvterm_id'), $values, $options);  
-  if(!$term or count($term) == 0) {
+  if (!$term or count($term) == 0) {
     watchdog('tripal_core', "Cannot find property '%prop_name'.",
     watchdog('tripal_core', "Cannot find property '%prop_name'.",
       array('%prop_name' => $property), WATCHDOG_ERROR);
       array('%prop_name' => $property), WATCHDOG_ERROR);
     return FALSE;
     return FALSE;
@@ -2902,7 +2841,6 @@ function tripal_db_set_active($dbname  = 'default') {
 
 
     // if this is the default database then set the search path and return
     // if this is the default database then set the search path and return
     if (strcmp($dbname, 'default')==0) {
     if (strcmp($dbname, 'default')==0) {
-      tripal_db_set_default_search_path();
       return db_set_active($dbname);
       return db_set_active($dbname);
     }
     }
     // if the user requests a database other than the default
     // if the user requests a database other than the default
@@ -2965,24 +2903,6 @@ function tripal_db_set_chado_search_path($dbname) {
   }
   }
 }
 }
 
 
-/**
- * Set the default search_path for PostgreSQL
- *
- * Sets the database search_path for postgreSQL to the
- * default schema.
- *
- * @ingroup tripal_chado_api
- */
-function tripal_db_set_default_search_path() {
-  // we make the assumption that the default schema is 'public'.
-  $chado_exists = variable_get('chado_schema_exists', FALSE);
-  if ($chado_exists) {
-    db_query('set search_path to %s', 'public,chado');
-  }
-  else {
-    db_query('set search_path to %s', 'public');
-  }
-}
 /**
 /**
  * Indicates if the SQL statement is prepapred
  * Indicates if the SQL statement is prepapred
  *
  *
@@ -2993,15 +2913,15 @@ function tripal_db_set_default_search_path() {
  *   TRUE if the statement is preapred, FALSE otherwise
  *   TRUE if the statement is preapred, FALSE otherwise
  */
  */
 function tripal_core_is_sql_prepared($statement_name) {
 function tripal_core_is_sql_prepared($statement_name) {
-  global $prepared_statements;
+  global $_tripal_core_prepared_statements;
 
 
-  if (!is_array($prepared_statements)) {
+  if (!is_array($_tripal_core_prepared_statements)) {
     watchdog('tripal_core', "tripal_core_is_sql_prepared: argument must be an array", array(), WATCHDOG_ERROR);
     watchdog('tripal_core', "tripal_core_is_sql_prepared: argument must be an array", array(), WATCHDOG_ERROR);
       return FALSE;
       return FALSE;
   }
   }
 
 
   // check to see if the statement is prepared already
   // check to see if the statement is prepared already
-  if (in_array($statement_name, $prepared_statements)) {
+  if (in_array($statement_name, $_tripal_core_prepared_statements)) {
     return TRUE;
     return TRUE;
   }
   }
 
 
@@ -3030,10 +2950,10 @@ function tripal_core_is_sql_prepared($statement_name) {
  *   be the type of value needed (ie: text, int, etc.)
  *   be the type of value needed (ie: text, int, etc.)
  */
  */
 function tripal_core_chado_prepare($statement_name, $psql, $args) {
 function tripal_core_chado_prepare($statement_name, $psql, $args) {
-  global $persistent_chado;
-  global $prepared_statements;
+  global $_tripal_core_persistent_chado;
+  global $_tripal_core_prepared_statements;
 
 
-  if (!$persistent_chado) {
+  if (!$_tripal_core_persistent_chado) {
     watchdog('tripal_core', "chado_prepare: not able to prepare '%name' statement as no persistent connection is available", array('%name' => $statement_name, '%sql' => $psql), WATCHDOG_ERROR);
     watchdog('tripal_core', "chado_prepare: not able to prepare '%name' statement as no persistent connection is available", array('%name' => $statement_name, '%sql' => $psql), WATCHDOG_ERROR);
     return FALSE;
     return FALSE;
   }
   }
@@ -3041,15 +2961,15 @@ function tripal_core_chado_prepare($statement_name, $psql, $args) {
   // Check to see if this statement was already prepared
   // Check to see if this statement was already prepared
   if (tripal_core_is_sql_prepared($statement_name)) {
   if (tripal_core_is_sql_prepared($statement_name)) {
     // check that the arguments are the same
     // check that the arguments are the same
-    $prepared_args = $prepared_statements[$statement_name]['prepared_args'];
-    $prepared_sql = $prepared_statements[$statement_name]['prepared_sql'];
+    $prepared_args = $_tripal_core_prepared_statements[$statement_name]['prepared_args'];
+    $prepared_sql = $_tripal_core_prepared_statements[$statement_name]['prepared_sql'];
     if ($prepared_args == $args) {
     if ($prepared_args == $args) {
       // This statement is already prepared
       // This statement is already prepared
       return TRUE;
       return TRUE;
     }
     }
     else {
     else {
       // Although a statement with this name is already prepared it is not the same!
       // Although a statement with this name is already prepared it is not the same!
-      watchdog('tripal_core', "chado_prepare: '%name' statement already prepared with different arguments! ".
+      watchdog('tripal_core', "chado_prepare: '%name' statement already prepared with different arguments! " .
         "You want to prepare \n%sql\n with \n%values\n and the existing statement is \n%esql\n with \n%existing",
         "You want to prepare \n%sql\n with \n%values\n and the existing statement is \n%esql\n with \n%existing",
         array('%name' => $statement_name, '%sql' => $psql, '%values' => print_r($args, TRUE), '%esql' => $prepared_sql,
         array('%name' => $statement_name, '%sql' => $psql, '%values' => print_r($args, TRUE), '%esql' => $prepared_sql,
           '%existing' => print_r($prepared_args, TRUE)), WATCHDOG_ERROR);
           '%existing' => print_r($prepared_args, TRUE)), WATCHDOG_ERROR);
@@ -3063,9 +2983,9 @@ function tripal_core_chado_prepare($statement_name, $psql, $args) {
     return FALSE;
     return FALSE;
   }
   }
   else {
   else {
-    $prepared_statements[$statement_name] = array();
-    $prepared_statements[$statement_name]['prepared_args'] = $args;
-    $prepared_statements[$statement_name]['prepared_sql'] = $psql;
+    $_tripal_core_prepared_statements[$statement_name] = array();
+    $_tripal_core_prepared_statements[$statement_name]['prepared_args'] = $args;
+    $_tripal_core_prepared_statements[$statement_name]['prepared_sql'] = $psql;
     return TRUE;
     return TRUE;
   }
   }
 }
 }
@@ -3082,7 +3002,7 @@ function tripal_core_chado_prepare($statement_name, $psql, $args) {
  *   An array of values in the execute sql statement
  *   An array of values in the execute sql statement
  */
  */
 function tripal_core_chado_execute_prepared($statement_name, $sql, $values) {
 function tripal_core_chado_execute_prepared($statement_name, $sql, $values) {
-  global $prepared_statements;
+  global $_tripal_core_prepared_statements;
 
 
   if (!tripal_core_is_sql_prepared($statement_name)) {
   if (!tripal_core_is_sql_prepared($statement_name)) {
     watchdog('tripal_core', "tripal_core_chado_execute_prepared: Cannot execute an unprepared statement: '%name'", array('%name' => $statement_name), WATCHDOG_ERROR);
     watchdog('tripal_core', "tripal_core_chado_execute_prepared: Cannot execute an unprepared statement: '%name'", array('%name' => $statement_name), WATCHDOG_ERROR);
@@ -3090,7 +3010,7 @@ function tripal_core_chado_execute_prepared($statement_name, $sql, $values) {
   }
   }
 
 
   // Before Executing, Ensure that all the values are supplied
   // Before Executing, Ensure that all the values are supplied
-  $required_values = $prepared_statements[$statement_name]['prepared_args'];
+  $required_values = $_tripal_core_prepared_statements[$statement_name]['prepared_args'];
   if (!$required_values) {
   if (!$required_values) {
     watchdog('tripal_core', "tripal_core_chado_execute_prepared: missing prepare arguments for this statement: '%name'", array('%name' => $statement_name), WATCHDOG_ERROR);
     watchdog('tripal_core', "tripal_core_chado_execute_prepared: missing prepare arguments for this statement: '%name'", array('%name' => $statement_name), WATCHDOG_ERROR);
     return FALSE;
     return FALSE;
@@ -3158,7 +3078,7 @@ function tripal_core_chado_execute_prepared($statement_name, $sql, $values) {
     watchdog('tripal_core', "chado_execute_prepared: wrong number of arguments supplied for '%name' statement. ' .
     watchdog('tripal_core', "chado_execute_prepared: wrong number of arguments supplied for '%name' statement. ' .
       'Expected %required but recieved %values. Statement: %statement.",
       'Expected %required but recieved %values. Statement: %statement.",
       array('%name' => $statement_name, '%required' => print_r($required_values, TRUE),
       array('%name' => $statement_name, '%required' => print_r($required_values, TRUE),
-        '%values' => print_r($values, TRUE), '%statement' => $prepared_statements[$statement_name]['prepared_sql']), WATCHDOG_ERROR);
+        '%values' => print_r($values, TRUE), '%statement' => $_tripal_core_prepared_statements[$statement_name]['prepared_sql']), WATCHDOG_ERROR);
     return FALSE;
     return FALSE;
   }
   }
 }
 }
@@ -3169,19 +3089,19 @@ function tripal_core_chado_execute_prepared($statement_name, $sql, $values) {
  * If no statement_name_regex is supplied then it clears ALL prepared statements;
  * If no statement_name_regex is supplied then it clears ALL prepared statements;
  * Otherwise, it clears prepared statement names that match the regex provided
  * Otherwise, it clears prepared statement names that match the regex provided
  */
  */
-function tripal_core_chado_clear_prepared ($statement_name_regex = NULL) {
-  global $prepared_statements;
+function tripal_core_chado_clear_prepared($statement_name_regex = NULL) {
+  global $_tripal_core_prepared_statements;
 
 
   if ($statement_name_regex) {
   if ($statement_name_regex) {
-    $resource = chado_query("SELECT * FROM pg_catalog.pg_prepared_statements WHERE name~'%s'",$statement_name_regex);
+    $resource = chado_query("SELECT * FROM pg_catalog.pg_prepared_statements WHERE name~'%s'", $statement_name_regex);
     while ($r = db_fetch_object($resource)) {
     while ($r = db_fetch_object($resource)) {
-      $k = array_search($r->name, $prepared_statements);
-      unset($prepared_statements[$k]);
-      chado_query('DEALLOCATE PREPARE %s',$r->name);
+      $k = array_search($r->name, $_tripal_core_prepared_statements);
+      unset($_tripal_core_prepared_statements[$k]);
+      chado_query('DEALLOCATE PREPARE %s', $r->name);
     }
     }
   }
   }
   else {
   else {
-    $prepared_statements = array();
+    $_tripal_core_prepared_statements = array();
     chado_query('DEALLOCATE PREPARE ALL');
     chado_query('DEALLOCATE PREPARE ALL');
   }
   }
 }
 }
@@ -3198,11 +3118,11 @@ function tripal_core_chado_clear_prepared ($statement_name_regex = NULL) {
  */
  */
 function tripal_db_persistent_chado() {
 function tripal_db_persistent_chado() {
   global $db_url;
   global $db_url;
-  global $persistent_chado;
+  global $_tripal_core_persistent_chado;
 
 
   // get connection if it already exists otherwise we need to set it
   // get connection if it already exists otherwise we need to set it
-  if ($persistent_chado) {
-    return $persistent_chado;
+  if ($_tripal_core_persistent_chado) {
+    return $_tripal_core_persistent_chado;
   }
   }
   else {
   else {
     if (is_array($db_url) && isset($db_url['chado'])) {
     if (is_array($db_url) && isset($db_url['chado'])) {
@@ -3211,7 +3131,7 @@ function tripal_db_persistent_chado() {
         watchdog('tripal_core', "Could not create persistant connection", array(), WATCHDOG_ERROR);
         watchdog('tripal_core', "Could not create persistant connection", array(), WATCHDOG_ERROR);
         return FALSE;
         return FALSE;
       }
       }
-      $persistent_chado = $connection;
+      $_tripal_core_persistent_chado = $connection;
     }
     }
     else {
     else {
       if (is_array($db_url)) {
       if (is_array($db_url)) {
@@ -3221,11 +3141,11 @@ function tripal_db_persistent_chado() {
         $connection = db_connect($db_url);
         $connection = db_connect($db_url);
       }
       }
       if (!$connection) {
       if (!$connection) {
-        $persistent_chado = NULL;
+        $_tripal_core_persistent_chado = NULL;
         watchdog('tripal_core', "Could not create persistant connection", array(), WATCHDOG_ERROR);
         watchdog('tripal_core', "Could not create persistant connection", array(), WATCHDOG_ERROR);
         return FALSE;
         return FALSE;
       }
       }
-      $persistent_chado = $connection;
+      $_tripal_core_persistent_chado = $connection;
     }
     }
     return $connection;
     return $connection;
   }
   }
@@ -3236,7 +3156,7 @@ function tripal_db_persistent_chado() {
  * Release a persistent chado connection
  * Release a persistent chado connection
  */
  */
 function tripal_db_release_persistent_chado() {
 function tripal_db_release_persistent_chado() {
-  $persistent_chado = NULL;
+  $_tripal_core_persistent_chado = NULL;
 }
 }
 
 
 /**
 /**
@@ -3390,8 +3310,14 @@ function tripal_core_chado_schema_exists() {
   if (!$exists) {
   if (!$exists) {
     // This is postgresql-specific code to check the existence of the chado schema
     // This is postgresql-specific code to check the existence of the chado schema
     // @coder-ignore: acting on pg_catalog schema rather then drupal schema therefore, table prefixing does not apply
     // @coder-ignore: acting on pg_catalog schema rather then drupal schema therefore, table prefixing does not apply
-    $sql = "SELECT nspname FROM pg_catalog.pg_namespace WHERE nspname = 'chado'";
-    if (db_fetch_object(db_query($sql))) {
+    $sql = "
+      SELECT nspname 
+      FROM pg_catalog.pg_namespace 
+      WHERE nspname = 'chado'
+    ";
+    $results = db_query($sql);
+    $name = $results->fetchObject();
+    if ($name) {
       variable_set('chado_schema_exists', TRUE);
       variable_set('chado_schema_exists', TRUE);
       return TRUE;
       return TRUE;
     }
     }
@@ -3415,11 +3341,16 @@ function tripal_core_chado_schema_exists() {
 function tripal_core_schema_exists($schema) {
 function tripal_core_schema_exists($schema) {
 
 
   // check that the chado schema now exists
   // check that the chado schema now exists
-  $sql = "SELECT nspname
-         FROM pg_namespace
-         WHERE has_schema_privilege(nspname, 'USAGE') and nspname = '%s'
-         ORDER BY nspname";
-  $name = db_fetch_object(db_query($sql, $schema));
+  $sql = "
+    SELECT nspname
+    FROM pg_namespace
+    WHERE 
+      has_schema_privilege(nspname, 'USAGE') AND 
+      nspname = :nspname
+    ORDER BY nspname
+  ";
+  $results = db_query($sql, array(':nspname' => $schema));
+  $name = $results->fetchObject();
   if (strcmp($name->nspname, $schema) != 0) {
   if (strcmp($name->nspname, $schema) != 0) {
     return FALSE;
     return FALSE;
   }
   }
@@ -3485,14 +3416,14 @@ function tripal_core_get_chado_tables($include_custom = NULL) {
  * @ingroup tripal_core_api
  * @ingroup tripal_core_api
  */
  */
 function tripal_core_set_chado_version() {
 function tripal_core_set_chado_version() {
-  global $db_url;
+  global $databases;
 
 
   // check that Chado is installed if not return 'uninstalled as the version'
   // check that Chado is installed if not return 'uninstalled as the version'
   $chado_exists = tripal_core_chado_schema_exists();
   $chado_exists = tripal_core_chado_schema_exists();
-  if (!$chado_exists) {
+  if (!$chado_exists) {  	
     // if it's not in the drupal database check to see if it's specified in the $db_url
     // if it's not in the drupal database check to see if it's specified in the $db_url
-    // in the settings.php
-    if (!is_array($db_url) or !array_key_exists('chado', $db_url)) {
+    // in the settings.php    
+    if (!array_key_exists('chado', $databases)) {    	
       // if it's not in the drupal database or specified in the $db_url then
       // if it's not in the drupal database or specified in the $db_url then
       // return uninstalled as the version
       // return uninstalled as the version
       return 'not installed';
       return 'not installed';
@@ -3511,14 +3442,17 @@ function tripal_core_set_chado_version() {
   // we can't use the Tripal API to query this table
   // we can't use the Tripal API to query this table
   // because the Tripal API depends on this function to
   // because the Tripal API depends on this function to
   // tell it the version. So, we need a typical SQL statement
   // tell it the version. So, we need a typical SQL statement
-  $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 "
-  ."WHERE CV.name = 'chado_properties' and CVT.name = 'version'";
+  $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 
+    WHERE CV.name = 'chado_properties' and CVT.name = 'version'
+  ";
   $previous_db = tripal_db_set_active('chado');
   $previous_db = tripal_db_set_active('chado');
-  $v = db_fetch_object(db_query($sql));
+  $resultes = db_query($sql);
   tripal_db_set_active($previous_db);
   tripal_db_set_active($previous_db);
+  $v = $results->fetchObject();
 
 
   // if we don't have a version in the chadoprop table then it must be
   // if we don't have a version in the chadoprop table then it must be
   // v1.11 or older
   // v1.11 or older

+ 5 - 5
tripal_core/api/tripal_core_custom_tables.api.inc

@@ -47,7 +47,7 @@ function tripal_core_edit_custom_table($table_id, $table_name, $schema, $skip_cr
   }
   }
 
 
   // if skip creation is not set, then drop the table from chado if it exists
   // if skip creation is not set, then drop the table from chado if it exists
-  if(!$skip_creation){
+  if (!$skip_creation) {
     if (db_table_exists($custom_table->table_name)) {
     if (db_table_exists($custom_table->table_name)) {
       chado_query("DROP TABLE %s", $custom_table->table_name);
       chado_query("DROP TABLE %s", $custom_table->table_name);
       drupal_set_message(t("Custom Table '%name' dropped", array('%name' => $custom_table->table_name)));
       drupal_set_message(t("Custom Table '%name' dropped", array('%name' => $custom_table->table_name)));
@@ -58,7 +58,7 @@ function tripal_core_edit_custom_table($table_id, $table_name, $schema, $skip_cr
   if (drupal_write_record('tripal_custom_tables', $record, 'table_id')) {
   if (drupal_write_record('tripal_custom_tables', $record, 'table_id')) {
 
 
     // drop the table from chado if it exists
     // drop the table from chado if it exists
-    if(!$skip_creation){
+    if (!$skip_creation) {
       if (db_table_exists($custom_table->table_name)) {
       if (db_table_exists($custom_table->table_name)) {
         chado_query("DROP TABLE %s", $custom_table->table_name);
         chado_query("DROP TABLE %s", $custom_table->table_name);
         drupal_set_message(t("Custom Table '%name' dropped", array('%name' => $custom_table->table_name)));
         drupal_set_message(t("Custom Table '%name' dropped", array('%name' => $custom_table->table_name)));
@@ -159,7 +159,7 @@ function tripal_core_create_custom_table(&$ret, $table, $schema, $skip_creation
   }
   }
   
   
   // now add any foreign key constraints
   // now add any foreign key constraints
-  if(!$skip_creation and array_key_exists('foreign keys', $schema)){
+  if (!$skip_creation and array_key_exists('foreign keys', $schema)) {
     $fkeys = $schema['foreign keys'];
     $fkeys = $schema['foreign keys'];
     foreach ($fkeys as $fktable => $fkdetails) {
     foreach ($fkeys as $fktable => $fkdetails) {
       $relations = $fkdetails['columns'];
       $relations = $fkdetails['columns'];
@@ -167,7 +167,7 @@ function tripal_core_create_custom_table(&$ret, $table, $schema, $skip_creation
         $sql = "ALTER TABLE $table ADD CONSTRAINT " . 
         $sql = "ALTER TABLE $table ADD CONSTRAINT " . 
           $table . "_" . $left . "_fkey FOREIGN KEY ($left) REFERENCES  $fktable ($right) " .
           $table . "_" . $left . "_fkey FOREIGN KEY ($left) REFERENCES  $fktable ($right) " .
           "ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED";
           "ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED";
-        if(!chado_query($sql)){
+        if (!chado_query($sql)) {
           watchdog('tripal_core', "Error, could not add foreign key contraint to custom table.",
           watchdog('tripal_core', "Error, could not add foreign key contraint to custom table.",
             array('!table_name' => $table), WATCHDOG_ERROR);
             array('!table_name' => $table), WATCHDOG_ERROR);
           drupal_set_message(t("Could not add foreign key contraint to table %table_name. 
           drupal_set_message(t("Could not add foreign key contraint to table %table_name. 
@@ -193,7 +193,7 @@ function tripal_core_create_custom_table(&$ret, $table, $schema, $skip_creation
  * @ingroup tripal_custom_tables_api
  * @ingroup tripal_custom_tables_api
  */
  */
 function tripal_custom_tables_get_table_id($table_name) {
 function tripal_custom_tables_get_table_id($table_name) {
-  $sql = "SELECT * FROM {tripal_custom_tables} ".
+  $sql = "SELECT * FROM {tripal_custom_tables} " .
          "WHERE table_name = '%s'";
          "WHERE table_name = '%s'";
   if (db_table_exists('tripal_custom_tables')) {
   if (db_table_exists('tripal_custom_tables')) {
     $custom_table = db_fetch_object(db_query($sql, $table_name));
     $custom_table = db_fetch_object(db_query($sql, $table_name));

+ 16 - 4
tripal_core/api/tripal_core_files.api.inc

@@ -16,6 +16,18 @@
  *
  *
  */
  */
  
  
+/**
+ * This function is a substitute for Drupal 6's file_directory_path()
+ * function which no longer exists in Drupal 7.  However, the function
+ * call is useful because it's more intitutive. So this wrapper was created
+ * to mimic the behavior of the old function.  
+ * 
+ * @return
+ *   the public directory where tripal files are housed: sites/default/files/tripal
+ */
+function tripal_file_directory_path() {
+  return variable_get('file_public_path', conf_path() . '/files/tripal');
+}
 /**
 /**
  * This function is typically used in the '.install' file for a Tripal module
  * This function is typically used in the '.install' file for a Tripal module
  * Each module should call this function during installation to create
  * Each module should call this function during installation to create
@@ -34,10 +46,10 @@
 function tripal_create_moddir($module_name) {
 function tripal_create_moddir($module_name) {
 
 
   // make the data directory for this module
   // make the data directory for this module
-  $data_dir = file_directory_path() . "/tripal/$module_name";
+  $data_dir = tripal_file_directory_path() . "$module_name";
   if (!file_check_directory($data_dir, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
   if (!file_check_directory($data_dir, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
-    $message = "Cannot create directory $data_dir. This module may not ".
-               "behave correctly without this directory.  Please  create ".
+    $message = "Cannot create directory $data_dir. This module may not " .
+               "behave correctly without this directory.  Please  create " .
                "the directory manually or fix the problem and reinstall.";
                "the directory manually or fix the problem and reinstall.";
     drupal_set_message(check_plain(t($message)), 'error');
     drupal_set_message(check_plain(t($message)), 'error');
     watchdog('tripal_core', $message, array(), WATCHDOG_ERROR);
     watchdog('tripal_core', $message, array(), WATCHDOG_ERROR);
@@ -58,6 +70,6 @@ function tripal_create_moddir($module_name) {
  * @ingroup tripal_files_api
  * @ingroup tripal_files_api
  */
  */
 function tripal_get_moddir($module_name) {
 function tripal_get_moddir($module_name) {
-  $data_dir = file_directory_path() . "/tripal/$module_name";
+  $data_dir = tripal_file_directory_path() . "$module_name";
   return $data_dir;
   return $data_dir;
 }
 }

+ 24 - 27
tripal_core/api/tripal_core_jobs.api.inc

@@ -70,7 +70,7 @@ function tripal_add_job($job_name, $modulename, $callback, $arguments, $uid, $pr
   $record->modulename = $modulename;
   $record->modulename = $modulename;
   $record->callback = $callback;
   $record->callback = $callback;
   $record->status = 'Waiting';
   $record->status = 'Waiting';
-  $record->submit_date = time();
+  $record->submit_date = REQUEST_TIME;
   $record->uid = $uid;
   $record->uid = $uid;
   $record->priority = $priority;  # the lower the number the higher the priority
   $record->priority = $priority;  # the lower the number the higher the priority
   if ($args) {
   if ($args) {
@@ -101,10 +101,10 @@ function tripal_jobs_check_running() {
   // and see if it is still running. If it is not
   // and see if it is still running. If it is not
   // running but does not have an end_time then
   // running but does not have an end_time then
   // set the end time and set the status to 'Error'
   // set the end time and set the status to 'Error'
-  $sql =  "SELECT * FROM {tripal_jobs} TJ ".
+  $sql =  "SELECT * FROM {tripal_jobs} TJ " .
           "WHERE TJ.end_time IS NULL and NOT TJ.start_time IS NULL ";
           "WHERE TJ.end_time IS NULL and NOT TJ.start_time IS NULL ";
   $jobs = db_query($sql);
   $jobs = db_query($sql);
-  while ($job = db_fetch_object($jobs)) {
+  foreach ($jobs as $job) {
     $status = `ps -p $job->pid -o pid=`;
     $status = `ps -p $job->pid -o pid=`;
     if ($job->pid && $status) {
     if ($job->pid && $status) {
       // the job is still running so let it go
       // the job is still running so let it go
@@ -115,7 +115,7 @@ function tripal_jobs_check_running() {
       // the job is not running so terminate it
       // the job is not running so terminate it
       $record = new stdClass();
       $record = new stdClass();
       $record->job_id = $job->job_id;
       $record->job_id = $job->job_id;
-      $record->end_time = time();
+      $record->end_time = REQUEST_TIME;
       $record->status = 'Error';
       $record->status = 'Error';
       $record->error_msg = 'Job has terminated unexpectedly.';
       $record->error_msg = 'Job has terminated unexpectedly.';
       drupal_write_record('tripal_jobs', $record, 'job_id');
       drupal_write_record('tripal_jobs', $record, 'job_id');
@@ -186,16 +186,11 @@ function tripal_jobs_get_end_time($job) {
 function tripal_jobs_rerun($job_id, $goto_jobs_page = TRUE) {
 function tripal_jobs_rerun($job_id, $goto_jobs_page = TRUE) {
   global $user;
   global $user;
 
 
-  $sql = "SELECT * FROM {tripal_jobs} WHERE job_id = %d";
-  $job = db_fetch_object(db_query($sql, $job_id));
+  $sql = "SELECT * FROM {tripal_jobs} WHERE job_id = :job_id";
+  $results = db_query($sql, array(':job_id' => $job_id));
+  $job = $results->fetchObject();
   $args = explode("::", $job->arguments);
   $args = explode("::", $job->arguments);
-  $job_id = tripal_add_job(
-    $job->job_name,
-    $job->modulename,
-    $job->callback,
-    $args,
-    $user->uid,
-    $job->priority);
+  $job_id = tripal_add_job($job->job_name, $job->modulename, $job->callback, $args, $user->uid, $job->priority);
 
 
   if ($goto_jobs_page) {
   if ($goto_jobs_page) {
     drupal_goto("admin/tripal/tripal_jobs");
     drupal_goto("admin/tripal/tripal_jobs");
@@ -212,14 +207,15 @@ function tripal_jobs_rerun($job_id, $goto_jobs_page = TRUE) {
  * @ingroup tripal_jobs_api
  * @ingroup tripal_jobs_api
  */
  */
 function tripal_jobs_cancel($job_id, $redirect = TRUE) {
 function tripal_jobs_cancel($job_id, $redirect = TRUE) {
-  $sql = "SELECT * FROM {tripal_jobs} WHERE job_id = %d";
-  $job = db_fetch_object(db_query($sql, $job_id));
+  $sql = "SELECT * FROM {tripal_jobs} WHERE job_id = :job_id";
+  $results = db_query($sql, array(':job_id' => $job_id));
+  $job = $results->fetchOjbect();
 
 
   // set the end time for this job
   // set the end time for this job
   if ($job->start_time == 0) {
   if ($job->start_time == 0) {
     $record = new stdClass();
     $record = new stdClass();
     $record->job_id = $job->job_id;
     $record->job_id = $job->job_id;
-    $record->end_time = time();
+    $record->end_time = REQUEST_TIME;
     $record->status = 'Cancelled';
     $record->status = 'Cancelled';
     $record->progress = '0';
     $record->progress = '0';
     drupal_write_record('tripal_jobs', $record, 'job_id');
     drupal_write_record('tripal_jobs', $record, 'job_id');
@@ -261,22 +257,22 @@ function tripal_jobs_launch($do_parallel = 0, $job_id = NULL) {
   // get all jobs that have not started and order them such that
   // get all jobs that have not started and order them such that
   // they are processed in a FIFO manner.
   // they are processed in a FIFO manner.
   if ($job_id) {
   if ($job_id) {
-    $sql =  "SELECT * FROM {tripal_jobs} TJ ".
-            "WHERE TJ.start_time IS NULL and TJ.end_time IS NULL and TJ.job_id = %d ".
+    $sql =  "SELECT * FROM {tripal_jobs} TJ " .
+            "WHERE TJ.start_time IS NULL and TJ.end_time IS NULL and TJ.job_id = %d " .
             "ORDER BY priority ASC,job_id ASC";
             "ORDER BY priority ASC,job_id ASC";
-    $job_res = db_query($sql,$job_id);
+    $job_res = db_query($sql, $job_id);
   }
   }
   else {
   else {
-    $sql =  "SELECT * FROM {tripal_jobs} TJ ".
-            "WHERE TJ.start_time IS NULL and TJ.end_time IS NULL ".
+    $sql =  "SELECT * FROM {tripal_jobs} TJ " .
+            "WHERE TJ.start_time IS NULL and TJ.end_time IS NULL " .
             "ORDER BY priority ASC,job_id ASC";
             "ORDER BY priority ASC,job_id ASC";
     $job_res = db_query($sql);
     $job_res = db_query($sql);
   }
   }
-  while ($job = db_fetch_object($job_res)) {
+  foreach ($job_res as $job) {
     // set the start time for this job
     // set the start time for this job
     $record = new stdClass();
     $record = new stdClass();
     $record->job_id = $job->job_id;
     $record->job_id = $job->job_id;
-    $record->start_time = time();
+    $record->start_time = REQUEST_TIME;
     $record->status = 'Running';
     $record->status = 'Running';
     $record->pid = getmypid();
     $record->pid = getmypid();
     drupal_write_record('tripal_jobs', $record, 'job_id');
     drupal_write_record('tripal_jobs', $record, 'job_id');
@@ -290,7 +286,7 @@ function tripal_jobs_launch($do_parallel = 0, $job_id = NULL) {
     print "Calling: $callback(" . implode(", ", $args) . ")\n";
     print "Calling: $callback(" . implode(", ", $args) . ")\n";
     call_user_func_array($callback, $args);
     call_user_func_array($callback, $args);
     // set the end time for this job
     // set the end time for this job
-    $record->end_time = time();
+    $record->end_time = REQUEST_TIME;
     $record->status = 'Completed';
     $record->status = 'Completed';
     $record->progress = '100';
     $record->progress = '100';
     drupal_write_record('tripal_jobs', $record, 'job_id');
     drupal_write_record('tripal_jobs', $record, 'job_id');
@@ -337,9 +333,10 @@ function tripal_job_set_progress($job_id, $percentage) {
  * @ingroup tripal_jobs_api
  * @ingroup tripal_jobs_api
  */
  */
 function tripal_get_module_active_jobs($modulename) {
 function tripal_get_module_active_jobs($modulename) {
-  $sql =  "SELECT * FROM {tripal_jobs} TJ ".
-           "WHERE TJ.end_time IS NULL and TJ.modulename = '%s' ";
-  return db_fetch_object(db_query($sql, $modulename));
+  $sql =  "SELECT * FROM {tripal_jobs} TJ " .
+           "WHERE TJ.end_time IS NULL and TJ.modulename = :modulename ";
+  $results = db_query($sql, array(':modulename' => $modulename));
+  return $results->fetchObject();
 }
 }
 
 
 /**
 /**

+ 4 - 4
tripal_core/api/tripal_core_mviews.api.inc

@@ -180,7 +180,7 @@ function tripal_edit_mview($mview_id, $name, $modulename, $mv_table, $mv_specs,
   $create_table = 1;  
   $create_table = 1;  
   $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = %d";
   $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = %d";
   $mview = db_fetch_object(db_query($sql, $mview_id));  
   $mview = db_fetch_object(db_query($sql, $mview_id));  
-  if($mview->mv_schema == $mv_schema and $mview->mv_table == $mv_table and 
+  if ($mview->mv_schema == $mv_schema and $mview->mv_table == $mv_table and 
      $mview->mv_specs == $mv_specs and $mview->indexed == $indexed and 
      $mview->mv_specs == $mv_specs and $mview->indexed == $indexed and 
      $mview->special_index == $special_index) {
      $mview->special_index == $special_index) {
     // nothing has changed so simpy update the SQL and other fields 
     // nothing has changed so simpy update the SQL and other fields 
@@ -270,7 +270,7 @@ function tripal_edit_mview($mview_id, $name, $modulename, $mv_table, $mv_specs,
  * @ingroup tripal_mviews_api
  * @ingroup tripal_mviews_api
  */
  */
 function tripal_mviews_get_mview_id($view_name) {
 function tripal_mviews_get_mview_id($view_name) {
-  $sql = "SELECT * FROM {tripal_mviews} ".
+  $sql = "SELECT * FROM {tripal_mviews} " .
         "WHERE name = '%s'";
         "WHERE name = '%s'";
   if (db_table_exists('tripal_mviews')) {
   if (db_table_exists('tripal_mviews')) {
     $mview = db_fetch_object(db_query($sql, $view_name));
     $mview = db_fetch_object(db_query($sql, $view_name));
@@ -313,7 +313,7 @@ function tripal_mviews_action($op, $mview_id, $redirect = FALSE) {
   }
   }
   if ($op == 'delete') {
   if ($op == 'delete') {
     // remove the mview from the tripal_mviews table
     // remove the mview from the tripal_mviews table
-    $sql = "DELETE FROM {tripal_mviews} ".
+    $sql = "DELETE FROM {tripal_mviews} " .
            "WHERE mview_id = $mview_id";
            "WHERE mview_id = $mview_id";
     db_query($sql);
     db_query($sql);
     // drop the table from chado if it exists
     // drop the table from chado if it exists
@@ -362,7 +362,7 @@ function tripal_update_mview($mview_id) {
       tripal_db_set_active($previous_db);  // now use drupal database
       tripal_db_set_active($previous_db);  // now use drupal database
       $record = new stdClass();
       $record = new stdClass();
       $record->mview_id = $mview_id;
       $record->mview_id = $mview_id;
-      $record->last_update = time();
+      $record->last_update = REQUEST_TIME;
       $record->status = "Populated with " . number_format($count->cnt) . " rows";
       $record->status = "Populated with " . number_format($count->cnt) . " rows";
       drupal_write_record('tripal_mviews', $record, 'mview_id');
       drupal_write_record('tripal_mviews', $record, 'mview_id');
       return TRUE;
       return TRUE;

+ 21 - 23
tripal_core/includes/chado_install.inc

@@ -17,12 +17,12 @@ function tripal_core_chado_load_form() {
 
 
   // get the effective version.  Pass true as second argument
   // get the effective version.  Pass true as second argument
   // to warn the user if the current version is not compatible
   // to warn the user if the current version is not compatible
-  $version = tripal_core_get_chado_version(FALSE, TRUE);
+  $version = tripal_core_get_chado_version(FALSE, TRUE);  
 
 
   $form['current_version'] = array(
   $form['current_version'] = array(
     '#type' => 'item',
     '#type' => 'item',
-    '#title' => t("Current installed version of Chado"),
-    '#value' => $real_version,
+    '#title' => t("Current installed version of Chado:"),
+    '#description' => $real_version,
   );
   );
 
 
   $form['action_to_do'] = array(
   $form['action_to_do'] = array(
@@ -40,13 +40,13 @@ function tripal_core_chado_load_form() {
   $form['description'] = array(
   $form['description'] = array(
     '#type' => 'item',
     '#type' => 'item',
     '#value' => t("<font color=\"red\">WARNING:</font> A new install of Chado v1.2 or v1.11 "
     '#value' => t("<font color=\"red\">WARNING:</font> A new install of Chado v1.2 or v1.11 "
-      ."will install Chado within the Drupal database in a \"chado\" schema. If the \"chado\" schema already exists it will "
-      ."be overwritten and all data will be lost.  You may choose to update an existing Chado v1.11 if it was installed with a previous "
-      ."version of Tripal (e.g. v0.3b or v0.3.1). The update will not erase any data. "
-      ."If you are using chado in a database external to the "
-      ."Drupal database with a 'chado' entry in the 'settings.php' \$db_url argument "
-      ."then Chado will be installed but will not be used .  The external "
-      ."database specified in the settings.php file takes precedence."),
+      . "will install Chado within the Drupal database in a \"chado\" schema. If the \"chado\" schema already exists it will "
+      . "be overwritten and all data will be lost.  You may choose to update an existing Chado v1.11 if it was installed with a previous "
+      . "version of Tripal (e.g. v0.3b or v0.3.1). The update will not erase any data. "
+      . "If you are using chado in a database external to the "
+      . "Drupal database with a 'chado' entry in the 'settings.php' \$db_url argument "
+      . "then Chado will be installed but will not be used .  The external "
+      . "database specified in the settings.php file takes precedence."),
   );
   );
 
 
   $form['button'] = array(
   $form['button'] = array(
@@ -65,11 +65,9 @@ function tripal_core_chado_load_form() {
  */
  */
 function tripal_core_chado_load_form_submit($form, &$form_state) {
 function tripal_core_chado_load_form_submit($form, &$form_state) {
   global $user;
   global $user;
-  $action_to_do   = trim($form_state['values']['action_to_do']);
-
+  $action_to_do = trim($form_state['values']['action_to_do']);
   $args = array($action_to_do);
   $args = array($action_to_do);
-  tripal_add_job($action_to_do, 'tripal_core',
-    'tripal_core_install_chado', $args, $user->uid);
+  tripal_add_job($action_to_do, 'tripal_core', 'tripal_core_install_chado', $args, $user->uid);
 }
 }
 
 
 /**
 /**
@@ -86,7 +84,7 @@ function tripal_core_install_chado($action) {
           "WHERE CV.name = 'chado_properties' AND CVT.name = 'version'), " .
           "WHERE CV.name = 'chado_properties' AND CVT.name = 'version'), " .
           "'%s') ";
           "'%s') ";
 
 
-  if($action == 'Install Chado v1.2'){
+  if ($action == 'Install Chado v1.2') {
     $schema_file = drupal_get_path('module', 'tripal_core') . '/chado_schema/default_schema-1.2.sql';
     $schema_file = drupal_get_path('module', 'tripal_core') . '/chado_schema/default_schema-1.2.sql';
     $init_file = drupal_get_path('module', 'tripal_core') . '/chado_schema/initialize-1.2.sql';
     $init_file = drupal_get_path('module', 'tripal_core') . '/chado_schema/initialize-1.2.sql';
     if (tripal_core_reset_chado_schema()) {
     if (tripal_core_reset_chado_schema()) {
@@ -106,14 +104,14 @@ function tripal_core_install_chado($action) {
         print "Installation (Step 2 of 2) Problems!  Please check output above for errors.\n";
         print "Installation (Step 2 of 2) Problems!  Please check output above for errors.\n";
         exit;
         exit;
       }
       }
-      chado_query($vsql,'1.2'); # set the version
+      chado_query($vsql, '1.2'); # set the version
     }
     }
     else {
     else {
       print "ERROR: cannot install chado.  Please check database permissions\n";
       print "ERROR: cannot install chado.  Please check database permissions\n";
       exit;
       exit;
     }
     }
   }
   }
-  elseif($action == 'Upgrade Chado v1.11 to v1.2') {
+  elseif ($action == 'Upgrade Chado v1.11 to v1.2') {
     $schema_file = drupal_get_path('module', 'tripal_core') . '/chado_schema/default_schema-1.11-1.2-diff.sql';
     $schema_file = drupal_get_path('module', 'tripal_core') . '/chado_schema/default_schema-1.11-1.2-diff.sql';
     $init_file = drupal_get_path('module', 'tripal_core') . '/chado_schema/upgrade-1.11-1.2.sql';
     $init_file = drupal_get_path('module', 'tripal_core') . '/chado_schema/upgrade-1.11-1.2.sql';
     $success = tripal_core_install_sql($schema_file);
     $success = tripal_core_install_sql($schema_file);
@@ -132,9 +130,9 @@ function tripal_core_install_chado($action) {
       print "Upgrade (Step 2 of 2) problems!  Please check output above for errors.\n";
       print "Upgrade (Step 2 of 2) problems!  Please check output above for errors.\n";
       exit;
       exit;
     }
     }
-    chado_query($vsql,'1.2'); # set the version
+    chado_query($vsql, '1.2'); # set the version
   }
   }
-  elseif($action == 'Install Chado v1.11'){
+  elseif ($action == 'Install Chado v1.11') {
     $schema_file = drupal_get_path('module', 'tripal_core') . '/chado_schema/default_schema-1.11.sql';
     $schema_file = drupal_get_path('module', 'tripal_core') . '/chado_schema/default_schema-1.11.sql';
     $init_file = drupal_get_path('module', 'tripal_core') . '/chado_schema/initialize-1.11.sql';
     $init_file = drupal_get_path('module', 'tripal_core') . '/chado_schema/initialize-1.11.sql';
     if (tripal_core_reset_chado_schema()) {
     if (tripal_core_reset_chado_schema()) {
@@ -169,7 +167,6 @@ function tripal_core_install_chado($action) {
  * @ingroup tripal_core
  * @ingroup tripal_core
  */
  */
 function tripal_core_reset_chado_schema() {
 function tripal_core_reset_chado_schema() {
-  global $active_db;
 
 
   // drop current chado and chado-related schema
   // drop current chado and chado-related schema
   if (tripal_core_schema_exists('chado')) {
   if (tripal_core_schema_exists('chado')) {
@@ -196,7 +193,8 @@ function tripal_core_reset_chado_schema() {
     // before creating the plpgsql language let's check to make sure
     // before creating the plpgsql language let's check to make sure
     // it doesn't already exists
     // it doesn't already exists
     $sql = "SELECT COUNT(*) FROM pg_language WHERE lanname = 'plpgsql'";
     $sql = "SELECT COUNT(*) FROM pg_language WHERE lanname = 'plpgsql'";
-    $count = db_fetch_object(db_query($sql));
+    $results = db_query($sql);
+    $count = $results->fetchObject();
     if (!$count or $count->count == 0) {
     if (!$count or $count->count == 0) {
       db_query("create language plpgsql");
       db_query("create language plpgsql");
     }
     }
@@ -218,7 +216,7 @@ function tripal_core_install_sql($sql_file) {
   
   
   $chado_local = tripal_core_schema_exists('chado');
   $chado_local = tripal_core_schema_exists('chado');
 
 
-  if($chado_local) {
+  if ($chado_local) {
     db_query("set search_path to chado");
     db_query("set search_path to chado");
   }
   }
   print "Loading $sql_file...\n";
   print "Loading $sql_file...\n";
@@ -358,7 +356,7 @@ function tripal_core_install_sql($sql_file) {
       //print "Adding $type: line $i\n";
       //print "Adding $type: line $i\n";
       // rewrite the set search_path to make 'public' be 'chado', but only if the
       // rewrite the set search_path to make 'public' be 'chado', but only if the
       // chado schema exists
       // chado schema exists
-      if (strcmp($type, 'set')==0 and $chado_local){
+      if (strcmp($type, 'set') == 0 and $chado_local) {
         $query = preg_replace("/public/m", "chado", $query);
         $query = preg_replace("/public/m", "chado", $query);
       }
       }
       
       

+ 16 - 16
tripal_core/includes/custom_tables.inc

@@ -31,15 +31,15 @@ function tripal_custom_table_view($table_id) {
   $output .= "<br />";
   $output .= "<br />";
   $output .= "<table class=\"border-table\">";
   $output .= "<table class=\"border-table\">";
   if ($custom_table->table_name) {
   if ($custom_table->table_name) {
-    $output .= "  <tr>".
-    "    <th>Table Name</th>".
-    "    <td>$custom_table->table_name</td>".
+    $output .= "  <tr>" .
+    "    <th>Table Name</th>" .
+    "    <td>$custom_table->table_name</td>" .
     "  </tr>";
     "  </tr>";
   }
   }
   if ($custom_table->schema) {
   if ($custom_table->schema) {
-    $output .= "  <tr>".
-    "    <th>Table Field Definitions</th>".
-    "    <td><pre>" . var_export(unserialize($custom_table->schema),1) . "</pre></td>".
+    $output .= "  <tr>" .
+    "    <th>Table Field Definitions</th>" .
+    "    <td><pre>" . var_export(unserialize($custom_table->schema), 1) . "</pre></td>" .
     "  </tr>";
     "  </tr>";
   }
   }
 
 
@@ -47,9 +47,9 @@ function tripal_custom_table_view($table_id) {
   // clean URLs are or are not used
   // clean URLs are or are not used
   $delete_url = url("admin/tripal/custom_tables/action/delete/$custom_table->table_id");
   $delete_url = url("admin/tripal/custom_tables/action/delete/$custom_table->table_id");
   $edit_url = url("admin/tripal/custom_tables/edit/$custom_table->table_id");
   $edit_url = url("admin/tripal/custom_tables/edit/$custom_table->table_id");
-  $output .= "<tr><th>Actions</th>".
-            "<td>".
-            "     <a href='$edit_url'>Edit</a>, ".
+  $output .= "<tr><th>Actions</th>" .
+            "<td>" .
+            "     <a href='$edit_url'>Edit</a>, " .
             "     <a href='$delete_url'>Delete</a></td></tr>";
             "     <a href='$delete_url'>Delete</a></td></tr>";
   $output .= "</table>";
   $output .= "</table>";
 
 
@@ -69,8 +69,8 @@ function tripal_custom_tables_list() {
   while ($custom_table = db_fetch_object($custom_tables)) {
   while ($custom_table = db_fetch_object($custom_tables)) {
  
  
     $rows[] = array(
     $rows[] = array(
-      l(t('View'), "admin/tripal/custom_tables/view/$custom_table->table_id") ." | ".
-      l(t('Edit'), "admin/tripal/custom_tables/edit/$custom_table->table_id") ." | ".
+      l(t('View'), "admin/tripal/custom_tables/view/$custom_table->table_id") . " | " .
+      l(t('Edit'), "admin/tripal/custom_tables/edit/$custom_table->table_id") . " | " .
       $custom_table->table_name,
       $custom_table->table_name,
       $custom_table->comment,
       $custom_table->comment,
       l(t('Delete'), "admin/tripal/custom_tables/action/delete/$custom_table->table_id"),
       l(t('Delete'), "admin/tripal/custom_tables/action/delete/$custom_table->table_id"),
@@ -125,8 +125,8 @@ function tripal_custom_tables_form(&$form_state = NULL, $table_id = NULL) {
       $default_table = $custom_table->table_name;
       $default_table = $custom_table->table_name;
     }
     }
     if (!$default_schema) {
     if (!$default_schema) {
-      $default_schema = var_export(unserialize($custom_table->schema),1);
-      $default_schema = preg_replace('/=>\s+\n\s+array/','=> array', $default_schema);
+      $default_schema = var_export(unserialize($custom_table->schema), 1);
+      $default_schema = preg_replace('/=>\s+\n\s+array/', '=> array', $default_schema);
     }
     }
   }
   }
 
 
@@ -311,7 +311,7 @@ function tripal_custom_tables_form_submit($form, &$form_state) {
   eval("\$schema_arr = $schema;");
   eval("\$schema_arr = $schema;");
   
   
 
 
-  if (strcmp($action, 'Edit') == 0) {  	
+  if (strcmp($action, 'Edit') == 0) {    
     tripal_core_edit_custom_table($table_id, $schema_arr['table'], $schema_arr, $skip_creation);
     tripal_core_edit_custom_table($table_id, $schema_arr['table'], $schema_arr, $skip_creation);
   }
   }
   elseif (strcmp($action, 'Add') == 0) {
   elseif (strcmp($action, 'Add') == 0) {
@@ -350,14 +350,14 @@ function tripal_custom_tables_action($op, $table_id, $redirect = FALSE) {
   if ($op == 'delete') {
   if ($op == 'delete') {
   
   
     // remove the entry from the tripal_custom tables table
     // remove the entry from the tripal_custom tables table
-    $sql = "DELETE FROM {tripal_custom_tables} ".
+    $sql = "DELETE FROM {tripal_custom_tables} " .
            "WHERE table_id = $table_id";
            "WHERE table_id = $table_id";
     db_query($sql);
     db_query($sql);
     
     
     // drop the table from chado if it exists
     // drop the table from chado if it exists
     if (db_table_exists($custom_table->table_name)) {
     if (db_table_exists($custom_table->table_name)) {
       $success = chado_query("DROP TABLE %s", $custom_table->table_name);
       $success = chado_query("DROP TABLE %s", $custom_table->table_name);
-      if($success){
+      if ($success) {
         drupal_set_message(t("Custom Table '%name' dropped", array('%name' => $custom_table->table_name)));
         drupal_set_message(t("Custom Table '%name' dropped", array('%name' => $custom_table->table_name)));
       }
       }
     }
     }

+ 86 - 48
tripal_core/includes/jobs.inc

@@ -13,29 +13,34 @@
 function tripal_jobs_report_form($form, &$form_state = NULL) {
 function tripal_jobs_report_form($form, &$form_state = NULL) {
   $form = array();
   $form = array();
 
 
-  // set the default values
-  $default_status = $form_state['values']['job_status'];
-  $default_job_name = $form_state['values']['job_name'];
-
-  if (!$default_status) {
-    $default_status = $_SESSION['tripal_job_filter']['job_status'];    
+  // set the default values 
+  $default_status = '';
+  $default_job_name = '';
+  if (array_key_exists('values', $form_state)) {
+    $default_status = array_key_exists('job_status', $form_state['values']) ? $form_state['values']['job_status'] : '';
+    $default_job_name = array_key_exists('job_name', $form_state['values']) ? $form_state['values']['job_name'] : '';
+  }
+  
+  if (!$default_status and array_key_exists('tripal_job_filter', $_SESSION)) {
+    $job_status = array_key_exists('job_status', $_SESSION['tripal_job_filter']) ? $_SESSION['tripal_job_filter']['job_status'] : '';
   }
   }
-  if (!$default_job_name) {
-    $default_job_name = $_SESSION['tripal_job_filter']['job_name'];
+  if (!$default_job_name and array_key_exists('tripal_job_filter', $_SESSION)) {
+    $default_job_name = array_key_exists('job_name', $_SESSION['tripal_job_filter']) ? $_SESSION['tripal_job_filter']['job_name'] : '';
   }
   }
+  
 
 
   $form['job_status'] = array(
   $form['job_status'] = array(
     '#type'          => 'select',
     '#type'          => 'select',
     '#title'         => t('Filter by Job Status'),
     '#title'         => t('Filter by Job Status'),
     '#default_value' => $default_status,
     '#default_value' => $default_status,
     '#options' => array(
     '#options' => array(
-	    0           => 'All Jobs',
-	    'Running'   => 'Running',
-	    'Waiting'   => 'Waiting',
-	    'Completed' => 'Completed',
-	    'Cancelled' => 'Cancelled',
-	    'Error'     => 'Error',
-	  ),
+    0           => 'All Jobs',
+    'Running'   => 'Running',
+    'Waiting'   => 'Waiting',
+    'Completed' => 'Completed',
+    'Cancelled' => 'Cancelled',
+    'Error'     => 'Error',
+  ),
   );
   );
   $form['job_name'] = array(
   $form['job_name'] = array(
     '#type'          => 'textfield',
     '#type'          => 'textfield',
@@ -75,10 +80,15 @@ function tripal_jobs_report() {
   // run the following function which will
   // run the following function which will
   // change the status of jobs that have errored out
   // change the status of jobs that have errored out
   tripal_jobs_check_running();
   tripal_jobs_check_running();
+  
+  $job_status = '';
+  $job_name = '';
+  if (array_key_exists('tripal_job_filter', $_SESSION)) {
+    $job_status = array_key_exists('job_status', $_SESSION['tripal_job_filter']) ? $_SESSION['tripal_job_filter']['job_status'] : '';
+    $job_name = array_key_exists('job_name', $_SESSION['tripal_job_filter']) ? $_SESSION['tripal_job_filter']['job_name'] : '';
+  }
 
 
-	$job_status = $_SESSION['tripal_job_filter']['job_status'];
-	$job_name = $_SESSION['tripal_job_filter']['job_name'];
-
+  // build the SQL for getting the jobs
   $sql = "
   $sql = "
     SELECT
     SELECT
       TJ.job_id,TJ.uid,TJ.job_name,TJ.modulename,TJ.progress,
       TJ.job_id,TJ.uid,TJ.job_name,TJ.modulename,TJ.progress,
@@ -87,32 +97,38 @@ function tripal_jobs_report() {
     FROM {tripal_jobs} TJ
     FROM {tripal_jobs} TJ
       INNER JOIN {users} U on TJ.uid = U.uid 
       INNER JOIN {users} U on TJ.uid = U.uid 
     WHERE 1=1 
     WHERE 1=1 
-  ";
+  ";  
   $args = array();
   $args = array();
   if ($job_status) {
   if ($job_status) {
-    $sql .= "AND TJ.status = '%s' ";
-    $args[] = $job_status;
+    $sql .= "AND TJ.status = :status ";
+    $args[':status'] = $job_status;
   }
   }
   if ($job_name) {
   if ($job_name) {
-    $sql .= "AND TJ.job_name like '%%%s%%'";
-    $args[] = $job_name;
+    $sql .= "AND TJ.job_name like :job_name";
+    $args[':job_name'] = "%$job_name%";
   }
   }
-  $sql .= "ORDER BY job_id DESC";
-
-  $jobs = pager_query($sql, 25, 0, "SELECT count(*) FROM ($sql) as t1", $args);
-  $header = array(
-    'Job ID',
-    'User',
-    'Job Name',
-    array('data' => 'Dates', 'style'=> "white-space: nowrap"),
-    'Priority',
-    'Progress',
-    'Status',
-    'Action');
-  $rows = array();
-
-  // iterate through the jobs
-  while ($job = db_fetch_object($jobs)) {
+  $sql .= " ORDER BY job_id DESC ";
+  
+  // create the SQL that returns the total number of records
+  $count_sql = "SELECT count(*) as total FROM ($sql) as t1";  
+  $result = db_query($count_sql, $args);
+  $total_jobs = $result->fetchObject();
+
+  // initialize the pager
+  $num_per_page = 25;
+  $page = pager_find_page();
+  pager_default_initialize($total_jobs->total, $num_per_page);
+  
+  // get results
+  $pager_sql = "$sql LIMIT  :number OFFSET :offset";
+  $args[':number'] = $num_per_page;
+  $args[':offset'] = $num_per_page * $page;
+  $jobs = db_query($pager_sql, $args);
+  
+  
+  // iterate through the jobs and build the table rows
+  $rows = array();  
+  foreach ($jobs as $job) {
     $submit = tripal_jobs_get_submit_date($job);
     $submit = tripal_jobs_get_submit_date($job);
     $start = tripal_jobs_get_start_time($job);
     $start = tripal_jobs_get_start_time($job);
     $end = tripal_jobs_get_end_time($job);
     $end = tripal_jobs_get_end_time($job);
@@ -133,14 +149,35 @@ function tripal_jobs_report() {
       "$cancel_link $rerun_link $view_link",
       "$cancel_link $rerun_link $view_link",
     );
     );
   }
   }
-
+  
+  // the header for the jobs table  
+  $header = array(
+    'Job ID',
+    'User',
+    'Job Name',
+    array('data' => 'Dates', 'style' => "white-space: nowrap"),
+    'Priority',
+    'Progress',
+    'Status',
+    'Action'
+  );
+  $table = array(
+    'header' => $header, 
+    'rows' => $rows, 
+    'attributes' => array(), 
+    'sticky' => FALSE,
+    'caption' => '',
+    'colgroups' => array(), 
+    'empty' => 'No jobs have been submitted', 
+  );
+    
   // create the report page
   // create the report page
-  $output .= "Waiting jobs are executed first by priority level (the lower the ".
-             "number the higher the priority) and second by the order they ".
-             "were entered";
-  $output .= drupal_get_form('tripal_jobs_report_form');
-  $output .= theme('table', $header, $rows);
-  $output .= theme_pager();
+  $output = "Waiting jobs are executed first by priority level (the lower the " .
+             "number the higher the priority) and second by the order they " .
+             "were entered";  
+  $output .= drupal_render(drupal_get_form('tripal_jobs_report_form'));   
+  $output .= theme_table($table);
+  $output .= theme('pager');
   return $output;
   return $output;
 }
 }
 /**
 /**
@@ -176,8 +213,9 @@ function tripal_core_preprocess_tripal_core_job_view(&$variables) {
             TJ.callback,TJ.error_msg,TJ.pid
             TJ.callback,TJ.error_msg,TJ.pid
      FROM {tripal_jobs} TJ
      FROM {tripal_jobs} TJ
        INNER JOIN users U on TJ.uid = U.uid
        INNER JOIN users U on TJ.uid = U.uid
-     WHERE TJ.job_id = %d";
-  $job = db_fetch_object(db_query($sql, $job_id));
+     WHERE TJ.job_id = :job_id";
+  $results = db_query($sql, array(':job_id' => $job_id));
+  $job = $results->fetchObject();
 
 
   // we do not know what the arguments are for and we want to provide a
   // we do not know what the arguments are for and we want to provide a
   // meaningful description to the end-user. So we use a callback function
   // meaningful description to the end-user. So we use a callback function

+ 8 - 8
tripal_core/includes/mviews.inc

@@ -92,8 +92,8 @@ function tripal_mviews_report() {
     }
     }
 
 
     $rows[] = array(
     $rows[] = array(
-      l(t('View'), "admin/tripal/mviews/report/$mview->mview_id") ." | ".
-      l(t('Edit'), "admin/tripal/mviews/edit/$mview->mview_id") ." | ".
+      l(t('View'), "admin/tripal/mviews/report/$mview->mview_id") . " | " .
+      l(t('Edit'), "admin/tripal/mviews/edit/$mview->mview_id") . " | " .
       l(t('Populate'), "admin/tripal/mviews/action/update/$mview->mview_id"),
       l(t('Populate'), "admin/tripal/mviews/action/update/$mview->mview_id"),
       $mview->name,
       $mview->name,
       $update,
       $update,
@@ -114,7 +114,7 @@ function tripal_mviews_report() {
     data storage platform, but unfortunately some queries may be slow.  MViews alleviate slowness by aggregating data
     data storage platform, but unfortunately some queries may be slow.  MViews alleviate slowness by aggregating data
     into tables that are more easy to query.  Use MViews to create tables for custom search pages or custom Tripal
     into tables that are more easy to query.  Use MViews to create tables for custom search pages or custom Tripal
     module development.") . '</p>';
     module development.") . '</p>';
-  $page .= '<p><b>' . t("MViews behaves in the following way:") . '</b><ul>'.
+  $page .= '<p><b>' . t("MViews behaves in the following way:") . '</b><ul>' .
            '<li>' . t("The SQL statement defined for an MVIEW will be used to populate the table") . '</li>' .
            '<li>' . t("The SQL statement defined for an MVIEW will be used to populate the table") . '</li>' .
            '<li>' . t("Altering the table structure of an MView will cause the MView table to be dropped and recreated.  All records in the MView will be lost.") . '</li>' .
            '<li>' . t("Altering the table structure of an MView will cause the MView table to be dropped and recreated.  All records in the MView will be lost.") . '</li>' .
            '<li>' . t("Altering the query of an existing view will not change the MView table. No records will be lost. ") . '</li>' .
            '<li>' . t("Altering the query of an existing view will not change the MView table. No records will be lost. ") . '</li>' .
@@ -251,8 +251,8 @@ function tripal_mviews_form(&$form_state = NULL, $mview_id = NULL) {
   $form['schema'] = array(
   $form['schema'] = array(
     '#type' => 'fieldset',
     '#type' => 'fieldset',
     '#title' => 'Drupal Schema API Setup',
     '#title' => 'Drupal Schema API Setup',
-    '#description' => t('Use the Drupal Schema API array to describe a table. The benefit is that it '.
-                       'can be fully integrated with Tripal Views.  Tripal supports an extended '.
+    '#description' => t('Use the Drupal Schema API array to describe a table. The benefit is that it ' .
+                       'can be fully integrated with Tripal Views.  Tripal supports an extended ' .
                        'array format to allow for descriptoin of foreign key relationships.'),
                        'array format to allow for descriptoin of foreign key relationships.'),
     '#collapsible' => 1,
     '#collapsible' => 1,
     '#collapsed' => $schema_collapsed ,
     '#collapsed' => $schema_collapsed ,
@@ -271,8 +271,8 @@ function tripal_mviews_form(&$form_state = NULL, $mview_id = NULL) {
   $form['traditional'] = array(
   $form['traditional'] = array(
     '#type' => 'fieldset',
     '#type' => 'fieldset',
     '#title' => 'Legacy MViews Setup',
     '#title' => 'Legacy MViews Setup',
-    '#description' => t('Traditionally MViews were created by specifying PostgreSQL style '.
-                       'column types.  This method can be used but is deprecated in favor of the '.
+    '#description' => t('Traditionally MViews were created by specifying PostgreSQL style ' .
+                       'column types.  This method can be used but is deprecated in favor of the ' .
                        'newer Drupal schema API method provided above. In rare cases where the Drupal Schema API ' .
                        'newer Drupal schema API method provided above. In rare cases where the Drupal Schema API ' .
                        'does not support a desired data type the Legacy Mviews should be used'),
                        'does not support a desired data type the Legacy Mviews should be used'),
     '#collapsible' => 1,
     '#collapsible' => 1,
@@ -359,7 +359,7 @@ function tripal_mviews_form_validate($form, &$form_state) {
 
 
   if ($schema and ($mv_table or $mv_specs or $indexed or $special_index)) {
   if ($schema and ($mv_table or $mv_specs or $indexed or $special_index)) {
     form_set_error($form_state['values']['schema'],
     form_set_error($form_state['values']['schema'],
-      t('You can create an MView using the Drupal Schema API method or the '.
+      t('You can create an MView using the Drupal Schema API method or the ' .
         'traditional method but not both.'));
         'traditional method but not both.'));
   }
   }
   if (!$schema) {
   if (!$schema) {

+ 20 - 15
tripal_core/tripal_core.drush.inc

@@ -71,7 +71,7 @@ function tripal_core_drush_command() {
     'examples' => array(
     'examples' => array(
       'Standard example' => 'drush tripal-jobs-current',
       'Standard example' => 'drush tripal-jobs-current',
     ),
     ),
-    'aliases' => array('trpjob-cur','tripal-current-job'),
+    'aliases' => array('trpjob-cur', 'tripal-current-job'),
   );
   );
   $items['tripal-jobs-launch'] = array(
   $items['tripal-jobs-launch'] = array(
     // used by drush help
     // used by drush help
@@ -88,7 +88,7 @@ function tripal_core_drush_command() {
       'parallel' => dt('Normally jobs are executed one at a time. But if you are certain no conflicts will occur with other currently running jobs you may set this argument to a value of 1 to make the job run in parallel with other running jobs.'),
       'parallel' => dt('Normally jobs are executed one at a time. But if you are certain no conflicts will occur with other currently running jobs you may set this argument to a value of 1 to make the job run in parallel with other running jobs.'),
       'job_id' => dt('Provide a job_id to run a specific job. Only jobs that have not been run already can be used'),
       'job_id' => dt('Provide a job_id to run a specific job. Only jobs that have not been run already can be used'),
     ),
     ),
-    'aliases' => array('trpjob-run','tripal-launch-jobs')
+    'aliases' => array('trpjob-run', 'tripal-launch-jobs')
   );
   );
   $items['tripal-jobs-rerun'] = array(
   $items['tripal-jobs-rerun'] = array(
     // used by drush help
     // used by drush help
@@ -105,7 +105,7 @@ function tripal_core_drush_command() {
     'options' => array(
     'options' => array(
       'parallel' => dt('Normally jobs are executed one at a time. But if you are certain no conflicts will occur with other currently running jobs you may set this argument to a value of 1 to make the job run in parallel with other running jobs.'),
       'parallel' => dt('Normally jobs are executed one at a time. But if you are certain no conflicts will occur with other currently running jobs you may set this argument to a value of 1 to make the job run in parallel with other running jobs.'),
     ),
     ),
-    'aliases' => array('trpjob-rerun','tripal-rerun-job')
+    'aliases' => array('trpjob-rerun', 'tripal-rerun-job')
   );
   );
 
 
   // Chado-specific
   // Chado-specific
@@ -178,8 +178,13 @@ function drush_tripal_core_tripal_jobs_launch($username) {
   $job_id = drush_get_option('job_id');
   $job_id = drush_get_option('job_id');
 
 
   if ($username) {
   if ($username) {
+    $sql = "SELECT uid FROM {user} WHERE name = '%s'";
+    $u = db_fetch_object(db_query($sql, $username));
+    if (!$u) {
+      drush_print('ERROR: Please provide a valid username for running this job.');  
+    }
     global $user;
     global $user;
-    $user = user_load(array('name' => $username));
+    $user = user_load($u->uid);
   }
   }
   else {
   else {
     drush_print('ERROR: Please provide a username for running this job.');
     drush_print('ERROR: Please provide a username for running this job.');
@@ -218,18 +223,18 @@ function drush_tripal_core_tripal_jobs_rerun($username, $job_id) {
  * NOTE: The following code is executed when 'drush trpjob-curr' or 'drush tripal-current-job' is called
  * NOTE: The following code is executed when 'drush trpjob-curr' or 'drush tripal-current-job' is called
  */
  */
 function drush_tripal_core_tripal_jobs_current() {
 function drush_tripal_core_tripal_jobs_current() {
-  $sql =  "SELECT * FROM {tripal_jobs} TJ ".
+  $sql =  "SELECT * FROM {tripal_jobs} TJ " .
             "WHERE TJ.end_time IS NULL and NOT TJ.start_time IS NULL ";
             "WHERE TJ.end_time IS NULL and NOT TJ.start_time IS NULL ";
   $jobs = db_query($sql);
   $jobs = db_query($sql);
   while ($job = db_fetch_object($jobs)) {
   while ($job = db_fetch_object($jobs)) {
     $job_pid = $job->pid;
     $job_pid = $job->pid;
     $output = "Name: " . $job->job_name . "\n"
     $output = "Name: " . $job->job_name . "\n"
-             ."Submitted: " . date(DATE_RFC822, $job->submit_date) . "\n"
-             ."Started: " . date(DATE_RFC822, $job->start_time) . "\n"
-             ."Module: " . $job->modulename . "\n"
-             ."Callback: " . $job->callback . "\n"
-             ."Process ID: " . $job->pid . "\n"
-             ."Progress: " . $job->progress . "%\n";
+             . "Submitted: " . date(DATE_RFC822, $job->submit_date) . "\n"
+             . "Started: " . date(DATE_RFC822, $job->start_time) . "\n"
+             . "Module: " . $job->modulename . "\n"
+             . "Callback: " . $job->callback . "\n"
+             . "Process ID: " . $job->pid . "\n"
+             . "Progress: " . $job->progress . "%\n";
     drush_print($output);
     drush_print($output);
   }
   }
   if (!$job_pid) {
   if (!$job_pid) {
@@ -284,7 +289,7 @@ function drush_tripal_core_tripal_update_mview() {
  */
  */
 function drush_tripal_core_tripal_chado_version() {
 function drush_tripal_core_tripal_chado_version() {
   $version = tripal_core_get_chado_version();
   $version = tripal_core_get_chado_version();
-  drush_print('Current Chado Version: '.$version);
+  drush_print('Current Chado Version: ' . $version);
 }
 }
 
 
 /**
 /**
@@ -300,10 +305,10 @@ function drush_tripal_core_tripal_chadotable_desc($table_name) {
   $desc = tripal_core_get_chado_table_schema($table_name);
   $desc = tripal_core_get_chado_table_schema($table_name);
 
 
   if (!empty($section)) {
   if (!empty($section)) {
-    drush_print("$section = ".print_r($desc[$section],TRUE));
+    drush_print("$section = " . print_r($desc[$section], TRUE));
   }
   }
   else {
   else {
-    drush_print(print_r($desc,TRUE));
+    drush_print(print_r($desc, TRUE));
   }
   }
 }
 }
 
 
@@ -314,7 +319,7 @@ function drush_tripal_core_tripal_chadotable_desc($table_name) {
  *  The name of a module with nodes associated with it. For example, feature
  *  The name of a module with nodes associated with it. For example, feature
  */
  */
 function drush_tripal_core_tripal_node_sync($module) {
 function drush_tripal_core_tripal_node_sync($module) {
-  switch($module) {
+  switch ($module) {
     case 'analysis':
     case 'analysis':
       call_user_func('tripal_analysis_sync_analyses');
       call_user_func('tripal_analysis_sync_analyses');
       break;
       break;

+ 2 - 3
tripal_core/tripal_core.info

@@ -1,7 +1,6 @@
 name = Tripal Core
 name = Tripal Core
 description = The core module for the Tripal package that integrates Drupal and GMOD chado. This module provides common support for all Tripal modules.
 description = The core module for the Tripal package that integrates Drupal and GMOD chado. This module provides common support for all Tripal modules.
-core = 6.x
+core = 7.x
 project = tripal_core
 project = tripal_core
 package = Tripal
 package = Tripal
-version = 6.x-1.1
-
+version = 7.x-2.0

+ 5 - 40
tripal_core/tripal_core.install

@@ -13,50 +13,16 @@
 function tripal_core_install() {
 function tripal_core_install() {
 
 
   // make the data directory for this module
   // make the data directory for this module
-  $data_dir = file_directory_path() . "/tripal";
+  $data_dir = tripal_file_directory_path();
   if (!file_check_directory($data_dir, FILE_CREATE_DIRECTORY)) {
   if (!file_check_directory($data_dir, FILE_CREATE_DIRECTORY)) {
-    $message = "Cannot create directory $data_dir. This module may not ".
-               "behave correctly without this directory.  Please  create ".
+    $message = "Cannot create directory $data_dir. This module may not " .
+               "behave correctly without this directory.  Please  create " .
                "the directory manually or fix the problem and reinstall.";
                "the directory manually or fix the problem and reinstall.";
     drupal_set_message(check_plain($message), 'error');
     drupal_set_message(check_plain($message), 'error');
     watchdog('tripal_core', $message, array(), WATCHDOG_ERROR);
     watchdog('tripal_core', $message, array(), WATCHDOG_ERROR);
   }
   }
 
 
-  // create the tables that manage materialized views and jobs
-  drupal_install_schema('tripal_core');
-
-}
-
-/**
- *  Update for Drupal 6.x, Tripal 1.0
- *  This update
- *   - adjusts the materialized view by adding status, comment and mv_schema columns
- *   - changes the specs of mv_table, mv_specs and indexed
- *   - creates the tripal_custom_tables table
- *
- * @ingroup tripal_core
- */
-function tripal_core_update_6000() {
-  // add additional columns to the tripal_mviews table
-  db_add_field($ret, 'tripal_mviews', 'status', array('type' => 'text', 'size' => 'normal', 'not NULL' => FALSE));
-  db_add_field($ret, 'tripal_mviews', 'comment', array('type' => 'text', 'size' => 'normal', 'not NULL' => FALSE));
-  db_add_field($ret, 'tripal_mviews', 'mv_schema', array('type' => 'text', 'size' => 'normal', 'not NULL' => FALSE));
-  db_change_field($ret, 'tripal_mviews', 'mv_table', 'mv_table', array('type' => 'varchar', 'length' => 128, 'not NULL' => FALSE));
-  db_change_field($ret, 'tripal_mviews', 'mv_specs', 'mv_specs', array('type' => 'text', 'size' => 'normal', 'not NULL' => FALSE));
-  db_change_field($ret, 'tripal_mviews', 'indexed', 'indexed', array('type' => 'text', 'size' => 'normal', 'not NULL' => FALSE));
-
-  // create the custom tables table
-  $ret = array();
-  $schema = tripal_core_custom_tables_schema();
-  db_create_table($ret, 'tripal_custom_tables', $schema['tripal_custom_tables']);
-
-  $ret = array(
-    '#finished' => 1,
-  );
-
-  return $ret;
 }
 }
-
 /**
 /**
  * Implementation of hook_schema().
  * Implementation of hook_schema().
  *
  *
@@ -75,8 +41,8 @@ function tripal_core_schema() {
   // Chado database.
   // Chado database.
   if (db_table_exists('tripal_custom_tables')) {
   if (db_table_exists('tripal_custom_tables')) {
     $sql = 'SELECT * FROM {tripal_custom_tables}';
     $sql = 'SELECT * FROM {tripal_custom_tables}';
-    $q = db_query($sql);
-    while ($custom = db_fetch_object($q)) {
+    $results = db_query($sql);    
+    foreach ($results as $custom) {
       $schema[$custom->table_name] = unserialize($custom->schema);
       $schema[$custom->table_name] = unserialize($custom->schema);
     }
     }
   }
   }
@@ -90,7 +56,6 @@ function tripal_core_schema() {
  * @ingroup tripal_core
  * @ingroup tripal_core
  */
  */
 function tripal_core_uninstall() {
 function tripal_core_uninstall() {
-  drupal_uninstall_schema('tripal_core');
 }
 }
 
 
 /**
 /**

+ 25 - 25
tripal_core/tripal_core.module

@@ -59,13 +59,7 @@ require_once "includes/form_elements.inc";
  */
  */
 function tripal_core_init() {
 function tripal_core_init() {
   global $base_url;     
   global $base_url;     
-  
-  // we need to declare here the persistent_chado global variable
-  global $persistent_chado;
-  global $prepared_statements;
-  $persistent_chado = NULL;
-  $prepared_statements = array();
-  
+    
   // add javascript files 
   // add javascript files 
   drupal_add_js(drupal_get_path('theme', 'tripal') . '/js/tripal.ahah.js');
   drupal_add_js(drupal_get_path('theme', 'tripal') . '/js/tripal.ahah.js');
   
   
@@ -76,15 +70,24 @@ function tripal_core_init() {
     // make sure the current version of chado is set
     // make sure the current version of chado is set
     tripal_core_set_chado_version();  
     tripal_core_set_chado_version();  
   
   
-    if (!db_fetch_object(chado_query("SELECT * FROM {cv} WHERE name = 'tripal'"))) {
+    // if the Tripal cv is missing then add
+    $results = chado_query("SELECT * FROM {cv} WHERE name = 'tripal'");
+    $tripal_cv = $results->fetchObject();    
+    if (!$tripal_cv) {
       $results = chado_query(
       $results = chado_query(
-        "INSERT INTO {cv} (name,definition) ".
-        "VALUES ('tripal', 'Terms used by Tripal for modules to manage data such as that stored in property tables like featureprop, analysisprop, etc')");
+        "INSERT INTO {cv} (name,definition) " .
+        "VALUES ('tripal', 'Terms used by Tripal for modules to manage data such as that stored in property tables like featureprop, analysisprop, etc')"
+      );
     }
     }
-    if (!db_fetch_object(chado_query("SELECT * FROM {db} WHERE name = 'tripal'"))) {
+    
+    // if the Tripal db is missing then add it
+    $results = chado_query("SELECT * FROM {db} WHERE name = 'tripal'");
+    $tripal_db = $results->fetchObject();
+    if (!$tripal_db) {
       $results = chado_query(
       $results = chado_query(
-        "INSERT INTO {db} (name,description) ".
-        "VALUES ('tripal', 'Used as a database placeholder for tripal defined objects such as tripal cvterms')");
+        "INSERT INTO {db} (name,description) " .
+        "VALUES ('tripal', 'Used as a database placeholder for tripal defined objects such as tripal cvterms')"
+      );
     }
     }
   }
   }
 
 
@@ -101,16 +104,8 @@ function tripal_core_init() {
   // make sure the date time settings are the way Tripal will insert them
   // make sure the date time settings are the way Tripal will insert them
   // otherwise PostgreSQL version that may have a different datestyle setting
   // otherwise PostgreSQL version that may have a different datestyle setting
   // will fail when inserting or updating a date column in a table.
   // will fail when inserting or updating a date column in a table.
-  db_query("SET DATESTYLE TO '%s'", 'MDY'); 
-
-  // in the event that an errant Tripal or extension function fails to
-  // set the postgres search_path back to noraml we do it here on 
-  // init of the core
-  tripal_db_set_default_search_path(); 
-  
-  // create a persistent connection
-  $connection = tripal_db_persistent_chado();
-  
+  db_query("SET DATESTYLE TO :style", array(':style' => 'MDY')); 
+   
   // If we want AHAH elements on the node forms (e.g. chado_pub form) then we need to include
   // If we want AHAH elements on the node forms (e.g. chado_pub form) then we need to include
   // the node.pages file. Otherwise this error message is given:
   // the node.pages file. Otherwise this error message is given:
   //
   //
@@ -287,8 +282,13 @@ function tripal_core_menu() {
  *
  *
  * @ingroup tripal_core
  * @ingroup tripal_core
  */
  */
-function tripal_core_perm() {
-  return array('install chado');
+function tripal_core_permission() {
+  return array(
+    'install chado' => array(
+      'title' => t('Install Chado'),
+      'description' => t('Allow the user to install or upgrade a Chado database in the existing Drupal database.')
+    ),
+  );
 }
 }
 
 
 /**
 /**

+ 1 - 1
tripal_organism/tripal_organism.install

@@ -20,7 +20,7 @@ function tripal_organism_install() {
   // The user that performs the syncing will receive ownership of the
   // The user that performs the syncing will receive ownership of the
   // images directory which may not allow for write access by the web server
   // images directory which may not allow for write access by the web server
   // user.  So, we create it here
   // user.  So, we create it here
-  $dest = file_directory_path() . "/tripal/tripal_organism/images";
+  $dest = tripal_file_directory_path() . "/tripal_organism/images";
   file_check_directory($dest, FILE_CREATE_DIRECTORY);
   file_check_directory($dest, FILE_CREATE_DIRECTORY);
 
 
   // create the tables that correlate drupal nodes with chado
   // create the tables that correlate drupal nodes with chado

+ 1 - 1
tripal_organism/tripal_organism.module

@@ -402,7 +402,7 @@ function chado_organism_add_image($node) {
   // directory for display with the organism
   // directory for display with the organism
   if (isset($_FILES['files']) && $_FILES['files']['name']['organism_image'] &&
   if (isset($_FILES['files']) && $_FILES['files']['name']['organism_image'] &&
     is_uploaded_file($_FILES['files']['tmp_name']['organism_image'])) {
     is_uploaded_file($_FILES['files']['tmp_name']['organism_image'])) {
-      $dest = file_directory_path() . "/tripal/tripal_organism/images";
+      $dest = tripal_file_directory_path() . "/tripal_organism/images";
       $validators = array(
       $validators = array(
         'file_validate_is_image' => array(),
         'file_validate_is_image' => array(),
       );
       );