Răsfoiți Sursa

Converted tripal_pub

spficklin 11 ani în urmă
părinte
comite
38e9922c11

+ 1 - 1
tripal_feature/includes/gff_loader.inc

@@ -315,7 +315,7 @@ function tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id,
   $ret = array(); 
   if (!db_table_exists('tripal_gff_temp')) { 
     $schema = tripal_feature_get_custom_tables('tripal_gff_temp');  
-    $success = tripal_core_create_custom_table($ret, 'tripal_gff_temp', $schema['tripal_gff_temp']);
+    $success = tripal_core_create_custom_table('tripal_gff_temp', $schema['tripal_gff_temp']);
     if (!$success) {
       watchdog('T_gff3_loader', "Cannot create temporary loading table", array(), WATCHDOG_ERROR); 
       return;

+ 32 - 18
tripal_pub/api/tripal_pub.api.inc

@@ -134,13 +134,13 @@ function tripal_pub_update_publications($do_contact = FALSE, $dbxref = NULL, $db
   if ($dbxref and preg_match('/^(.*?):(.*?)$/', $dbxref, $matches)) {
     $dbname = $matches[1];
     $accession = $matches[2];
-    $sql .= "WHERE DBX.accession = '%s' and DB.name = '%s' ";
-    $args[] = $accession;
-    $args[] = $dbname;
+    $sql .= "WHERE DBX.accession = :accession and DB.name = :dbname ";
+    $args[':accession'] = $accession;
+    $args[':dbname'] = $dbname;
   }
   elseif ($db) {
-    $sql .= " WHERE DB.name = '%s' ";
-    $args[] = $db;
+    $sql .= " WHERE DB.name = :dbname ";
+    $args[':dbname'] = $db;
   }
   $sql .= "ORDER BY DB.name, P.pub_id";
   $results = chado_query($sql, $args);
@@ -152,7 +152,7 @@ function tripal_pub_update_publications($do_contact = FALSE, $dbxref = NULL, $db
   $search = array();      // the search array passed to the search function
 
   // iterate through the pub IDs
-  while ($pub = db_fetch_object($results)) {
+  while ($pub = $results->fetchObject()) {
     $accession = $pub->accession;
     $remote_db = $pub->db_name;
 
@@ -170,8 +170,8 @@ function tripal_pub_update_publications($do_contact = FALSE, $dbxref = NULL, $db
           'scope' => 'id',
           'operation' => '',
           'is_phrase' => 0,
-    ),
-    ),
+        ),
+      ),
     );
     $pubs = tripal_pub_get_remote_search_results($remote_db, $search, 1, 0);
     tripal_pub_add_publications($pubs, $do_contact, TRUE);
@@ -225,7 +225,7 @@ function tripal_pub_import_publications($report_email = FALSE, $do_update = FALS
   $results = db_query($sql, $args);
   $do_contact = FALSE;
   $reports = array();
-  while ($import = db_fetch_object($results)) {
+  while ($import = $results->fetchObject()) {
     print "Importing: " . $import->name . "\n";
     // keep track if any of the importers want to create contacts from authors
     if ($import->do_contact == 1) {
@@ -736,14 +736,14 @@ function tripal_pub_add_publication($pub_details, &$action, $do_contact = FALSE,
     $sql = "
       DELETE FROM {pubprop} 
       WHERE 
-        pub_id = %d AND 
+        pub_id = :pub_id AND 
         NOT type_id in (
           SELECT cvterm_id
           FROM {cvterm} 
           WHERE name = 'Publication Dbxref' 
         )
     ";
-    chado_query($sql, $pub_id);
+    chado_query($sql, array(':pub_id' => $pub_id));
   }
 
   // iterate through the properties and add them
@@ -805,8 +805,8 @@ function tripal_pub_add_authors($pub_id, $authors, $do_contact) {
   $rank = 0;
 
   // first remove any of the existing pubauthor entires
-  $sql = "DELETE FROM {pubauthor} WHERE pub_id = %d";
-  chado_query($sql, $pub_id);
+  $sql = "DELETE FROM {pubauthor} WHERE pub_id = :pub_id";
+  chado_query($sql, array(':pub_id' => $pub_id));
 
   // iterate through the authors and add them to the pubauthors and contact
   // tables of chado, then link them through the custom pubauthors_contact table
@@ -1077,8 +1077,13 @@ function tripal_pub_get_publication_array($pub_id, $skip_existing = TRUE) {
   }
   // if there is no 'Author's property then try to retreive authors from the pubauthor table
   else {
-    $sql = "SELECT string_agg(surname || ' ' || givennames, ', ') FROM {pubauthor} WHERE pub_id = %d GROUP BY pub_id";
-    $au = db_result(chado_query($sql));
+    $sql = "
+      SELECT string_agg(surname || ' ' || givennames, ', ') 
+      FROM {pubauthor} 
+      WHERE pub_id = :pub_id
+      GROUP BY pub_id
+    ";
+    $au = chado_query($sql, array(':pub_id' => $pub_id))->fetchField();
     if ($au) {
       $pub_array['Authors'] = $au;
     }
@@ -1119,9 +1124,18 @@ function tripal_pub_get_publication_array($pub_id, $skip_existing = TRUE) {
   foreach ($props AS $prop) {
     $sql = 
       "SELECT value FROM {pubprop} 
-       WHERE type_id = (SELECT cvterm_id FROM {cvterm} WHERE name = '%s' AND cv_id = (SELECT cv_id FROM cv WHERE name = 'tripal_pub')) 
-       AND pub_id = %d";
-    $val = trim(db_result(chado_query($sql, $prop, $pub->pub_id)));
+       WHERE type_id = 
+         (SELECT cvterm_id 
+          FROM {cvterm} 
+          WHERE name = :cvtname AND cv_id = 
+            (SELECT cv_id 
+             FROM cv 
+             WHERE name = 'tripal_pub'
+            )
+         ) 
+       AND pub_id = :pub_id
+    ";
+    $val = trim(chado_query($sql, array(':cvtname' => $prop, ':pub_id' => $pub->pub_id))->fetchField());
     if ($val) {
       $pub_array[$prop] =$val;
     } 

+ 1 - 1
tripal_pub/includes/importers/PMID.inc

@@ -106,7 +106,7 @@ function tripal_pub_remote_search_PMID($search_array, $num_to_retrieve, $pager_i
   }
   if ($days) {
     // get the date of the day suggested
-    $past_timestamp = time() - ($days * 86400);
+    $past_timestamp = REQUEST_TIME - ($days * 86400);
     $past_date = getdate($past_timestamp);
     $search_str .= " AND (\"" . sprintf("%04d/%02d/%02d", $past_date['year'], $past_date['mon'], $past_date['mday']) . "\"[Date - Create] : \"3000\"[Date - Create]))";
   }

+ 38 - 20
tripal_pub/includes/pub_citation.inc

@@ -32,8 +32,7 @@ function tripal_pub_citation_form($form_state) {
 
 function tripal_pub_citation_form_submit(&$form_state) {
   $options [0] = $form_state['options']['#value'];
-  tripal_add_job("Create citations ($options[0])", 'tripal_pub',
-       'tripal_pub_create_citations', $options, $user->uid);
+  tripal_add_job("Create citations ($options[0])", 'tripal_pub', 'tripal_pub_create_citations', $options, $user->uid);
 }
 
 /*
@@ -41,40 +40,59 @@ function tripal_pub_citation_form_submit(&$form_state) {
  */
 function tripal_pub_create_citations ($options) {
   $skip_existing = TRUE;
-  $citation_type_id = db_result(chado_query("SELECT cvterm_id FROM {cvterm} WHERE name = 'Citation' AND cv_id = (SELECT cv_id FROM {cv} WHERE name = 'tripal_pub')"));
+  $sql = "
+    SELECT cvterm_id 
+    FROM {cvterm} 
+    WHERE 
+      name = 'Citation' AND 
+      cv_id = (SELECT cv_id FROM {cv} WHERE name = 'tripal_pub')
+  ";
+  $citation_type_id = chado_query($sql)->fetchField();
   // Create and replace citation for all pubs
   if ($options == 'all') {
-  	$sql = "SELECT pub_id FROM {pub} P WHERE pub_id <> 1";
-    $skip_existing = FALSE;
+    $sql = "SELECT pub_id FROM {pub} P WHERE pub_id <> 1";
+    $skip_existing = FALSE;  
+  } 
   // Create citation for pubs that don't already have one
-  } else if ($options == 'new') {
-  	$sql = "SELECT pub_id FROM {pub} P WHERE (SELECT value FROM {pubprop} PB WHERE type_id = $citation_type_id AND P.pub_id = PB.pub_id AND rank = 0) IS NULL AND  pub_id <> 1";
-  	$skip_existing = TRUE;
+  else if ($options == 'new') {
+    $sql = "
+      SELECT pub_id 
+      FROM {pub} P 
+      WHERE 
+        (SELECT value 
+         FROM {pubprop} PB 
+         WHERE type_id = :type_id AND P.pub_id = PB.pub_id AND rank = 0) IS NULL 
+        AND  pub_id <> 1
+    ";
+    $skip_existing = TRUE;
   }
 
-  $result = chado_query($sql);
+  $result = chado_query($sql, array(':type_id' => $citation_type_id));
   $counter_updated = 0;
   $counter_generated = 0;
-  while ($pub = db_fetch_object($result)) {
+  while ($pub = $result->fetchObject()) {
     $pub_arr = tripal_pub_get_publication_array($pub->pub_id, $skip_existing);
     if ($pub_arr) {
       $citation = tripal_pub_create_citation ($pub_arr);
       print $citation . "\n\n";
       // Replace if citation exists. This condition is never TRUE if $skip_existing is TRUE
       if ($pub_arr['Citation']) {
-        $sql = 
-            "UPDATE {pubprop} 
-             SET value = '%s' 
-             WHERE pub_id = %d 
-             AND type_id = %d
-             AND rank = %d";
-        chado_query($sql, $citation, $pub->pub_id, $citation_type_id, 0);
+        $sql = "
+          UPDATE {pubprop} SET value = :value 
+          WHERE pub_id = :pub_id  AND type_id = :type_id AND rank = :rank
+        ";
+        chado_query($sql, array(':value' => $citation, ':pub_id' => $pub->pub_id, 
+          ':type_id' => $citation_type_id, ':rank' => 0));
         $counter_updated ++;
       // Generate a new citation
       } else {
-      	$sql = "INSERT INTO {pubprop} (pub_id, type_id, value, rank) VALUES (%d, %d, '%s', %d)";
-      	chado_query($sql, $pub->pub_id, $citation_type_id, $citation, 0);
-      	$counter_generated ++;
+        $sql = "
+          INSERT INTO {pubprop} (pub_id, type_id, value, rank) 
+          VALUES (:pub_id, :type_id, :value, :rank)
+        ";
+        chado_query($sql, array(':pub_id' => $pub->pub_id, ':type_id' => $citation_type_id, 
+          ':value' => $citation, ':rank' => 0));
+        $counter_generated ++;
       }
     }
   }

+ 16 - 13
tripal_pub/includes/pub_form.inc

@@ -45,18 +45,20 @@ function chado_pub_form($node, $form_state) {
   // ontologies these are all grouped under the term 'Publication Type'
   // we want the default to be 'Journal Article'
   $sql = "
-    SELECT CVTS.cvterm_id, CVTS.name
+    SELECT 
+      CVTS.cvterm_id, CVTS.name
     FROM {cvtermpath} CVTP
       INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
-      INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
-      INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
-    WHERE CV.name = 'tripal_pub' and CVTO.name = 'Publication Type' and 
+      INNER JOIN {cvterm} CVTO ON CVTP.object_id  = CVTO.cvterm_id
+      INNER JOIN {cv}          ON CVTO.cv_id      = CV.cv_id
+    WHERE 
+      CV.name = 'tripal_pub' AND CVTO.name = 'Publication Type' AND 
       NOT CVTS.is_obsolete = 1
     ORDER BY CVTS.name ASC 
   ";
   $results = chado_query($sql);
   $pub_types = array();
-  while ($pub_type = db_fetch_object($results)) {
+  while ($pub_type = $results->fetchObject()) {
     $pub_types[$pub_type->cvterm_id] = $pub_type->name;
     // if we don't have a default type then set the default to be 'Journal Article'
     if (strcmp($pub_type->name,"Journal Article") == 0 and !$d_type_id) {
@@ -72,18 +74,19 @@ function chado_pub_form($node, $form_state) {
   $properties_select[] = 'Select a Property';
   $properties_list = array();
   $sql = "
-    SELECT DISTINCT CVTS.cvterm_id, CVTS.name, CVTS.definition
+    SELECT 
+      DISTINCT CVTS.cvterm_id, CVTS.name, CVTS.definition
     FROM {cvtermpath} CVTP
       INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
-      INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
-      INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
+      INNER JOIN {cvterm} CVTO ON CVTP.object_id  = CVTO.cvterm_id
+      INNER JOIN {cv}          ON CVTO.cv_id      = CV.cv_id
     WHERE CV.name = 'tripal_pub' and 
-      (CVTO.name = 'Publication Details' or CVTS.name = 'Publication Type') and 
+      (CVTO.name = 'Publication Details' OR CVTS.name = 'Publication Type') AND 
       NOT CVTS.is_obsolete = 1
     ORDER BY CVTS.name ASC 
   ";
   $prop_types = chado_query($sql);
-  while ($prop = db_fetch_object($prop_types)) {
+  while ($prop = $prop_types->fetchObject()) {
     // the 'Citation' term is special because it serves
     // both as a property and as the uniquename for the publiation table
     if ($prop->name != "Citation") {
@@ -539,11 +542,11 @@ function chado_pub_node_form_add_pubprop_table_props(&$form, $form_state, $pub_i
     SELECT CVT.cvterm_id, CVT.name, CVT.definition, PP.value, PP.rank
     FROM {pubprop} PP
       INNER JOIN {cvterm} CVT on CVT.cvterm_id = PP.type_id
-    WHERE PP.pub_id = %d
+    WHERE PP.pub_id = :pub_id
     ORDER BY CVT.name, PP.rank
   ";
-  $pub_props = chado_query($sql, $pub_id);
-  while ($prop = db_fetch_object($pub_props)) {
+  $pub_props = chado_query($sql, array(':pub_id' => $pub_id));
+  while ($prop = $pub_props->fetchObject()) {
 
     $type_id = $prop->cvterm_id;
     $rank = count($d_properties[$type_id]);

+ 9 - 9
tripal_pub/includes/pub_importers.inc

@@ -12,7 +12,7 @@ function tripal_pub_importers_list() {
   $rows = array();
   $importers = db_query("SELECT * FROM {tripal_pub_import} ORDER BY name");
 
-  while ($importer = db_fetch_object($importers)) {
+  while ($importer = $importers->fetchObject()) {
     $criteria = unserialize($importer->criteria);
     $num_criteria = $criteria['num_criteria'];
     $criteria_str = '';
@@ -176,8 +176,8 @@ function tripal_pub_importer_setup_form(&$form_state = NULL, $pub_import_id = NU
   // and one is provided then look it up in the database
   $criteria = NULL;
   if ($action == "edit" and !$form_state['values']) {
-    $sql = "SELECT * FROM {tripal_pub_import} WHERE pub_import_id = %d";
-    $importer = db_fetch_object(db_query($sql, $pub_import_id));
+    $sql = "SELECT * FROM {tripal_pub_import} WHERE pub_import_id = :pub_import_id";
+    $importer = db_query($sql, array(':pub_import_id' => $pub_import_id))->fetchObject();
 
     $criteria       = unserialize($importer->criteria);
     $remote_db      = $criteria['remote_db'];
@@ -520,8 +520,8 @@ function tripal_pub_importer_setup_form_submit($form, &$form_state) {
     );
     // first check to see if this pub_import_id is already present. If so,
     // do an update rather than an insert
-    $sql = "SELECT * FROM {tripal_pub_import} WHERE pub_import_id = %d";
-    $importer = db_fetch_object(db_query($sql, $pub_import_id));
+    $sql = "SELECT * FROM {tripal_pub_import} WHERE pub_import_id = :pub_import_id";
+    $importer = db_query($sql, array(':pub_import_id' => $pub_import_id))->fetchObject();
     if($importer) {
       // do the update
       $record['pub_import_id'] = $pub_import_id;
@@ -552,8 +552,8 @@ function tripal_pub_importer_setup_form_submit($form, &$form_state) {
     }
   }
   if ($form_state['values']['op'] == 'Delete Importer') {
-    $sql = "DELETE FROM {tripal_pub_import} WHERE pub_import_id = %d";
-    $success = db_query($sql, $pub_import_id);
+    $sql = "DELETE FROM {tripal_pub_import} WHERE pub_import_id = :pub_import_id";
+    $success = db_query($sql, array(':pub_import_id' => $pub_import_id));
     if ($success) {
       drupal_set_message('Publication importer deleted.');
       drupal_goto('admin/tripal/tripal_pub/import_list');
@@ -568,8 +568,8 @@ function tripal_pub_importer_setup_form_submit($form, &$form_state) {
  *
  */
 function tripal_pub_importer_delete($pub_import_id) {
-  $sql = "DELETE FROM {tripal_pub_import} WHERE pub_import_id = %d";
-  $success = db_query($sql, $pub_import_id);
+  $sql = "DELETE FROM {tripal_pub_import} WHERE pub_import_id = :pub_import_id";
+  $success = db_query($sql, array(':pub_import_id' => $pub_import_id));
   if ($success) {
     drupal_set_message('Publication importer deleted.');
     drupal_goto('admin/tripal/tripal_pub/import_list');

+ 21 - 36
tripal_pub/includes/pub_search.inc

@@ -41,7 +41,7 @@ function tripal_pub_search_page() {
     // iterate through the results and construct the table displaying the publications
     $rows = array();
     $i = $page * $limit + 1;
-    while($pub = db_fetch_object($pubs)) {
+    while($pub = $pubs->fetchObject()) {
       // get the citation for this publication
       $values = array(
         'pub_id' => $pub->pub_id, 
@@ -140,7 +140,7 @@ function tripal_pub_search_form(&$form_state = NULL) {
   ";
   $allowed_fields = variable_get('tripal_pub_allowed_search_fields', array());
   $prop_types = chado_query($sql);
-  while ($prop = db_fetch_object($prop_types)) {
+  while ($prop = $prop_types->fetchObject()) {
     if($allowed_fields[$prop->cvterm_id] > 0) {
       $properties[$prop->cvterm_id] = $prop->name;
     }
@@ -414,8 +414,7 @@ function tripal_pub_get_search_results($search_array, $limit, $pager_id) {
             ";
   $where  = "WHERE (NOT P.title = 'null') "; // always exclude the dummy pub
   $order  = "ORDER BY P.pyear DESC, P.title ASC";
-  $fargs = array(); // arguments for from, inner join clause
-  $wargs = array();  // arguments for where clause
+  $args = array();  // arguments for where clause
   $join = 0;
 
   $num_criteria = $search_array['num_criteria'];
@@ -447,13 +446,13 @@ function tripal_pub_get_search_results($search_array, $limit, $pager_id) {
 
     $action = "= lower('%s')";
     if($mode == 'Contains') {
-      $action = 'LIKE lower(\'%%%s%%\')';
+      $action = 'LIKE lower(\'%%' . ":crit$i" . '%%\')';
     }
     if($mode == 'Starts With') {
-      $action = '= lower(\'%%%s\')';
+      $action = '= lower(\'%%' . ":crit$i" . '\')';
     }
     if($mode == 'Ends With') {
-      $action = '= lower(\'%s%%\')';
+      $action = '= lower(\'' . ":crit$i" . '%%\')';
     }
      
     // get the scope type
@@ -462,39 +461,35 @@ function tripal_pub_get_search_results($search_array, $limit, $pager_id) {
     $type_name = $cvterm[0]->name;
     if ($type_name == 'Title') {
       $where .= " $op (lower(P.title)  $action) ";
-      $wargs[] = $value;
+      $args[":crit$i"] = $value;
     }
     elseif ($type_name == 'Year') {
       $where .= " $op (lower(P.pyear)  $action) ";
-      $wargs[] = $value;
+      $args[":crit$i"] = $value;
     }
     elseif ($type_name == 'Volume') {
       $where .= " $op (lower(P.volume)  $action) ";
-      $wargs[] = $value;
+      $args[":crit$i"] = $value;
     }
     elseif ($type_name == 'Issue') {
       $where .= " $op (lower(P.issue)  $action)";
-      $wargs[] = $value;
+      $args[":crit$i"] = $value;
     }
     elseif ($type_name == 'Journal Name') {
-      $from .= " LEFT JOIN {pubprop} PP$i ON PP$i.pub_id = P.pub_id AND PP$i.type_id = %d ";
+      $from .= " LEFT JOIN {pubprop} PP$i ON PP$i.pub_id = P.pub_id AND PP$i.type_id = :crit$i ";
       $where .= " $op ((lower(P.series_name) $action and CVT.name = 'Journal Article') OR
                        (lower(PP$i.value) $action)) ";
-      $fargs[] = $type_id;
-      $wargs[] = $value;
-      $wargs[] = $value;
+      $args[":crit$i"] = $type_id;
     }
     elseif ($type_name == 'Conference Name') {
-      $from .= " LEFT JOIN {pubprop} PP$i ON PP$i.pub_id = P.pub_id AND PP$i.type_id = %d ";
+      $from .= " LEFT JOIN {pubprop} PP$i ON PP$i.pub_id = P.pub_id AND PP$i.type_id = :crit$i ";
       $where .= " $op ((lower(P.series_name) $action and CVT.name = 'Conference Proceedings') OR
                        (lower(PP$i.value) $action)) ";
-      $fargs[] = $type_id;
-      $wargs[] = $value;
-      $wargs[] = $value;
+      $args[":crit$i"] = $type_id;
     }
     elseif ($type_name == 'Publication Type') {
       $where .= " $op (lower(CVT.name) $action)";
-      $wargs[] = $value;
+      $args[":crit$i"] = $value;
     }
     elseif ($type_id == 0) { //'Any Field'
       $from .= " LEFT JOIN {pubprop} PP$i ON PP$i.pub_id = P.pub_id ";
@@ -506,32 +501,22 @@ function tripal_pub_get_search_results($search_array, $limit, $pager_id) {
                        lower(P.pubplace) $action OR
                        lower(P.miniref) $action OR
                        lower(P.series_name) $action) ";
-      $wargs[] = $value;
-      $wargs[] = $value;
-      $wargs[] = $value;
-      $wargs[] = $value;
-      $wargs[] = $value;
-      $wargs[] = $value;
-      $wargs[] = $value;
-      $wargs[] = $value;
+      $args[":crit$i"] = $value;
     }
     // for all other properties
     else {
-      $from .= " LEFT JOIN {pubprop} PP$i ON PP$i.pub_id = P.pub_id AND PP$i.type_id = %d ";
+      $from .= " LEFT JOIN {pubprop} PP$i ON PP$i.pub_id = P.pub_id AND PP$i.type_id = :crit$i ";
       $where .= " $op (lower(PP$i.value) $action) ";
-      $fargs[] = $type_id;
-      $wargs[] = $value;
+      $args[":crit$i"] = $type_id;
     }
 
   }
   if($from_year and $to_year) {
-    $where .= " AND (P.pyear ~ '....' AND to_number(P.pyear,'9999') >= %d AND to_number(P.pyear,'9999') <= %d) ";
-    $wargs[] = $from_year;
-    $wargs[] = $to_year;
+    $where .= " AND (P.pyear ~ '....' AND to_number(P.pyear,'9999') >= :from$i AND to_number(P.pyear,'9999') <= :to$i) ";
+    $args[":from$i"] = $from_year;
+    $args[":to$i"] = $to_year;
   }
   $sql = "$select $from $where $order";
   $count = "SELECT count(*) FROM ($select $from $where $order) as t1";
-  $args = array_merge($fargs, $wargs);
-  //dpm(array($mode, $sql, $args));
   return chado_pager_query($sql, $limit, $pager_id, $count, $args);
 }

+ 4 - 4
tripal_pub/includes/pub_sync.inc

@@ -42,14 +42,14 @@ function tripal_pub_sync_pubs($job_id = NULL) {
   // to sync that one.
   $sql = "
     SELECT P.*
-    FROM chado.pub P
-      LEFT JOIN {chado_pub} CP ON CP.pub_id = P.pub_id
+    FROM {pub} P
+      LEFT JOIN public.chado_pub CP ON CP.pub_id = P.pub_id
     WHERE CP.pub_id IS NULL and NOT P.title = 'NULL'
   ";
-  $results = db_query($sql);
+  $results = chado_query($sql);
 
 
-  while ($pub = db_fetch_object($results)) {
+  while ($pub = $results->fetchObject()) {
     $node = tripal_pub_sync_pub($pub);
   }
 }

+ 8 - 7
tripal_pub/includes/tripal_pub.admin.inc

@@ -46,18 +46,19 @@ function get_tripal_pub_admin_form_default_type(&$form) {
   // ontologies these are all grouped under the term 'Publication Type'
   // we want the default to be 'Journal Article'
   $sql = "
-    SELECT CVTS.cvterm_id, CVTS.name
+    SELECT 
+      CVTS.cvterm_id, CVTS.name
     FROM {cvtermpath} CVTP
       INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
-      INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
-      INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
-    WHERE CV.name = 'tripal_pub' and CVTO.name = 'Publication Type' and 
+      INNER JOIN {cvterm} CVTO ON CVTP.object_id  = CVTO.cvterm_id
+      INNER JOIN {cv}          ON CVTO.cv_id      = CV.cv_id
+    WHERE CV.name = 'tripal_pub' AND CVTO.name = 'Publication Type' AND 
       NOT CVTS.is_obsolete = 1
     ORDER BY CVTS.name ASC 
   ";
   $results = chado_query($sql);
   $pub_types = array();
-  while ($pub_type = db_fetch_object($results)) {
+  while ($pub_type = $results->fetchObject()) {
     $pub_types[$pub_type->cvterm_id] = $pub_type->name;
     if (strcmp($pub_type->name,"Journal Article") == 0) {
       $d_type_id = $pub_type->cvterm_id;
@@ -156,7 +157,7 @@ function get_tripal_pub_admin_form_select_search_list(&$form) {
     ORDER BY CVTS.name ASC 
   ";
   $prop_types = chado_query($sql);
-  while ($prop = db_fetch_object($prop_types)) {
+  while ($prop = $prop_types->fetchObject()) {
     $properties[$prop->cvterm_id] = $prop->name;
   }
   $form['searching']['allowed_search_fields'] = array(
@@ -225,7 +226,7 @@ function tripal_pub_set_pub_url($node, $pub_id) {
   $url_alias = "pub/$pub_id";
 
   // remove any previous alias
-  db_query("DELETE FROM {url_alias} WHERE src = '%s'", $node_url);
+  db_query("DELETE FROM {url_alias} WHERE src = :src", array(':src' => $node_url));
   // add the new alias
   path_set_alias($node_url, $url_alias);
 

+ 2 - 2
tripal_pub/tripal_pub.info

@@ -1,9 +1,9 @@
 name = Tripal Publication
 description = A module for interfacing the GMOD chado database with Drupal, providing viewing of publications
-core = 6.x
+core = 7.x
 project = tripal_pub
 package = Tripal
-version = 6.x-1.1
+version = 7.x-2.0-beta1
 dependencies[] = tripal_core
 dependencies[] = tripal_cv
 dependencies[] = tripal_db

+ 78 - 40
tripal_pub/tripal_pub.install

@@ -10,20 +10,35 @@
  * multiple project/mysql instances as well as manage and create such project instances
  */
 
+/**
+ * Implementation of hook_requirements().
+ */
+function tripal_pub_requirements($phase) {
+  $requirements = array();
+  if ($phase == 'install') {
+    // make sure chado is installed
+    if (!tripal_core_is_chado_installed()) {
+      $requirements ['tripal_pub'] = array(
+        'title' => "tripal_pub",
+        'value' => "ERROR: Chado most be installed before this module can be enabled",
+        'severity' => REQUIREMENT_ERROR,
+      );
+    }
+  }
+  return $requirements;
+}
 
 /**
  * Implementation of hook_install().
  */
 function tripal_pub_install() {
+  global $base_path;
 
   // create the module's data directory
   tripal_create_moddir('tripal_pub');
 
-  // install the tripal_oub
-  drupal_install_schema('tripal_pub');
-
   // add loading of the the tripal pub ontology to the job queue
-  $obo_path =  realpath('./') . '/' . drupal_get_path('module', 'tripal_pub') . '/files/tpub.obo';
+  $obo_path =  drupal_realpath(drupal_get_path('module', 'tripal_pub') . '/files/tpub.obo');
   $obo_id = tripal_cv_add_obo_ref('Tripal Publication', $obo_path);
   tripal_cv_submit_obo_job($obo_id);
 
@@ -32,6 +47,16 @@ function tripal_pub_install() {
 
 }
 
+/**
+ * Implementation of hook_uninstall().
+ */
+function tripal_pub_uninstall() {
+
+}
+
+/**
+ * 
+ */
 function tripal_pub_enable() {
   // make sure we have our supported databases
   tripal_db_add_db('PMID', 'PubMed', 'http://www.ncbi.nlm.nih.gov/pubmed', 'http://www.ncbi.nlm.nih.gov/pubmed/', TRUE);
@@ -39,13 +64,6 @@ function tripal_pub_enable() {
 
   variable_set('tripal_pub_supported_dbs', array('PMID', 'AGL'));
 }
-/**
- * Implementation of hook_uninstall().
- */
-function tripal_pub_uninstall() {
-  //Remove tables
-  drupal_uninstall_schema('tripal_pub');
-}
 
 
 /**
@@ -55,10 +73,27 @@ function tripal_pub_schema() {
 
   $schema['chado_pub'] = array(
     'fields' => array(
-      'vid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
-      'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
-      'pub_id' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
-      'sync_date' => array('type' => 'int', 'not null' => FALSE, 'description' => 'UNIX integer sync date/time'),
+      'vid' => array(
+        'type' => 'int', 
+        'unsigned' => TRUE, 
+        'not null' => TRUE, 'default' => 0
+      ),
+      'nid' => array(
+        'type' => 'int', 
+        'unsigned' => TRUE, 
+        'not null' => TRUE, 
+        'default' => 0
+      ),
+      'pub_id' => array(
+        'type' => 'int', 
+        'not null' => TRUE, 
+        'default' => 0
+      ),
+      'sync_date' => array(
+        'type' => 'int', 
+        'not null' => FALSE, 
+        'description' => 'UNIX integer sync date/time'
+      ),
     ),
     'indexes' => array(
       'pub_id' => array('pub_id')
@@ -72,11 +107,33 @@ function tripal_pub_schema() {
   
   $schema['tripal_pub_import'] = array(
     'fields' => array(
-      'pub_import_id' => array('type' => 'serial', 'not null' => TRUE),
-      'name' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE),
-      'criteria' => array('type' => 'text', 'size' => 'normal', 'not null' => TRUE, 'description' => 'Contains a serialized PHP array containing the search criteria'),
-      'disabled'  => array('type' => 'int', 'unsigned' => TRUE, 'not NULL' => TRUE, 'default' => 0),      
-      'do_contact'  => array('type' => 'int', 'unsigned' => TRUE, 'not NULL' => TRUE, 'default' => 0),
+      'pub_import_id' => array(
+        'type' => 'serial', 
+        'not null' => TRUE
+      ),
+      'name' => array(
+        'type' => 'varchar', 
+        'length' => 255, 
+        'not null' => TRUE
+      ),
+      'criteria' => array(
+        'type' => 'text', 
+        'size' => 'normal', 
+        'not null' => TRUE, 
+        'description' => 'Contains a serialized PHP array containing the search criteria'
+      ),
+      'disabled'  => array(
+        'type' => 'int', 
+        'unsigned' => TRUE, 
+        'not NULL' => TRUE, 
+        'default' => 0
+      ),      
+      'do_contact'  => array(
+        'type' => 'int', 
+        'unsigned' => TRUE, 
+        'not NULL' => TRUE, 
+        'default' => 0
+      ),
     ),
     'primary key' => array('pub_import_id'),
     'indexes' => array(
@@ -88,25 +145,6 @@ function tripal_pub_schema() {
 }
 
 
-
-/**
- * Implementation of hook_requirements().
- */
-function tripal_pub_requirements($phase) {
-  $requirements = array();
-  if ($phase == 'install') {
-    // make sure chado is installed
-    if (!tripal_core_is_chado_installed()) {
-      $requirements ['tripal_pub'] = array(
-        'title' => "tripal_pub",
-        'value' => "ERROR: Chado most be installed before this module can be enabled",
-        'severity' => REQUIREMENT_ERROR,
-      );
-    }
-  }
-  return $requirements;
-}
-
 /*
  *
  */
@@ -151,5 +189,5 @@ function tripal_pub_add_custom_tables() {
       ),
     ),
   );
-  tripal_core_create_custom_table($ret, 'pubauthor_contact', $schema, TRUE);
+  tripal_core_create_custom_table('pubauthor_contact', $schema, TRUE);
 }

+ 82 - 72
tripal_pub/tripal_pub.module

@@ -40,7 +40,7 @@ function tripal_pub_node_info() {
   return array(
     'chado_pub' => array(
       'name' => t('Publication'),
-      'module' => 'chado_pub',
+      'base' => 'chado_pub',
       'description' => t('A publication from the Chado database'),
       'title_label' => t('Article Title'),
       'body_label' => t('Abstract'),
@@ -283,15 +283,30 @@ function tripal_pub_help ($path, $arg) {
   }
 }
 /**
- * Implement hook_perm().
+ * Implement hook_permissions().
  */
-function tripal_pub_perm() {
+function tripal_pub_permissions() {
   return array(
-    'access chado_pub content',
-    'create chado_pub content',
-    'delete chado_pub content',
-    'edit chado_pub content',
-    'administer tripal pubs',
+    'access chado_pub content' => array(
+      'title' => t('View Publications'),
+      'description' => t('Allow users to view publication pages.'),
+    ),
+    'create chado_pub content' => array(
+      'title' => t('Create Publication'),
+      'description' => t('Allow users to create new publication pages.'),
+    ),
+    'delete chado_pub content' => array(
+      'title' => t('Delete Publication'),
+      'description' => t('Allow users to delete publication pages.'),
+    ),
+    'edit chado_pub content' => array(
+      'title' => t('Edit Publications'),
+      'description' => t('Allow users to edit publication pages.'),
+    ),
+    'adminster tripal pub' => array(
+      'title' => t('Administer Publications'),
+      'description' => t('Allow users to administer all publications.'),
+    ),
   );
 }
 
@@ -388,7 +403,7 @@ function chado_pub_insert($node) {
       ORDER BY CVTS.name ASC 
     ";
     $prop_types = chado_query($sql);
-    while ($prop = db_fetch_object($prop_types)) {
+    while ($prop = $prop_types->fetchObject()) {
       $properties_list[$prop->cvterm_id] = $prop->name;
       // The 'Citation' term is special because it serves
       // both as a property and as the uniquename for the
@@ -524,8 +539,8 @@ function chado_pub_insert($node) {
     if (!$pub_id) {
       // next add the item to the drupal table
       $sql = "INSERT INTO {chado_pub} (nid, vid, pub_id) ".
-             "VALUES (%d, %d, %d)";
-      db_query($sql, $node->nid, $node->vid, $pub['pub_id']);
+             "VALUES (:nid, :vid, :pub_id)";
+      db_query($sql, array(':nid' => $node->nid, ':vid' => $node->vid, ':pub_id' => $pub['pub_id']));
     }
   }
   else {
@@ -578,7 +593,7 @@ function chado_pub_update($node) {
     ORDER BY CVTS.name ASC 
   ";
   $prop_types = chado_query($sql);
-  while ($prop = db_fetch_object($prop_types)) {
+  while ($prop = $prop_types->fetchObject()) {
     $properties_list[$prop->cvterm_id] = $prop->name;
     // The 'Citation' term is special because it serves
     // both as a property and as the uniquename for the
@@ -776,43 +791,20 @@ function chado_pub_delete(&$node) {
     return;
   }
 
-  // Remove data from {chado_pub}, {node} and {node_revisions} tables of
+  // Remove data from {chado_pub}, {node} and {node_revision} tables of
   // drupal database
-  $sql_del = "DELETE FROM {chado_pub} ".
-             "WHERE nid = %d ".
-             "AND vid = %d";
-  db_query($sql_del, $node->nid, $node->vid);
-  $sql_del = "DELETE FROM {node_revisions} ".
-             "WHERE nid = %d ".
-             "AND vid = %d";
-  db_query($sql_del, $node->nid, $node->vid);
-  $sql_del = "DELETE FROM {node} ".
-             "WHERE nid = %d ".
-             "AND vid = %d";
-  db_query($sql_del, $node->nid, $node->vid);
+  $sql_del = "DELETE FROM {chado_pub} WHERE nid = :nid AND vid = :vid";
+  db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
+  $sql_del = "DELETE FROM {node_revision} WHERE nid = :nid AND vid = :vid";
+  db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
+  $sql_del = "DELETE FROM {node} WHERE nid = :nid AND vid = :vid";
+  db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
 
   // Remove data from pub and pubprop tables of chado database as well
-  chado_query("DELETE FROM {pubprop} WHERE pub_id = %d", $pub_id);
-  chado_query("DELETE FROM {pub} WHERE pub_id = %d", $pub_id);
+  chado_query("DELETE FROM {pubprop} WHERE pub_id = :pub_id", array(':pub_id' => $pub_id));
+  chado_query("DELETE FROM {pub} WHERE pub_id = :pub_id", array(':pub_id' => $pub_id));
 }
 
-/**
- * Because we are using AJAX with a node form we need to provide a callback
- * for the chado_pub node form.  This callback is different from the
- * default 'chado_pub_form' callback
- */
-/*
- function tripal_pub_forms($form_id, $args) {
- $forms = array();
- if($form_id == 'chado_pub_node_form') {
- $forms[$form_id] = array(
- 'callback' => 'chado_pub_node_form',
- 'callback arguments' => array($args)
- );
- }
- return $forms;
- }*/
-
 /*
  *
  */
@@ -855,18 +847,18 @@ function tripal_pub_preprocess_tripal_pub_relationships(&$variables) {
       INNER JOIN {pub} P            ON PR.object_id = P.pub_id
       INNER JOIN {cvterm} CVT       ON PR.type_id   = CVT.cvterm_id
       LEFT JOIN public.chado_pub CP ON P.pub_id     = CP.pub_id
-    WHERE PR.subject_id = %d
+    WHERE PR.subject_id = :subject_id
   ";
-  $as_subject = chado_query($sql, $pub->pub_id);
+  $as_subject = chado_query($sql, array(':subject_id' => $pub->pub_id));
   $sql = "
     SELECT P.title, P.pub_id, CP.nid, CVT.name as rel_type
     FROM pub_relationship PR
       INNER JOIN {pub} P            ON PR.subject_id = P.pub_id
       INNER JOIN {cvterm} CVT       ON PR.type_id    = CVT.cvterm_id
       LEFT JOIN public.chado_pub CP ON P.pub_id      = CP.pub_id
-    WHERE PR.object_id = %d
+    WHERE PR.object_id = :object_id
   ";
-  $as_object = chado_query($sql, $pub->pub_id);
+  $as_object = chado_query($sql, array(':object_id' => $pub->pub_id));
 
   // combine both object and subject relationshisp into a single array
   $relationships = array();
@@ -874,7 +866,7 @@ function tripal_pub_preprocess_tripal_pub_relationships(&$variables) {
   $relationships['subject'] = array();
 
   // iterate through the object relationships
-  while ($relationship = db_fetch_object($as_object)) {
+  while ($relationship = $as_object->fetchObject()) {
 
     // get the relationship and child types
     $rel_type = t(preg_replace('/_/', " ", $relationship->rel_type));
@@ -890,7 +882,7 @@ function tripal_pub_preprocess_tripal_pub_relationships(&$variables) {
   }
 
   // now add in the subject relationships
-  while ($relationship = db_fetch_object($as_subject)) {
+  while ($relationship = $as_subject->fetchObject()) {
 
     // get the relationship and child types
     $rel_type = t(preg_replace('/_/', " ", $relationship->rel_type));
@@ -930,10 +922,11 @@ function tripal_pub_mail($key, &$message, $params) {
   }
 }
 
-/*
- *
+/**
+ * 
+ * @param $node
  */
-function tripal_pub_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
+function tripal_pub_node_insert($node) {
   // we want the publications to always have a URL of http://[base url]/pub/[pub id]
   // where [pub id] is the Chado publication ID.  This will allow for easy linking
   // into the publication without needing to know the node.  Of course if you know the
@@ -941,25 +934,42 @@ function tripal_pub_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
   // so the nodeapi function ensures that the URL path is set after insert or update
   // of the node and when the node is loaded if it hasn't yet been set.
   if ($node->type == 'chado_pub') {
-    switch ($op) {
-      case 'presave':
-        break;
-      case 'insert':
-        $pub_id = chado_get_id_for_node('pub', $node->nid);
-        tripal_pub_set_pub_url($node, $pub_id);
-        break;
-      case 'load':
-        if (!$node->path) {
-          $pub_id = chado_get_id_for_node('pub', $node->nid);
-          $path = tripal_pub_set_pub_url($node, $pub_id);
-        }
-        break;
-      case 'update':
-        $pub_id = chado_get_id_for_node('pub', $node->nid);
-        tripal_pub_set_pub_url($node, $pub_id);
-        break;
-      case 'view':
-        break;
+    $pub_id = chado_get_id_for_node('pub', $node->nid);
+    tripal_pub_set_pub_url($node, $pub_id);
+  }
+}
+/**
+ * 
+ * @param $node
+ * @param $types
+ */
+function tripal_pub_node_load($node, $types) {
+  // we want the publications to always have a URL of http://[base url]/pub/[pub id]
+  // where [pub id] is the Chado publication ID.  This will allow for easy linking
+  // into the publication without needing to know the node.  Of course if you know the
+  // node that will still work too (e.g. http://[base url]/node/[node id]
+  // so the nodeapi function ensures that the URL path is set after insert or update
+  // of the node and when the node is loaded if it hasn't yet been set.
+  if ($node->type == 'chado_pub') {
+    if (!$node->path) {
+      $pub_id = chado_get_id_for_node('pub', $node->nid);
+      $path = tripal_pub_set_pub_url($node, $pub_id);
     }
   }
 }
+/**
+ *
+ * @param $node
+ */
+function tripal_pub_node_update($node) {
+  // we want the publications to always have a URL of http://[base url]/pub/[pub id]
+  // where [pub id] is the Chado publication ID.  This will allow for easy linking
+  // into the publication without needing to know the node.  Of course if you know the
+  // node that will still work too (e.g. http://[base url]/node/[node id]
+  // so the nodeapi function ensures that the URL path is set after insert or update
+  // of the node and when the node is loaded if it hasn't yet been set.
+  if ($node->type == 'chado_pub') {  
+    $pub_id = chado_get_id_for_node('pub', $node->nid);
+    tripal_pub_set_pub_url($node, $pub_id);
+  }
+}

+ 1 - 1
tripal_stock/includes/tripal_stock.admin.inc

@@ -187,7 +187,7 @@ function get_tripal_stock_admin_form_vocabulary_set(&$form) {
   $sql = "SELECT * FROM {cv} ORDER BY name";
   $results = chado_query($sql);
   $cv_options = array();
-  while ($r = db_fetch_object($results)) {
+  while ($r = $results->fetchObject()) {
     $cv_options[$r->cv_id] = $r->name;
   }