Parcourir la source

Added function to stocks admin configuration for cleaning up orphaned stocks

spficklin il y a 12 ans
Parent
commit
fe13e2e1d6

+ 2 - 2
tripal_core/tripal_core.install

@@ -28,7 +28,7 @@ function tripal_core_install() {
 }
 
 /**
- *  Update for Drupal 6.x, Tripal 0.4
+ *  Update for Drupal 6.x, Tripal 1.0
  *  This update
  *   - adjusts the materialized view by adding status, comment and mv_schema columns
  *   - changes the specs of mv_table, mv_specs and indexed
@@ -37,7 +37,7 @@ function tripal_core_install() {
  * @ingroup tripal_feature
  */
 function tripal_core_update_6000() {
-  // add additional columsn to the tripal_mviews table
+  // add additional columns to the tripal_mviews table
   db_add_field($ret, 'tripal_mviews', 'status', array('type' => 'text', 'size' => 'normal', 'not NULL' => FALSE));
   db_add_field($ret, 'tripal_mviews', 'comment', array('type' => 'text', 'size' => 'normal', 'not NULL' => FALSE));
   db_add_field($ret, 'tripal_mviews', 'mv_schema', array('type' => 'text', 'size' => 'normal', 'not NULL' => FALSE));

+ 0 - 1
tripal_library/tripal_library.module

@@ -281,7 +281,6 @@ function tripal_library_admin() {
   // add the field set for syncing libraries
   if (!$active_jobs) {
     get_tripal_library_admin_form_sync_set($form);
-    get_tripal_library_admin_form_cleanup_set($form);
     get_tripal_library_admin_form_reindex_set($form);
     get_tripal_library_admin_form_taxonomy_set($form);
     get_tripal_library_admin_form_cleanup_set($form);

+ 67 - 22
tripal_stock/includes/tripal_stock-administration.inc

@@ -156,20 +156,17 @@ function tripal_stock_admin() {
     $active_jobs = TRUE;
   }
   if ($active_jobs) {
-
-  $form['notice'] = array(
+    $form['notice'] = array(
        '#type' => 'fieldset',
        '#title' => t('Stock Management Temporarily Unavailable')
     );
-
-  $form['notice']['message'] = array(
+    $form['notice']['message'] = array(
        '#value' => t("Currently, stock 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."),
     );
-
   }
   else {
 
@@ -245,6 +242,7 @@ function tripal_stock_admin() {
       '#type' => 'submit',
       '#value' => t('Sync Stocks')
     );
+    get_tripal_stock_admin_form_cleanup_set($form);
   }
 
   return system_settings_form($form);
@@ -287,6 +285,12 @@ function tripal_stock_admin_validate($form, &$form_state) {
     variable_set('chado_stock_prop_types_cv', $form_state['values']['stock_prop_types_cv']);
     variable_set('chado_stock_relationship_cv', $form_state['values']['stock_relationship_cv']);
   }
+  
+  // Submit the Cleanup Job if selected
+  if ($form_state['values']['op'] == t('Clean up orphaned stocks')) {
+    tripal_add_job('Cleanup orphaned stocks', 'tripal_stock',
+       'tripal_stock_cleanup', $job_args, $user->uid);
+  }
 }
 
 /**
@@ -365,31 +369,72 @@ function tripal_stock_sync_stock_set($organism_id, $job_id) {
              $node->vid
            );
            */
+          }
+        }
+        else {
+          print "Not completed due to errors:\nCreate Stock Form Errors: ";
+          print_r(form_get_errors());
         }
+        print "Nid=" . $node->nid . "\n";
       }
       else {
-        print "Not completed due to errors:\nCreate Stock Form Errors: ";
-        print_r(form_get_errors());
-      }
-        print "Nid=" . $node->nid . "\n";
-    }
-    else {
-      print "Skipped $r->uniquename because it's already in drupal.\n";
-    } //end of if not already in drupal
-  } //end of while still stocks to be sync'd
+        print "Skipped $r->uniquename because it's already in drupal.\n";
+      } //end of if not already in drupal
+    } //end of while still stocks to be sync'd
   } //end of if organism_id not supplied
 
   if ($stocks_attempted == 0) {
-  print "No stocks retrieved for organism (" . $organism_id . ")\n";
-  return 1;
-  }
-  else {
-  if ($stocks_created_count > 0) {
-    print "$stocks_created_count Stocks Successfully Created\n";
+    print "No stocks retrieved for organism (" . $organism_id . ")\n";
     return 1;
   }
   else {
-    return 0;
-  }
+    if ($stocks_created_count > 0) {
+      print "$stocks_created_count Stocks Successfully Created\n";
+      return 1;
+    }
+    else {
+      return 0;
+    }
   }
 }
+
+/**
+ *
+ *
+ * @ingroup tripal_stock
+ */
+function get_tripal_stock_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 stocks in Chado become ".
+        "\"orphaned\".  This can occur if an stock node in Drupal is ".
+        "deleted but the corresponding chado stock 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 stocks'),
+    '#weight' => 2,
+  );
+}
+/**
+ * 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_stock
+ */
+function tripal_stock_cleanup($dummy = NULL, $job_id = NULL) {
+
+  return tripal_core_clean_orphaned_nodes('stock', $job_id);
+  
+}