Bläddra i källkod

Loading of Ontologies is converted to 7.x

spficklin 11 år sedan
förälder
incheckning
a221e0f38b

+ 1 - 1
tripal_core/api/tripal_core_chado.api.inc

@@ -2697,7 +2697,7 @@ function tripal_get_chado_custom_schema($table) {
  * @return
  * @return
  *   TRUE/FALSE depending upon whether it exists
  *   TRUE/FALSE depending upon whether it exists
  */
  */
-function tripal_chado_table_exists($table) {
+function chado_table_exists($table) {
 	global $databases;
 	global $databases;
 	
 	
 	$default_db = $databases['default']['default']['database'];
 	$default_db = $databases['default']['default']['database'];

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

@@ -113,7 +113,7 @@ function tripal_core_create_custom_table($table, $schema, $skip_creation = 1) {
   $centry = $results->fetchObject();
   $centry = $results->fetchObject();
   
   
   // check to see if the table already exists in the chado schema
   // check to see if the table already exists in the chado schema
-  $exists = tripal_chado_table_exists($table); 
+  $exists = chado_table_exists($table); 
   
   
   // if the table does not exist then create it
   // if the table does not exist then create it
   if (!$exists) { 
   if (!$exists) { 

+ 6 - 8
tripal_core/api/tripal_core_mviews.api.inc

@@ -78,12 +78,10 @@ function tripal_add_mview($name, $modulename, $mv_table, $mv_specs, $indexed,
   if (drupal_write_record('tripal_mviews', $record)) {
   if (drupal_write_record('tripal_mviews', $record)) {
 
 
     // drop the table from chado if it exists
     // drop the table from chado if it exists
-    $previous_db = tripal_db_set_active('chado');  // use chado database
-    if (db_table_exists($mv_table)) {
-      $sql = "DROP TABLE $mv_table";
-      db_query($sql);
+    if (chado_table_exists($mv_table)) {
+      $sql = "DROP TABLE {$mv_table}";
+      chado_query($sql);
     }
     }
-    tripal_db_set_active($previous_db);  // now use drupal database
 
 
     // now construct the indexes
     // now construct the indexes
     $index = '';
     $index = '';
@@ -297,8 +295,7 @@ function tripal_mviews_get_mview_id($view_name) {
  */
  */
 function tripal_mviews_action($op, $mview_id, $redirect = FALSE) {
 function tripal_mviews_action($op, $mview_id, $redirect = FALSE) {
   global $user;
   global $user;
-
-  $args = array("$mview_id");
+  
   if (!$mview_id) {
   if (!$mview_id) {
     return '';
     return '';
   }
   }
@@ -310,6 +307,7 @@ function tripal_mviews_action($op, $mview_id, $redirect = FALSE) {
 
 
   // add a job or perform the action based on the given operation
   // add a job or perform the action based on the given operation
   if ($op == 'update') {
   if ($op == 'update') {
+  	$args = array("$mview_id");
     tripal_add_job("Populate materialized view '$mview->name'", 'tripal_core',
     tripal_add_job("Populate materialized view '$mview->name'", 'tripal_core',
        'tripal_update_mview', $args, $user->uid);
        'tripal_update_mview', $args, $user->uid);
   }
   }
@@ -321,7 +319,7 @@ function tripal_mviews_action($op, $mview_id, $redirect = FALSE) {
     // drop the table from chado if it exists
     // drop the table from chado if it exists
     $previous_db = tripal_db_set_active('chado');  // use chado database
     $previous_db = tripal_db_set_active('chado');  // use chado database
     if (db_table_exists($mview->mv_table)) {
     if (db_table_exists($mview->mv_table)) {
-      $sql = "DROP TABLE $mview->mv_table";
+      $sql = "DROP TABLE " . $mview->mv_table;
       db_query($sql);
       db_query($sql);
     }
     }
     tripal_db_set_active($previous_db);  // now use drupal database
     tripal_db_set_active($previous_db);  // now use drupal database

+ 41 - 37
tripal_cv/api/tripal_cv.api.inc

@@ -151,10 +151,9 @@ function tripal_cv_get_cv_by_id($cv_id) {
  */
  */
 function tripal_cv_get_cv_id($cv_name) {
 function tripal_cv_get_cv_id($cv_name) {
 
 
-  $sql = "
-    SELECT cv_id FROM {cv} WHERE name = '%s'
-  ";
-  $cv = db_fetch_object(chado_query($sql, $cv_name));
+  $sql = "SELECT cv_id FROM {cv} WHERE name = :name";
+  $result = chado_query($sql, array(':name' => $cv_name));
+  $cv = $result->fetchObject();
 
 
   return $cv->cv_id;
   return $cv->cv_id;
 }
 }
@@ -368,13 +367,24 @@ function tripal_cv_update_cvtermpath($cvid, $job_id = NULL) {
   // TODO: need better error checking in this function
   // TODO: need better error checking in this function
 
 
   // first get the controlled vocabulary name:
   // first get the controlled vocabulary name:
-  $cv = db_fetch_object(chado_query("SELECT * FROM {cv} WHERE cv_id = %d", $cvid));
+  $sql = "SELECT * FROM {cv} WHERE cv_id = :cv_id";
+  $result = chado_query($sql, array(':cv_id' => $cvid));
+  $cv = $result->fetchObject();
+  
   print "\nUpdating cvtermpath for $cv->name...\n";
   print "\nUpdating cvtermpath for $cv->name...\n";
-
-  // now fill the cvtermpath table
-  // @coder-ignore: using a function rather then tablename therefore table prefixing doesn't apply
-  $sql = "SELECT * FROM fill_cvtermpath('%s')";
-  $success = chado_query($sql, $cv->name); 
+  
+  $previous = tripal_db_set_active('chado');
+  try {
+    $sql = "SELECT * FROM fill_cvtermpath(':name')";
+    db_query($sql, array(':name' => $cv->name));
+    tripal_db_set_active($previous); 
+  }
+  catch (Exception $e) {
+    tripal_db_set_active($previous);	
+    $error = $e->getMessage();
+    watchdog('tripal_cv', "Could not fill cvtermpath table: @error", array('@error' => $error), WATCHDOG_ERROR);
+    return FALSE;
+  }
 
 
   return TRUE;
   return TRUE;
 }
 }
@@ -548,22 +558,15 @@ function tripal_cv_add_cvterm($term, $defaultcv = '_global', $is_relationship =
   // here for easy reference below.  Because CV terms can change their names
   // here for easy reference below.  Because CV terms can change their names
   // but accessions don't change, the following SQL finds cvterms based on
   // but accessions don't change, the following SQL finds cvterms based on
   // their accession rather than the name
   // their accession rather than the name
-  if (!tripal_core_is_sql_prepared('sel_cvterm_by_accession')) {
-    $pcvtermsql = "
-      PREPARE sel_cvterm_by_accession(text, text) AS
-      SELECT CVT.name, CVT.cvterm_id, CV.cv_id, CV.name as cvname, 
-        DB.name as dbname, DB.db_id, DBX.accession 
-      FROM {cvterm} CVT
-        INNER JOIN {dbxref} DBX on CVT.dbxref_id = DBX.dbxref_id
-        INNER JOIN {db} DB on DBX.db_id = DB.db_id
-        INNER JOIN {cv} CV on CV.cv_id = CVT.cv_id
-      WHERE DBX.accession = $1 and DB.name = $2";
-    if (!tripal_core_chado_prepare('sel_cvterm_by_accession', $pcvtermsql, array('text', 'text'))) {
-      watchdog('tripal_cv', "Cannot prepare statement 'sel_cvterm_by_accession'", NULL, WATCHDOG_WARNING);
-      return 0; 
-    }
-  } 
-  $cvtermsql = "EXECUTE sel_cvterm_by_accession('%s','%s')";  
+  $cvtermsql = "     
+    SELECT CVT.name, CVT.cvterm_id, CV.cv_id, CV.name as cvname, 
+      DB.name as dbname, DB.db_id, DBX.accession 
+    FROM {cvterm} CVT
+      INNER JOIN {dbxref} DBX on CVT.dbxref_id = DBX.dbxref_id
+      INNER JOIN {db} DB on DBX.db_id = DB.db_id
+      INNER JOIN {cv} CV on CV.cv_id = CVT.cv_id
+    WHERE DBX.accession = :accession and DB.name = :name
+  ";    
   
   
   // add the database. The function will just return the DB object if the
   // add the database. The function will just return the DB object if the
   // database already exists.
   // database already exists.
@@ -676,7 +679,8 @@ function tripal_cv_add_cvterm($term, $defaultcv = '_global', $is_relationship =
         }
         }
       }        
       }        
       // get the original cvterm with the same name and return that.
       // get the original cvterm with the same name and return that.
-      $cvterm = db_fetch_object(chado_query($cvtermsql, $dbxref->accession, $dbname));
+      $result = chado_query($cvtermsql, array(':accession' => $dbxref->accession, ':name' => $dbname));
+      $cvterm = $result->fetchObject();
       return $cvterm;
       return $cvterm;
     }
     }
     
     
@@ -685,10 +689,8 @@ function tripal_cv_add_cvterm($term, $defaultcv = '_global', $is_relationship =
   }
   }
   
   
   // get the CVterm record
   // get the CVterm record
-  $cvterm = db_fetch_object(chado_query($cvtermsql, $accession, $dbname)); 
-  //print "$pcvtermsql\n$cvtermsql\n$accession, $dbname\n";
-  //print "CVTERM:\n";
-  //print_r($cvterm);
+  $result = chado_query($cvtermsql, array(':accession' => $accession, ':name' => $dbname));
+  $cvterm = $result->fetchObject();
   if (!$cvterm) {
   if (!$cvterm) {
 
 
     // check to see if the dbxref exists if not, add it
     // check to see if the dbxref exists if not, add it
@@ -731,8 +733,9 @@ function tripal_cv_add_cvterm($term, $defaultcv = '_global', $is_relationship =
     else {
     else {
       watchdog('tripal_cv', "The dbxref already exists for another cvterm record: $name (cv: " . $cvname . " db: $dbname)", NULL, WATCHDOG_WARNING);
       watchdog('tripal_cv', "The dbxref already exists for another cvterm record: $name (cv: " . $cvname . " db: $dbname)", NULL, WATCHDOG_WARNING);
       return 0;
       return 0;
-    }    
-    $cvterm = db_fetch_object(chado_query($cvtermsql, $accession, $dbname));
+    } 
+    $result = chado_query($cvtermsql, array(':accession' => $accession, ':name' => $dbname));
+    $cvterm = $result->fetchObject();   
   }
   }
   // upate the cvterm
   // upate the cvterm
   elseif ($update) { 
   elseif ($update) { 
@@ -749,7 +752,8 @@ function tripal_cv_add_cvterm($term, $defaultcv = '_global', $is_relationship =
       watchdog('tripal_cv', "Failed to update the term: $name", NULL, WATCHDOG_WARNING);
       watchdog('tripal_cv', "Failed to update the term: $name", NULL, WATCHDOG_WARNING);
       return 0;
       return 0;
     }
     }
-    $cvterm = db_fetch_object(chado_query($cvtermsql, $accession, $dbname));
+    $result = chado_query($cvtermsql, array(':accession' => $accession, ':name' => $dbname));
+    $cvterm = $result->fetchObject();
   } 
   } 
   else {
   else {
      // do nothing, we have the cvterm but we don't want to update
      // do nothing, we have the cvterm but we don't want to update
@@ -832,9 +836,9 @@ function tripal_cv_submit_obo_job($obo_id = NULL, $obo_name = NULL, $obo_url = N
   global $user;
   global $user;
 
 
   if ($obo_id) {
   if ($obo_id) {
-    $sql = "SELECT * FROM {tripal_cv_obo} WHERE obo_id = %d";
-    $obo = db_fetch_object(db_query($sql, $obo_id));
-    
+    $sql = "SELECT * FROM {tripal_cv_obo} WHERE obo_id = :obo_id";
+    $obo = db_query($sql, array(':obo_id' => $obo_id))->fetchObject();
+        
     $args = array($obo_id);
     $args = array($obo_id);
     return tripal_add_job("Load OBO $obo->name", 'tripal_cv',
     return tripal_add_job("Load OBO $obo->name", 'tripal_cv',
        "tripal_cv_load_obo_v1_2_id", $args, $user->uid);
        "tripal_cv_load_obo_v1_2_id", $args, $user->uid);

+ 14 - 41
tripal_cv/includes/obo_loader.inc

@@ -13,7 +13,7 @@
  *
  *
   * @ingroup tripal_obo_loader
   * @ingroup tripal_obo_loader
  */
  */
-function tripal_cv_obo_form(&$form_state = NULL) {
+function tripal_cv_obo_form($form, &$form_state) {
 
 
   // get a list of db from chado for user to choose
   // get a list of db from chado for user to choose
   $sql = "SELECT * FROM {tripal_cv_obo} ORDER BY name";
   $sql = "SELECT * FROM {tripal_cv_obo} ORDER BY name";
@@ -21,7 +21,7 @@ function tripal_cv_obo_form(&$form_state = NULL) {
 
 
   $obos = array();
   $obos = array();
   $obos[] = '';
   $obos[] = '';
-  while ($obo = db_fetch_object($results)) {
+  foreach ($results as $obo) {
 //    $obos[$obo->obo_id] = "$obo->name  | $obo->path";
 //    $obos[$obo->obo_id] = "$obo->name  | $obo->path";
     $obos[$obo->obo_id] = $obo->name;
     $obos[$obo->obo_id] = $obo->name;
   }
   }
@@ -41,21 +41,18 @@ function tripal_cv_obo_form(&$form_state = NULL) {
                    installation of the Tripal CV module or were added from a previous upload.  Select
                    installation of the Tripal CV module or were added from a previous upload.  Select
                    an OBO, then click the submit button to load the vocabulary into the database.  If the
                    an OBO, then click the submit button to load the vocabulary into the database.  If the
                    vocabularies already exist then the ontology will be updated.'),
                    vocabularies already exist then the ontology will be updated.'),
-    '#weight'        => -1
   );
   );
 
 
   $form['obo_existing']['obo_id'] = array(
   $form['obo_existing']['obo_id'] = array(
     '#title' => t('Ontology OBO File Reference'),
     '#title' => t('Ontology OBO File Reference'),
     '#type' => 'select',
     '#type' => 'select',
     '#options' => $obos,
     '#options' => $obos,
-    '#weight'        => 0
   );
   );
 
 
   $form['obo_new']['path_instructions']= array(
   $form['obo_new']['path_instructions']= array(
     '#value' => t('Provide the name and path for the OBO file.  If the vocabulary OBO file
     '#value' => t('Provide the name and path for the OBO file.  If the vocabulary OBO file
                    is stored local to the server provide a file name. If the vocabulry is stored remotely,
                    is stored local to the server provide a file name. If the vocabulry is stored remotely,
                    provide a URL.  Only provide a URL or a local file, not both.'),
                    provide a URL.  Only provide a URL or a local file, not both.'),
-    '#weight'        => 0
   );
   );
 
 
   $form['obo_new']['obo_name']= array(
   $form['obo_new']['obo_name']= array(
@@ -63,7 +60,6 @@ function tripal_cv_obo_form(&$form_state = NULL) {
     '#title'         => t('New Vocabulary Name'),
     '#title'         => t('New Vocabulary Name'),
     '#description'   => t('Please provide a name for this vocabulary.  After upload, this name will appear in the drop down
     '#description'   => t('Please provide a name for this vocabulary.  After upload, this name will appear in the drop down
                            list above for use again later.'),
                            list above for use again later.'),
-    '#weight'        => 1
   );
   );
 
 
   $form['obo_new']['obo_url']= array(
   $form['obo_new']['obo_url']= array(
@@ -71,8 +67,6 @@ function tripal_cv_obo_form(&$form_state = NULL) {
     '#title'         => t('Remote URL'),
     '#title'         => t('Remote URL'),
     '#description'   => t('Please enter a URL for the online OBO file.  The file will be downloaded and parsed.
     '#description'   => t('Please enter a URL for the online OBO file.  The file will be downloaded and parsed.
                            (e.g. http://www.obofoundry.org/ro/ro.obo'),
                            (e.g. http://www.obofoundry.org/ro/ro.obo'),
-    '#default_value' => $default_desc,
-    '#weight'        => 2
   );
   );
 
 
   $form['obo_new']['obo_file']= array(
   $form['obo_new']['obo_file']= array(
@@ -81,14 +75,11 @@ function tripal_cv_obo_form(&$form_state = NULL) {
     '#description'   => t('Please enter the full system path for an OBO definition file, or a path within the Drupal
     '#description'   => t('Please enter the full system path for an OBO definition file, or a path within the Drupal
                            installation (e.g. /sites/default/files/xyz.obo).  The path must be accessible to the
                            installation (e.g. /sites/default/files/xyz.obo).  The path must be accessible to the
                            server on which this Drupal instance is running.'),
                            server on which this Drupal instance is running.'),
-    '#default_value' => $default_desc,
-    '#weight'        => 3
   );
   );
 
 
   $form['submit'] = array(
   $form['submit'] = array(
     '#type'         => 'submit',
     '#type'         => 'submit',
     '#value'        => t('Submit'),
     '#value'        => t('Submit'),
-    '#weight'       => 5,
     '#executes_submit_callback' => TRUE,
     '#executes_submit_callback' => TRUE,
   );
   );
 
 
@@ -125,7 +116,7 @@ function tripal_cv_cvtermpath_form() {
 
 
   $cvs = array();
   $cvs = array();
   $cvs[] = '';
   $cvs[] = '';
-  while ($cv = db_fetch_object($results)) {
+  foreach ($results as $cv) {
     $cvs[$cv->cv_id] = $cv->name;
     $cvs[$cv->cv_id] = $cv->name;
   }
   }
 
 
@@ -161,8 +152,8 @@ function tripal_cv_cvtermpath_form() {
 function tripal_cv_load_obo_v1_2_id($obo_id, $jobid = NULL) {
 function tripal_cv_load_obo_v1_2_id($obo_id, $jobid = NULL) {
 
 
   // get the OBO reference
   // get the OBO reference
-  $sql = "SELECT * FROM {tripal_cv_obo} WHERE obo_id = %d";
-  $obo = db_fetch_object(db_query($sql, $obo_id));
+  $sql = "SELECT * FROM {tripal_cv_obo} WHERE obo_id = :obo_id";
+  $obo = db_query($sql, array(':obo_id' => $obo_id))->fetchObject();
 
 
   // if the reference is for a remote URL then run the URL processing function
   // if the reference is for a remote URL then run the URL processing function
   if (preg_match("/^http:\/\//", $obo->path) or preg_match("/^ftp:\/\//", $obo->path)) {
   if (preg_match("/^http:\/\//", $obo->path) or preg_match("/^ftp:\/\//", $obo->path)) {
@@ -274,9 +265,9 @@ function tripal_cv_load_obo_v1_2($file, $jobid = NULL, &$newcvs) {
     
     
   // make sure our temporary table exists
   // make sure our temporary table exists
   $ret = array(); 
   $ret = array(); 
-  if (!db_table_exists('tripal_obo_temp')) { 
+  if (!chado_table_exists('tripal_obo_temp')) { 
     $schema = tripal_cv_get_custom_tables('tripal_obo_temp');  
     $schema = tripal_cv_get_custom_tables('tripal_obo_temp');  
-    $success = tripal_core_create_custom_table($ret, 'tripal_obo_temp', $schema['tripal_obo_temp']);
+    $success = tripal_core_create_custom_table('tripal_obo_temp', $schema['tripal_obo_temp']);
     if (!$success) {
     if (!$success) {
       watchdog('T_obo_loader', "Cannot create temporary loading table", array(), WATCHDOG_ERROR); 
       watchdog('T_obo_loader', "Cannot create temporary loading table", array(), WATCHDOG_ERROR); 
       return;
       return;
@@ -286,20 +277,6 @@ function tripal_cv_load_obo_v1_2($file, $jobid = NULL, &$newcvs) {
   $sql = "DELETE FROM {tripal_obo_temp}";
   $sql = "DELETE FROM {tripal_obo_temp}";
   chado_query($sql);
   chado_query($sql);
 
 
-  // get a persistent connection
-  $connection = tripal_db_persistent_chado();
-  if (!$connection) {
-     print "A persistant connection was not obtained. Loading will be slow\n";
-  }
-          
-  // if we cannot get a connection then let the user know the loading will be slow
-  tripal_db_start_transaction();
-  if ($connection) {
-     print "\nNOTE: Loading of this OBO file is performed using a database transaction. \n" .
-           "If the load fails or is terminated prematurely then the entire set of \n" .
-           "insertions/updates is rolled back and will not be found in the database\n\n";
-  }
-
   print "Step 1: Preloading File $file\n";  
   print "Step 1: Preloading File $file\n";  
 
 
   // make sure we have an 'internal' and a '_global' database
   // make sure we have an 'internal' and a '_global' database
@@ -350,19 +327,15 @@ function tripal_cv_obo_quiterror($message) {
  * 
  * 
  */
  */
 function tripal_cv_obo_load_typedefs($defaultcv, $newcvs, $default_db, $jobid){
 function tripal_cv_obo_load_typedefs($defaultcv, $newcvs, $default_db, $jobid){
-  $sql = "
-    SELECT * 
-    FROM tripal_obo_temp
-    WHERE type = 'Typedef' 
-  ";
+  $sql = "SELECT * FROM {tripal_obo_temp} WHERE type = 'Typedef' ";
   $typedefs = chado_query($sql);
   $typedefs = chado_query($sql);
   
   
-    $sql = "
+  $sql = "
     SELECT count(*) as num_terms
     SELECT count(*) as num_terms
-    FROM tripal_obo_temp
+    FROM {tripal_obo_temp}
     WHERE type = 'Typedef'     
     WHERE type = 'Typedef'     
   "; 
   "; 
-  $result = db_fetch_object(chado_query($sql));
+  $result = chado_query($sql)->fetchObject();
   $count = $result->num_terms;
   $count = $result->num_terms;
   
   
   // calculate the interval for updates
   // calculate the interval for updates
@@ -371,7 +344,7 @@ function tripal_cv_obo_load_typedefs($defaultcv, $newcvs, $default_db, $jobid){
     $interval = 1;
     $interval = 1;
   }
   }
   $i = 0;
   $i = 0;
-  while ($typedef = db_fetch_object($typedefs)) {
+  foreach ($typedefs as $typedef) {
     $term = unserialize(base64_decode($typedef->stanza));
     $term = unserialize(base64_decode($typedef->stanza));
     
     
     // update the job status every interval
     // update the job status every interval
@@ -419,7 +392,7 @@ function tripal_cv_obo_process_terms($defaultcv, $jobid = NULL, &$newcvs, $defau
     FROM {tripal_obo_temp}
     FROM {tripal_obo_temp}
     WHERE type = 'Term'     
     WHERE type = 'Term'     
   "; 
   "; 
-  $result = db_fetch_object(chado_query($sql));
+  $result = chado_query($sql)->fetchObject();
   $count = $result->num_terms;
   $count = $result->num_terms;
   
   
   // calculate the interval for updates
   // calculate the interval for updates
@@ -427,7 +400,7 @@ function tripal_cv_obo_process_terms($defaultcv, $jobid = NULL, &$newcvs, $defau
   if ($interval < 1) {
   if ($interval < 1) {
     $interval = 1;
     $interval = 1;
   }
   }
-  while($t = db_fetch_object($terms)) {
+  foreach ($terms as $t) {
     $term = unserialize(base64_decode($t->stanza));
     $term = unserialize(base64_decode($t->stanza));
     
     
     // update the job status every interval
     // update the job status every interval

+ 2 - 2
tripal_cv/tripal_cv.info

@@ -1,8 +1,8 @@
 name = Tripal CV
 name = Tripal CV
 description = The controlled vocabulary module for the Tripal package that integrates Drupal and GMOD chado. This module provides support for managing and viewing controlled vocabularies.
 description = The controlled vocabulary module for the Tripal package that integrates Drupal and GMOD chado. This module provides support for managing and viewing controlled vocabularies.
-core = 6.x
+core = 7.x
 project = tripal_cv
 project = tripal_cv
 package = Tripal
 package = Tripal
-version = 6.x-1.1
+version = 7.x-2.0
 dependencies[] = tripal_core
 dependencies[] = tripal_core
 dependencies[] = tripal_db
 dependencies[] = tripal_db

+ 3 - 43
tripal_cv/tripal_cv.install

@@ -31,8 +31,8 @@ function tripal_cv_install() {
     // SQL statement that populates the view
     // SQL statement that populates the view
     'SELECT DISTINCT CVT.name,CVT.cvterm_id, CV.cv_id, CV.name
     'SELECT DISTINCT CVT.name,CVT.cvterm_id, CV.cv_id, CV.name
      FROM {cvterm_relationship} CVTR
      FROM {cvterm_relationship} CVTR
-       INNER JOIN cvterm CVT on CVTR.object_id = CVT.cvterm_id
-       INNER JOIN CV on CV.cv_id = CVT.cv_id
+       INNER JOIN {cvterm} CVT on CVTR.object_id = CVT.cvterm_id
+       INNER JOIN {cv} CV on CV.cv_id = CVT.cv_id
      WHERE CVTR.object_id not in
      WHERE CVTR.object_id not in
        (SELECT subject_id FROM {cvterm_relationship}) ',
        (SELECT subject_id FROM {cvterm_relationship}) ',
     // special index
     // special index
@@ -40,27 +40,9 @@ function tripal_cv_install() {
   );
   );
 
 
   // create the tables that correlate OBO files/references with a chado CV
   // create the tables that correlate OBO files/references with a chado CV
-  drupal_install_schema('tripal_cv');
   tripal_cv_add_obo_defaults();
   tripal_cv_add_obo_defaults();
 }
 }
 
 
-/**
- *  This update adds the new tripal_obo table.  This is an upgrade from
- *  Tripal version 0.2
- *
- * @ingroup tripal_cv
- */
-
-function tripal_cv_update_6000() {
-  drupal_install_schema('tripal_cv');
-  tripal_cv_add_obo_defaults();
-  $ret = array(
-    '#finished' => 1,
-  );
-
-  return $ret;
-}
-
 /**
 /**
  * Implementation of hook_uninstall().
  * Implementation of hook_uninstall().
  *
  *
@@ -73,8 +55,6 @@ function tripal_cv_uninstall() {
   if ($mview) {
   if ($mview) {
     tripal_mviews_action('delete', $mview);
     tripal_mviews_action('delete', $mview);
   }
   }
-
-  drupal_uninstall_schema('tripal_cv');
 }
 }
 
 
 /**
 /**
@@ -83,21 +63,6 @@ function tripal_cv_uninstall() {
  * @ingroup tripal_cv
  * @ingroup tripal_cv
  */
  */
 function tripal_cv_schema() {
 function tripal_cv_schema() {
-  $schema = tripal_cv_get_schemas();
-  return $schema;
-}
-
-/**
- * This function simply defines all tables needed for the module to work
- * correctly.  By putting the table definitions in a separate function we
- * can easily provide the entire list for hook_install or individual
- * tables for an update.
- *
- * @ingroup tripal_cv
- */
-function tripal_cv_get_schemas() {
-  $schema = array();
-
   $schema['tripal_cv_obo'] = array(
   $schema['tripal_cv_obo'] = array(
     'fields' => array(
     'fields' => array(
       'obo_id' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
       'obo_id' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
@@ -131,13 +96,8 @@ function tripal_cv_add_obo_defaults() {
     array('Plant Growth and Development Stages Ontology', 'http://palea.cgrb.oregonstate.edu/viewsvn/Poc/trunk/ontology/OBO_format/po_temporal.obo?view=co')
     array('Plant Growth and Development Stages Ontology', 'http://palea.cgrb.oregonstate.edu/viewsvn/Poc/trunk/ontology/OBO_format/po_temporal.obo?view=co')
   );
   );
   foreach ($ontologies as $o) {
   foreach ($ontologies as $o) {
-    db_query(
-      "INSERT INTO {tripal_cv_obo} (name,path) VALUES ('%s','%s')",
-      $o[0],
-      $o[1]
-    );
+    db_query("INSERT INTO {tripal_cv_obo} (name,path) VALUES (:name, :path)", array(':name' => $o[0], ':path' => $o[1]));
   }
   }
-
 }
 }
 
 
 /**
 /**

+ 5 - 2
tripal_cv/tripal_cv.module

@@ -191,9 +191,12 @@ function tripal_cv_menu() {
  *
  *
  * @ingroup tripal_cv
  * @ingroup tripal_cv
  */
  */
-function tripal_cv_perm() {
+function tripal_cv_permission() {
   return array(
   return array(
-    'administer controlled vocabularies',
+    'administer controlled vocabularies' => array(
+      'title' => t('Administer controlled vocabularies (CVs).'),
+      'description' => t('Allow a user to add, edit and delete controlled vocabularies as well as add and edit terms.')
+    ),
   );
   );
 }
 }
 
 

+ 9 - 18
tripal_db/api/tripal_db.api.inc

@@ -84,11 +84,8 @@ function tripal_db_get_db($select_values) {
  */
  */
 function tripal_db_get_db_by_db_id($db_id) {
 function tripal_db_get_db_by_db_id($db_id) {
 
 
-  $r = db_fetch_object(chado_query(
-    "SELECT * FROM {db} WHERE db_id=%d", $db_id
-  ));
-
-  return $r;
+  $r = chado_query("SELECT * FROM {db} WHERE db_id = :db_id", array(':db_id' => $db_id ));
+  return $r->fetchObject();
 }
 }
 
 
 /**
 /**
@@ -142,12 +139,10 @@ function tripal_db_get_db_by_name($name) {
  */
  */
 function tripal_db_get_db_options() {
 function tripal_db_get_db_options() {
 
 
-  $result = chado_query(
-    "SELECT db_id, name FROM {db}"
-  );
+  $result = chado_query("SELECT db_id, name FROM {db}");
 
 
   $options = array();
   $options = array();
-  while ( $r = db_fetch_object($result) ) {
+  foreach ($result as $r) {
     $options[$r->db_id] = $r->name;
     $options[$r->db_id] = $r->name;
   }
   }
 
 
@@ -257,19 +252,15 @@ function tripal_db_get_dbxref($select_values) {
 function tripal_db_get_dbxref_by_accession($accession, $db_id=0) {
 function tripal_db_get_dbxref_by_accession($accession, $db_id=0) {
 
 
   if (!empty($db_id)) {
   if (!empty($db_id)) {
-    $r = db_fetch_object(chado_query(
-      "SELECT * FROM {dbxref} WHERE accession='%s' AND db_id=%d",
-      $accession, $db_id
-    ));
+  	$sql = "SELECT * FROM {dbxref} WHERE accession = :accession AND db_id = :db_id";
+    $r = chado_query($sql, array(':accession' => $accession, ':db_id' => $db_id));
   }
   }
   else {
   else {
-    $r = db_fetch_object(chado_query(
-      "SELECT * FROM {dbxref} WHERE accession='%s'",
-      $accession
-    ));
+  	$sql = "SELECT * FROM {dbxref} WHERE accession = :accession";
+    $r = chado_query($sql, array(':accession' => $accession));
   }
   }
 
 
-  return $r;
+  return $r->fetchObject();
 }
 }
 
 
 /**
 /**

+ 0 - 15
tripal_db/tripal_db.module

@@ -86,21 +86,6 @@ function tripal_db_views_api() {
   return array('api' => 2.0);
   return array('api' => 2.0);
 }
 }
 
 
-function tripal_db_form_alter(&$form, &$form_state, $form_id) {
-  if ($form_id == "tripal_db_form") {    
-    // updating the form through the ahah callback sets the action of
-    // the form to the ahah callback URL. We need to set it back
-    // to the normal form URL 
-    if (array_key_exists('values', $form_state)) {
-	    if ($form_state['values']['form_action'] == 'Update') {
-	      $form['#action'] = url("admin/tripal/tripal_db/edit_db");
-	    }
-	    if ($form_state['values']['form_action'] == 'Add') {
-	      $form['#action'] = url("admin/tripal/tripal_db/add_db");
-	    }
-    }
-  } 
-}
 
 
 /**
 /**
  *  We need to let drupal know about our theme functions and their arguments.
  *  We need to let drupal know about our theme functions and their arguments.