function tripal_project_sync_all_projects
1.x tripal_project.admin.inc | tripal_project_sync_all_projects() |
2 string references to 'tripal_project_sync_all_projects'
- 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_project_sync_projects_form_submit in tripal_project/
includes/ tripal_project.admin.inc
File
- tripal_project/
includes/ tripal_project.admin.inc, line 288 - @todo Add file header description
Code
function tripal_project_sync_all_projects() {
//retrieve all projects in drupal
$resource = db_query('SELECT project_id FROM {chado_project}');
$drupal_projects = array();
while ($r = db_fetch_object($resource)) {
$drupal_projects[$r->project_id] = $r->project_id;
}
// retrieve all projects in chado
$chado_projects = array();
$resource = chado_query('SELECT project_id FROM {project}');
while ($r = db_fetch_object($resource)) {
// if not already in drupal add to list to be sync'd
if (!isset($drupal_projects[$r->project_id])) {
$chado_projects[$r->project_id] = $r->project_id;
}
}
print 'Number of Projects to Sync: ' . sizeof($chado_projects) . "\n";
foreach ($chado_projects as $project_id) {
$project = tripal_core_chado_select('project', array('name', 'description'), array('project_id' => $project_id));
// create node
$new_node = new stdClass();
$new_node->type = 'chado_project';
$new_node->uid = $user->uid;
$new_node->title = $project[0]->name;
$new_node->project_id = $project_id;
$new_node->description = $project[0]->description;
node_validate($new_node);
$errors = form_get_errors();
if (!$errors) {
$node = node_submit($new_node);
node_save($node);
if ($node->nid) {
print "Added " . $project[0]->name . " (Node ID:" . $node->nid . ")\n";
}
}
else {
print "Failed to insert project: " . $project[0]->name . "\n";
print "Errors: " . print_r($errors, TRUE) . "\n";
}
}
}