$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()) { // Get the CV term details and add it to the tripal_entity_type table if // it doesn't already exist. $cvterm = chado_generate_var('cvterm', array('cvterm_id' => $cvterm_id)); // First add a record to the tripal_entity_type table. $values = array( 'cv_id' => $cvterm->cv_id->cv_id, 'db_id' => $cvterm->dbxref_id->db_id->db_id, 'publish' => 0, ); $entity_type_id = 0; $entity_type = chado_select_record('tripal_entity_type', array('entity_type_id'), $values); if (count($entity_type) == 0) { $entity_type = chado_insert_record('tripal_entity_type', $values); $entity_type_id = $entity_type['entity_type_id']; } else { $entity_type_id = $entity_type[0]->entity_type_id; } // Next add a record to the tripal_entity_bundle table. $values = array( 'entity_type_id' => $entity_type_id, 'cvterm_id' => $cvterm_id, 'publish' => 0 ); $bundle_id = 0; $bundle = chado_select_record('tripal_entity_bundle', array('bundle_id'), $values); if (count($bundle) == 0) { $bundle = chado_insert_record('tripal_entity_bundle', $values); $bundle_id = $bundle['bundle_id']; } else { $bundle_id = $bundle[0]->bundle_id; } // Add the table where the records are found. $values = array( 'bundle_id' => $bundle_id, 'data_table' => $tablename, 'type_table' => $tablename, 'field' => $local_id ); if (!chado_select_record('tripal_entity_bundle_source', array('bundle_source_id'), $values, array('has_record' => TRUE))) { chado_insert_record('tripal_entity_bundle_source', $values); } // Add the table where the records are found. $values = array( 'entity_type_id' => $entity_type_id, 'data_table' => $tablename, 'type_table' => $tablename, 'field' => $local_id ); if (!chado_select_record('tripal_entity_type_source', array('entity_type_id'), $values, array('has_record' => TRUE))) { chado_insert_record('tripal_entity_type_source', $values); } } } } } catch (Exception $e) { print "\n"; // make sure we start errors on new line $transaction->rollback(); watchdog_exception('tripal_ws', $e); print "FAILED: Rolling back database changes...\n"; } print "\nDone.\n"; }