tripal_jbrowse_mgmt.jobs.inc 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * Create first set of files for the instance.
  4. * This simply means preparing the reference sequence.
  5. *
  6. * @param $instance_id
  7. *
  8. * @throws \Exception
  9. */
  10. function tripal_jbrowse_mgmt_create_instance_files($instance_id) {
  11. $instance = tripal_jbrowse_mgmt_get_instance($instance_id);
  12. if (empty($instance)) {
  13. throw new Exception('Unable to find instance to create files for.');
  14. }
  15. $exit = tripal_jbrowse_mgmt_cmd_prepare_refseq($instance);
  16. if ($exit == 0) {
  17. if (tripal_jbrowse_mgmt_cmd_generate_names($instance) != 0) {
  18. throw new Exception(
  19. 'Unable to generate names for the instance. See above for errors.'
  20. );
  21. }
  22. return;
  23. }
  24. throw new Exception(
  25. 'Unable to prepare reference sequence for the instance. See above for
  26. errors.'
  27. );
  28. }
  29. /**
  30. * Job to create a new instance.
  31. *
  32. * @param $track_id
  33. *
  34. * @throws \Exception
  35. */
  36. function tripal_jbrowse_mgmt_add_track_to_instance($track_id) {
  37. $track = tripal_jbrowse_mgmt_get_track($track_id);
  38. if (empty($track)) {
  39. throw new Exception('Unable to find instance to create files for.');
  40. }
  41. if (tripal_jbrowse_mgmt_cmd_add_track($track) != 0) {
  42. throw new Exception('Unable to add track. See errors above.');
  43. }
  44. }
  45. /**
  46. * Job to delete a track from an instance.
  47. *
  48. * @param $track_id
  49. *
  50. * @throws \Exception
  51. */
  52. function tripal_jbrowse_mgmt_delete_track_from_instance($track_id)
  53. {
  54. $track = tripal_jbrowse_mgmt_get_track($track_id);
  55. if (empty($track)) {
  56. throw new Exception('Unable to find instance to create files for.');
  57. }
  58. if (tripal_jbrowse_mgmt_cmd_delete_track($track) != 0) {
  59. tripal_jbrowse_mgmt_update_track($track, ['is_deleted' => 0]);
  60. throw new Exception('Unable to add track. See errors above.');
  61. }
  62. tripal_jbrowse_mgmt_delete_track($track_id);
  63. }