tripal_pub.admin.inc 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * Administrative settings form
  4. *
  5. * @ingroup tripal_pub
  6. */
  7. function tripal_pub_admin() {
  8. $form = array();
  9. // before proceeding check to see if we have any
  10. // currently processing jobs. If so, we don't want
  11. // to give the opportunity to sync publications
  12. $active_jobs = FALSE;
  13. if (tripal_get_module_active_jobs('tripal_pub')) {
  14. $active_jobs = TRUE;
  15. }
  16. // add the field set for syncing publications
  17. if (!$active_jobs) {
  18. get_tripal_pub_admin_form_cleanup_set($form);
  19. }
  20. else {
  21. $form['notice'] = array(
  22. '#type' => 'fieldset',
  23. '#title' => t('Publication Management Temporarily Unavailable')
  24. );
  25. $form['notice']['message'] = array(
  26. '#value' => t('Currently, publication 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.'),
  27. );
  28. }
  29. return system_settings_form($form);
  30. }
  31. /**
  32. *
  33. *
  34. * @ingroup tripal_pub
  35. */
  36. function get_tripal_pub_admin_form_cleanup_set(&$form) {
  37. $form['cleanup'] = array(
  38. '#type' => 'fieldset',
  39. '#title' => t('Clean Up')
  40. );
  41. $form['cleanup']['description'] = array(
  42. '#type' => 'item',
  43. '#value' => t("With Drupal and chado residing in different databases ".
  44. "it is possible that nodes in Drupal and publications in Chado become ".
  45. "\"orphaned\". This can occur if an pub node in Drupal is ".
  46. "deleted but the corresponding chado pub is not and/or vice ".
  47. "versa. Click the button below to resolve these discrepancies."),
  48. '#weight' => 1,
  49. );
  50. $form['cleanup']['button'] = array(
  51. '#type' => 'submit',
  52. '#value' => t('Clean up orphaned publications'),
  53. '#weight' => 2,
  54. );
  55. }
  56. /**
  57. *
  58. * @ingroup tripal_pub
  59. */
  60. function tripal_pub_admin_validate($form, &$form_state) {
  61. global $user; // we need access to the user info
  62. $job_args = array();
  63. // -------------------------------------
  64. // Submit the Cleanup Job if selected
  65. if ($form_state['values']['op'] == t('Clean up orphaned publications')) {
  66. tripal_add_job('Cleanup orphaned publications', 'tripal_pub',
  67. 'tripal_pub_cleanup', $job_args, $user->uid);
  68. }
  69. }
  70. /**
  71. * Remove orphaned drupal nodes
  72. *
  73. * @param $dummy
  74. * Not Used -kept for backwards compatibility
  75. * @param $job_id
  76. * The id of the tripal job executing this function
  77. *
  78. * @ingroup tripal_pub
  79. */
  80. function tripal_pub_cleanup($dummy = NULL, $job_id = NULL) {
  81. return tripal_core_clean_orphaned_nodes('pub', $job_id);
  82. }