Jelajahi Sumber

Moved feature module to chado modules menu item

Stephen Ficklin 11 tahun lalu
induk
melakukan
4016020a94

+ 6 - 6
tripal_feature/tripal_feature.module

@@ -198,7 +198,7 @@ function tripal_feature_menu() {
   );
   
   // the administative settings menu
-  $items['admin/tripal/tripal_feature'] = array(
+  $items['admin/tripal/chado/tripal_feature'] = array(
     'title' => 'Features',
     'description' => 'Basic Description of Tripal Organism Module Functionality',
     'page callback' => 'theme',
@@ -206,7 +206,7 @@ function tripal_feature_menu() {
     'access arguments' => array('administer tripal features'),
     'type' => MENU_NORMAL_ITEM,
   );
-  $items['admin/tripal/tripal_feature/configuration'] = array(
+  $items['admin/tripal/chado/tripal_feature/configuration'] = array(
     'title' => 'Configuration',
     'description' => 'Configure the Tripal Feature module.',
     'page callback' => 'drupal_get_form',
@@ -214,7 +214,7 @@ function tripal_feature_menu() {
     'access arguments' => array('administer tripal features'),
     'type' => MENU_NORMAL_ITEM,
   );
-  $items['admin/tripal/tripal_feature/fasta_loader'] = array(
+  $items['admin/tripal/chado/tripal_feature/fasta_loader'] = array(
     'title' => 'Import a multi-FASTA file',
     'description' => 'Load sequences from a multi-FASTA file into Chado',
     'page callback' => 'drupal_get_form',
@@ -222,7 +222,7 @@ function tripal_feature_menu() {
     'access arguments' => array('administer tripal features'),
     'type' => MENU_NORMAL_ITEM,
   );
-  $items['admin/tripal/tripal_feature/gff3_load'] = array(
+  $items['admin/tripal/chado/tripal_feature/gff3_load'] = array(
     'title' => 'Import a GFF3 file',
     'description' => 'Import a GFF3 file into Chado',
     'page callback' => 'drupal_get_form',
@@ -231,7 +231,7 @@ function tripal_feature_menu() {
     'type' => MENU_NORMAL_ITEM,
   );
 
-  $items['admin/tripal/tripal_feature/delete'] = array(
+  $items['admin/tripal/chado/tripal_feature/delete'] = array(
     'title' => ' Delete Features',
     'description' => 'Delete multiple features from Chado',
     'page callback' => 'drupal_get_form',
@@ -240,7 +240,7 @@ function tripal_feature_menu() {
     'type' => MENU_NORMAL_ITEM,
   );
 
-  $items['admin/tripal/tripal_feature/sync'] = array(
+  $items['admin/tripal/chado/tripal_feature/sync'] = array(
     'title' => ' Sync Features',
     'description' => 'Sync features from Chado with Drupal',
     'page callback' => 'drupal_get_form',

+ 3 - 233
tripal_organism/includes/tripal_organism.admin.inc

@@ -9,58 +9,12 @@ function tripal_organism_admin() {
 
   $form = array();
 
-  // before proceeding check to see if we have any
-  // currently processing jobs. If so, we don't want
-  // to give the opportunity to sync libraries
-  $active_jobs = FALSE;
-  if (tripal_get_module_active_jobs('tripal_organism')) {
-    $active_jobs = TRUE;
-  }
-
-  // add the field set for syncing libraries
-  if (!$active_jobs) {
-    get_tripal_organism_admin_form_sync_set($form);
-    get_tripal_organism_admin_form_reindex_set($form);
-    get_tripal_organism_admin_form_taxonomy_set($form);
-    get_tripal_organism_admin_form_cleanup_set($form);
-  }
-  else {
-    $form['notice'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Organism Management Temporarily Unavailable')
-    );
-    $form['notice']['message'] = array(
-      '#value' => t('Currently, organism management jobs are waiting or are running. . Managemment features have been hidden until these jobs complete.  Please check back later once these jobs have finished.  You can view the status of pending jobs in the Tripal jobs page.'),
-    );
-  }
+  get_tripal_organism_admin_form_reindex_set($form);
+  get_tripal_organism_admin_form_taxonomy_set($form);  
 
   return system_settings_form($form);
 }
-/**
- *
- *
- * @ingroup tripal_organism
- */
-function get_tripal_organism_admin_form_cleanup_set(&$form) {
-  $form['cleanup'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Clean Up')
-  );
-  $form['cleanup']['description'] = array(
-    '#type' => 'item',
-    '#value' => t("With Drupal and chado residing in different databases " .
-    "it is possible that nodes in Drupal and organisms in Chado become " .
-    "\"orphaned\".  This can occur if an organism node in Drupal is " .
-    "deleted but the corresponding chado organism is not and/or vice " .
-    "versa. Click the button below to resolve these discrepancies."),
-    '#weight' => 1,
-  );
-  $form['cleanup']['button'] = array(
-    '#type' => 'submit',
-    '#value' => t('Clean up orphaned organisms'),
-    '#weight' => 2,
-  );
-}
+
 /**
  *
  *
@@ -150,80 +104,7 @@ function get_tripal_organism_admin_form_reindex_set(&$form) {
     '#weight' => 3,
   );
 }
-/**
- *
- * @ingroup tripal_organism
- */
-function get_tripal_organism_admin_form_sync_set(&$form) {
-  // define the fieldsets
-  $form['sync'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Sync Organisms')
-  );
-
-  // before proceeding check to see if we have any
-  // currently processing jobs. If so, we don't want
-  // to give the opportunity to sync libraries
-  $active_jobs = FALSE;
-  if (tripal_get_module_active_jobs('tripal_organism')) {
-    $active_jobs = TRUE;
-  }
-
-  if (!$active_jobs) {
-
-    // get the list of organisms
-    $sql = "SELECT * FROM {Organism} ORDER BY genus,species";
-    $org_rset = chado_query($sql);
 
-    // if we've added any organisms to the list that can be synced
-    // then we want to build the form components to allow the user
-    // to select one or all of them.  Otherwise, just present
-    // a message stating that all organisms are currently synced.
-    $org_boxes = array();
-    $added = 0;
-    foreach ($org_rset as $organism) {
-      // check to see if the organism is already present as a node in drupal.
-      // if so, then skip it.
-      $sql = "SELECT * FROM {chado_organism} WHERE organism_id = :organism_id";
-      if (!db_query($sql, array(':organism_id' => $organism->organism_id))->fetchObject()) {
-        $org_boxes[$organism->organism_id] = "$organism->genus $organism->species ($organism->common_name)";
-        $added++;
-      }
-    }
-
-    // if we have organisms we need to add to the checkbox then
-    // build that form element
-    if ($added > 0) {
-      $org_boxes['all'] = "All Organisms";
-
-      $form['sync']['organisms'] = array(
-        '#title'       => t('Available Organisms'),
-        '#type'        => t('checkboxes'),
-        '#description' => t("Check the organisms you want to sync.  Drupal content will be created for each of the organisms listed above.  Select 'All Organisms' to sync all of them."),
-        '#required'    => FALSE,
-        '#prefix'      => '<div id="org_boxes">',
-        '#suffix'      => '</div>',
-        '#options'     => $org_boxes,
-      );
-      $form['sync']['button'] = array(
-        '#type' => 'submit',
-        '#value' => t('Submit Sync Job')
-      );
-    }
-    // we don't have any organisms to select from
-    else {
-    $form['sync']['value'] = array(
-        '#value' => t('All organisms in Chado are currently synced with Drupal.')
-    );
-    }
-  }
-  // we don't want to present a form since we have an active job running
-  else {
-    $form['sync']['value'] = array(
-        '#value' => t('Currently, jobs exist related to chado organisms. Please check back later for organisms that can by synced once these jobs have finished.  You can view the status of pending jobs in the Tripal jobs page.')
-    );
-  }
-}
 /**
  *
  * @ingroup tripal_organism
@@ -232,40 +113,6 @@ function tripal_organism_admin_validate($form, &$form_state) {
   global $user;  // we need access to the user info
   $job_args = array();
 
-  if ($form_state['values']['op'] == t('Submit Sync Job')) {
-
-    // check to see if the user wants to sync chado and drupal.  If
-    // so then we need to register a job to do so with tripal
-    $organisms = $form_state['values']['organisms'];
-    $do_all = FALSE;
-    $to_sync = array();
-
-    foreach ($organisms as $organism_id) {
-      if (preg_match("/^all$/i" , $organism_id)) {
-        $do_all = TRUE;
-      }
-      if ($organism_id and preg_match("/^\d+$/i" , $organism_id)) {
-        // get the list of organisms
-        $sql = "SELECT * FROM {organism} WHERE organism_id = :organism_id";
-        $organism = chado_query($sql, array(':organism_id' => $organism_id))->fetchObject();
-        $to_sync[$organism_id] = "$organism->genus $organism->species";
-      }
-    }
-
-    // submit the job the tripal job manager
-    if ($do_all) {
-      tripal_add_job('Sync all organisms' , 'tripal_organism',
-      'tripal_organism_sync_organisms' , $job_args , $user->uid);
-    }
-    else{
-      foreach ($to_sync as $organism_id => $name) {
-        $job_args[0] = $organism_id;
-        tripal_add_job("Sync organism: $name" , 'tripal_organism',
-          'tripal_organism_sync_organisms' , $job_args , $user->uid);
-      }
-    }
-  }
-
   // -------------------------------------
   // Submit the Reindex Job if selected
   if ($form_state['values']['op'] == t('Reindex Features')) {
@@ -299,72 +146,9 @@ function tripal_organism_admin_validate($form, &$form_state) {
       }
     }
   }
-
-  // -------------------------------------
-  // Submit the Cleanup Job if selected
-  if ($form_state['values']['op'] == t('Clean up orphaned organisms')) {
-    tripal_add_job('Cleanup orphaned organisms', 'tripal_organism',
-      'tripal_organism_cleanup', $job_args, $user->uid);
-  }
 }
 
-/**
- * Synchronize organisms from chado to drupal
- *
- * @ingroup tripal_organism
- */
-function tripal_organism_sync_organisms($organism_id = NULL, $job_id = NULL) {
-  global $user;
-  $page_content = '';
-
-  if (!$organism_id) {
-    $sql = "SELECT * FROM {Organism} O";
-    $results = chado_query($sql);
-  }
-  else {
-    $sql = "SELECT * FROM {organism} WHERE organism_id = :organism_id";
-    $results = chado_query($sql, array(':organism_id' => $organism_id));
-  }
 
-  // We'll use the following SQL statement for checking if the organism
-  // already exists as a drupal node.
-  $sql = "SELECT * FROM {chado_organism} " .
-         "WHERE organism_id = :organism_id";
-
-  foreach ($results as $organism) {
-
-    // check if this organism already exists in the drupal database. if it
-    // does then skip this organism and go to the next one.
-    if (!db_query($sql, array(':organism_id' => $organism->organism_id))->fetchObject()) {
-
-      $new_node = new stdClass();
-      $new_node->type = 'chado_organism';
-      $new_node->uid = $user->uid;
-      $new_node->title = "$organism->genus $organism->species";
-      $new_node->organism_id = $organism->organism_id;
-      $new_node->genus = $organism->genus;
-      $new_node->species = $organism->species;
-      $new_node->description = '';
-      $form = array(); // dummy variable
-      $form_state = array(); // dummy variable
-      node_validate($new_node, $form, $form_state);
-      if (!form_get_errors()) {
-        $node = node_submit($new_node);
-        node_save($node);
-        if ($node->nid) {
-          print "Added $organism->common_name\n";
-        }
-      }
-      else {
-        print "Failed to insert organism $organism->common_name\n";
-      }
-    }
-    else {
-      print "Skipped $organism->common_name\n";
-    }
-  }
-  return $page_content;
-}
 /**
  *
  * @ingroup tripal_organism
@@ -447,17 +231,3 @@ function tripal_organism_taxonify_features($organism_id = NULL, $job_id = NULL)
     $i++;
   }
 }
-/**
- * Remove orphaned drupal nodes
- *
- * @param $dummy
- *   Not Used -kept for backwards compatibility
- * @param $job_id
- *   The id of the tripal job executing this function
- *
- * @ingroup tripal_organism
- */
-function tripal_organism_cleanup($dummy = NULL, $job_id = NULL) {
-
-  return tripal_core_clean_orphaned_nodes('organism', $job_id);
-}

+ 0 - 0
tripal_organism/theme/tripal_organism_admin.tpl.php → tripal_organism/theme/tripal_organism_help.tpl.php


+ 10 - 1
tripal_organism/tripal_organism.module

@@ -2,6 +2,7 @@
 
 require_once "api/tripal_organism.api.inc";
 require_once "includes/tripal_organism.admin.inc";
+require_once "includes/organism_sync.inc";
 
 /**
  * @file
@@ -117,11 +118,19 @@ function tripal_organism_menu() {
    'title' => 'Configuration',
    'description' => 'Manage integration of Chado organisms including associated features',
    'page callback' => 'drupal_get_form',
-   'page arguments' => array('tripal_organism_help'),
+   'page arguments' => array('tripal_organism_admin'),
    'access arguments' => array('adminster tripal organism'),
    'type' => MENU_NORMAL_ITEM,
   );
 
+  $items['admin/tripal/chado/tripal_organism/sync'] = array(
+    'title' => 'Sync Organisms',
+    'description' => 'Sync Chado organisms with Drupal',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_organism_sync'),
+    'access arguments' => array('adminster tripal organism'),
+    'type' => MENU_NORMAL_ITEM,
+  );
 
   return $items;
 }