function tripal_library_sync_libraries
1.x tripal_library.admin.inc | tripal_library_sync_libraries($library_id = NULL, $job_id = NULL) |
Related topics
3 string references to 'tripal_library_sync_libraries'
- drush_tripal_core_tripal_node_sync in tripal_core/
tripal_core.drush.inc - Sync's chado records with drupal creating nodes for the given chado-centric module.
- tripal_library_admin_validate in tripal_library/
includes/ tripal_library.admin.inc - tripal_library_menu in tripal_library/
tripal_library.module - Menu items are automatically added for the new node types created by this module to the 'Create Content' Navigation menu item. This function adds more menu items needed for this module.
File
- tripal_library/
includes/ tripal_library.admin.inc, line 359
Code
function tripal_library_sync_libraries($library_id = NULL, $job_id = NULL) {
global $user;
$page_content = '';
// get the list of libraries and create new nodes
if (!$library_id) {
$sql = "SELECT * FROM {Library} L";
$results = chado_query($sql);
}
else {
$sql = "SELECT * FROM {Library} L WHERE library_id = %d";
$results = chado_query($sql, $library_id);
}
// We'll use the following SQL statement for checking if the library
// already exists as a drupal node.
$sql = "SELECT * FROM {chado_library} " .
"WHERE library_id = %d";
while ($library = db_fetch_object($results)) {
// check if this library already exists in the drupal database. if it
// does then skip this library and go to the next one.
if (!db_fetch_object(db_query($sql, $library->library_id))) {
$new_node = new stdClass();
$new_node->type = 'chado_library';
$new_node->uid = $user->uid;
$new_node->title = "$library->name";
$new_node->library_id = $library->library_id;
$new_node->organism_id = $library->organism_id;
$new_node->uniquename = $library->uniquename;
$new_node->type_id = $library->type_id;
node_validate($new_node);
$errors = form_get_errors();
if (!$errors) {
$node = node_submit($new_node);
node_save($node);
if ($node->nid) {
print "Added " . $library->name . "\n";
}
else {
print "ERROR: Unable to create " . $library->name . "\n";
}
}
else {
print "ERROR: Unable to create " . $library->name . "\n" . print_r($errors, TRUE) . "\n";
}
}
else {
print "Skipped " . $library->name . "\n";
}
}
return $page_content;
}