function tripal_project_sync_projects
1.x tripal_project.admin.inc | tripal_project_sync_projects($project_id = NULL, $job_id = NULL) |
Synchronize projects from chado to drupal
Related topics
1 string reference to 'tripal_project_sync_projects'
- tripal_project_admin_validate in tripal_project/
includes/ tripal_project.admin.inc
File
- tripal_project/
includes/ tripal_project.admin.inc, line 224 - @todo Add file header description
Code
function tripal_project_sync_projects($project_id = NULL, $job_id = NULL) {
global $user;
$page_content = '';
if (!$project_id) {
$sql = "SELECT * FROM {project} P";
$results = chado_query($sql);
}
else {
$sql = "SELECT * FROM {project} P WHERE project_id = %d";
$results = chado_query($sql, $project_id);
}
// We'll use the following SQL statement for checking if the project
// already exists as a drupal node.
$sql = "SELECT * FROM {chado_project} " .
"WHERE project_id = %d";
while ($project = db_fetch_object($results)) {
// check if this project already exists in the drupal database. if it
// does then skip this project and go to the next one.
if (!db_fetch_object(db_query($sql, $project->project_id))) {
$new_node = new stdClass();
$new_node->type = 'chado_project';
$new_node->uid = $user->uid;
$new_node->title = "$project->name";
$new_node->project_id = $project->project_id;
$new_node->name = $project->name;
$new_node->description = $project->description;
node_validate($new_node);
if (!form_get_errors()) {
$node = node_submit($new_node);
node_save($node);
if ($node->nid) {
print "Added $project->name\n";
}
}
else {
print "Failed to insert project $project->name\n";
}
}
else {
print "Skipped $project->name\n";
}
}
return $page_content;
}