function drush_tripal_phylogeny_trp_update_phylotree

2.x tripal_phylogeny.drush.inc drush_tripal_phylogeny_trp_update_phylotree()
3.x tripal_phylogeny.drush.inc drush_tripal_phylogeny_trp_update_phylotree()

File

tripal_phylogeny/tripal_phylogeny.drush.inc, line 161
Contains function relating to drush-integration of this module.

Code

function drush_tripal_phylogeny_trp_update_phylotree() {
  $username = drush_get_option('username');
  drush_tripal_core_set_user($username);

  $options = array(
    'phylotree_id' => drush_get_option('phylotree_id'),
    'name' => drush_get_option('name'),
    'description' => drush_get_option('description'),
    'analysis' => drush_get_option('analysis'),
    'leaf_type' => drush_get_option('leaf_type'),
    'tree_file' => drush_get_option('tree_file'),
    'format' => drush_get_option('format'),
    'dbxref' => drush_get_option('dbxref'),
    'sync' => drush_get_option('sync'),
    'match' => drush_get_option('match'),
    'name_re' => drush_get_option('name_re'),
    'load_now' => TRUE,
  );

  if (!$options['phylotree_id'] and $options['name']) {
    $phylotree = chado_select_record('phylotree', array('phylotree_id'), array('name' => $options['name']));
    if (count($phylotree) > 0) {
      $options['phylotree_id'] = $phylotree[0]->phylotree_id;
    }
    else {
      drush_print('A phylotree record with this name does not exists.');
    }
  }

  if ($options['phylotree_id'] and tripal_update_phylotree($options['phylotree_id'], $options)) {

    if ($options['sync']) {
      chado_node_sync_records('phylotree', FALSE, FALSE, 
      array(), $ids = array($options['phylotree_id']));
    }
    $nid = chado_get_nid_from_id('phylotree', $options['phylotree_id']);
    if ($nid) {
      if ($options['name_re']) {
        tripal_delete_node_variables($nid, 'phylotree_name_re');
        tripal_add_node_variable($nid, 'phylotree_name_re', $options['name_re']);
      }
      if ($options['match']) {
        tripal_delete_node_variables($nid, 'phylotree_use_uniquename');
        tripal_add_node_variable($nid, 'phylotree_use_uniquename', $options['match']);
      }
      if ($options['tree_file']) {
        tripal_delete_node_variables($nid, 'phylotree_tree_file');
        tripal_add_node_variable($nid, 'phylotree_tree_file', basename($options['tree_file']));
      }
    }
  }
  drush_print("Done.");
}