$remote_id) { // Get the list of cvterm_ids from existing records in the table. $sql = " SELECT $local_id FROM { " . $tablename . "} GROUP BY $local_id "; $results = chado_query($sql); while ($cvterm_id = $results->fetchField()) { tripal_chado_add_cvterm_mapping($cvterm_id, $tablename, $local_id); } } } } catch (Exception $e) { print "\n"; // make sure we start errors on new line $transaction->rollback(); watchdog_exception('tripal_chado', $e); print "FAILED: Rolling back database changes...\n"; } print "\nDone.\n"; } /* * Add a cvterm mapping record * * Check if the cvterm mapping record exists. If not, add it to the tripal_cvterm_mapping * table */ function tripal_chado_add_cvterm_mapping($cvterm_id, $tablename, $chado_field) { // check if the record exists $record = db_select('tripal_cvterm_mapping', 'tcm') ->fields('tcm', array('mapping_id')) ->condition('cvterm_id', $cvterm_id) ->execute() ->fetchField(); // insert records into the tripal_cvterm_mapping table. if (!$record) { db_insert('tripal_cvterm_mapping') ->fields( array( 'cvterm_id' => $cvterm_id, 'chado_table' => $tablename, 'chado_field' => $chado_field ) ) ->execute(); } // if the record exists, update the term mapping else { db_update('tripal_cvterm_mapping') ->fields( array( 'chado_table' => $tablename, 'chado_field' => $chado_field ) ) ->condition('cvterm_id', $cvterm_id) ->execute() ; } }