function tripal_featuremap_sync_featuremaps

1.x tripal_featuremap.admin.inc tripal_featuremap_sync_featuremaps($featuremap_id = NULL, $job_id = NULL)

Related topics

3 string references to 'tripal_featuremap_sync_featuremaps'
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_featuremap_admin_validate in tripal_featuremap/includes/tripal_featuremap.admin.inc
tripal_featuremap_menu in tripal_featuremap/tripal_featuremap.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_featuremap/includes/tripal_featuremap.admin.inc, line 303

Code

function tripal_featuremap_sync_featuremaps($featuremap_id = NULL, $job_id = NULL) {

  global $user;
  $page_content = '';

  // get the list of featuremaps and create new nodes
  if (!$featuremap_id) {
    $sql = "SELECT * FROM {featuremap} L";
    $results = chado_query($sql);
  }
  else {
    $sql = "SELECT * FROM {featuremap} L WHERE featuremap_id = %d";
    $results = chado_query($sql, $featuremap_id);
  }

  // We'll use the following SQL statement for checking if the map
  // already exists as a drupal node.
  $sql = "SELECT * FROM {chado_featuremap} " .
    "WHERE featuremap_id = %d";

  while ($featuremap = db_fetch_object($results)) {

    // check if this map already exists in the drupal database. if it
    // does then skip this map and go to the next one.
    if (!db_fetch_object(db_query($sql, $featuremap->featuremap_id))) {

      $new_node = new stdClass();
      $new_node->type = 'chado_featuremap';
      $new_node->uid = $user->uid;
      $new_node->title = "$featuremap->name";
      $new_node->featuremap_id = $featuremap->featuremap_id;

      node_validate($new_node);
      $errors = form_get_errors();
      if (!$errors) {
        $node = node_submit($new_node);
        node_save($node);
        if ($node->nid) {
          print "Added " . $featuremap->name . "\n";
        }
        else {
          print "ERROR: Unable to create " . $featuremap->name . "\n";
        }
      }
      else {
        print "ERROR: Unable to create " . $featuremap->name . "\n" . print_r($errors, TRUE) . "\n";
      }
    }
    else {
      print "Skipped " . $featuremap->name . "\n";
    }
  }
  return $page_content;
}