tripal_analysis.delete.inc

  1. 2.x tripal_analysis/includes/tripal_analysis.delete.inc
  2. 3.x legacy/tripal_analysis/includes/tripal_analysis.delete.inc
  • Administration Interface for deleting multiple analyses

File

tripal_analysis/includes/tripal_analysis.delete.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Administration Interface for deleting multiple analyses
  5. */
  6. /**
  7. * A form for indicating the analyses to delete
  8. *
  9. * @ingroup tripal_analysis
  10. */
  11. function tripal_analysis_delete_form() {
  12. // get the list of analyses
  13. $sql = "SELECT * FROM {analysis} ORDER BY name";
  14. $org_rset = chado_query($sql);
  15. $analyses = array();
  16. while ($analysis = $org_rset->fetchObject()) {
  17. $analyses[$analysis->analysis_id] = "$analysis->name";
  18. }
  19. $form['desc'] = array(
  20. '#markup' => t("Use the following form to delete analyses which may or may
  21. not be synced. Please be cautious. Deleting an analysis will cause all
  22. data associated with the analysis to also be deleted."),
  23. );
  24. $form['analyses'] = array(
  25. '#title' => t('analysis'),
  26. '#type' => 'checkboxes',
  27. '#options' => $analyses,
  28. '#prefix' => '<div style="height: 400px; overflow: scroll">',
  29. '#suffix' => '</div><br>',
  30. );
  31. $form['button'] = array(
  32. '#type' => 'submit',
  33. '#value' => t('Delete analyses'),
  34. );
  35. return $form;
  36. }
  37. /**
  38. * Submit for the delete features form
  39. *
  40. * @ingroup tripal_analysis
  41. */
  42. function tripal_analysis_delete_form_submit($form, &$form_state) {
  43. global $user;
  44. // Convert the analyses input into an array of just ids.
  45. $analyses = $form_state['values']['analyses'];
  46. $org_ids = array();
  47. foreach ($analyses as $id => $val) {
  48. if ($val != 0) {
  49. $org_ids[] = $id;
  50. }
  51. }
  52. if (count($org_ids) > 0) {
  53. $args = array($org_ids);
  54. tripal_add_job("Delete analysis", 'tripal_analysis',
  55. 'tripal_analysis_delete_analyses', $args, $user->uid);
  56. drupal_set_message(t("analyses will disappear from the list below once the job completes."));
  57. }
  58. else {
  59. drupal_set_message(t("Please select at least one analysis to delete."), "error");
  60. }
  61. }
  62. /**
  63. * Function to actually delete the features indicated
  64. *
  65. * @param $analysis_id
  66. * The list of analysis_id of the features to delete
  67. * @param $job
  68. * The tripal_job id
  69. *
  70. * @ingroup tripal_analysis
  71. */
  72. function tripal_analysis_delete_analyses($analyses, $job = NULL) {
  73. global $user;
  74. // Deleting of analyses will cause a cascade delete on the
  75. // fassociated tables which may include the fatureloc table. The create_point
  76. // function which is not prefix with the schema, and an error occurs.
  77. // Therefore, we set the active database to chado to get around that
  78. // problem.
  79. // $previous_db = chado_set_active('chado');
  80. // begin the transaction
  81. $transaction = db_transaction();
  82. print "\nNOTE: Deleting analyses is performed using a database transaction. \n" .
  83. "If the load fails or is terminated prematurely then the entire set of \n" .
  84. "deletions is rolled back and will not be found in the database\n\n";
  85. try {
  86. $values = array(
  87. 'analysis_id' => $analyses
  88. );
  89. $num_deletes = chado_select_record('analysis', array('count(*) as cnt'), $values);
  90. print "Deleting " . $num_deletes[0]->cnt . " analyses\n";
  91. chado_delete_record('analysis', $values);
  92. print "Removing orphaned analysis pages\n";
  93. chado_cleanup_orphaned_nodes('analysis');
  94. }
  95. catch (Exception $e) {
  96. print "\n"; // make sure we start errors on new line
  97. $transaction->rollback();
  98. print "FAILED: Rolling back database changes...\n";
  99. watchdog_exception('tripal_analysis', $e);
  100. return 0;
  101. }
  102. // chado_set_active($previous_db);
  103. print "\nDone\n";
  104. }