tripal_bulk_loader.admin.inc 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. /**
  3. * @file
  4. * Bulk Loader Administration (Miscellaneous)
  5. *
  6. * @ingroup tripal_bulk_loader
  7. */
  8. /**
  9. * Landing page for bulk loader admin. Ensures views are enabled and if not
  10. * provides links to do so.
  11. *
  12. * @ingroup tripal_bulk_loader
  13. */
  14. function tripal_bulk_loader_admin_jobs_listing() {
  15. $output = '';
  16. // set the breadcrumb
  17. $breadcrumb = [];
  18. $breadcrumb[] = l('Home', '<front>');
  19. $breadcrumb[] = l('Administration', 'admin');
  20. $breadcrumb[] = l('Tripal', 'admin/tripal');
  21. $breadcrumb[] = l('Chado Data Loaders', 'admin/tripal/loaders');
  22. $breadcrumb[] = l('Bulk Loader', 'admin/tripal/loaders/bulk');
  23. drupal_set_breadcrumb($breadcrumb);
  24. // Add the view
  25. $jobs_view = views_embed_view('tripal_bulk_loading_jobs', 'default');
  26. $template_view = views_embed_view('tripal_bulk_loader_templates', 'default');
  27. if (isset($jobs_view) && isset($template_view)) {
  28. $output .= $jobs_view;
  29. }
  30. else {
  31. $output .= '<p>The Tripal Bulk Loader uses primarily views to provide an '
  32. . 'administrative interface. Currently one or more views needed for this '
  33. . 'administrative interface are disabled. <strong>Click each of the following links to '
  34. . 'enable the pertinent views</strong>:</p>';
  35. $output .= '<ul>';
  36. if (!isset($jobs_view)) {
  37. $output .= '<li>' . l('Tripal Bulk Loading Jobs', 'admin/tripal/loaders/bulk/views/jobs/enable') . '</li>';
  38. }
  39. if (!isset($template_view)) {
  40. $output .= '<li>' . l('Tripal Bulk Loader Templates', 'admin/tripal/loaders/bulk/views/templates/enable') . '</li>';
  41. }
  42. $output .= '</ul>';
  43. }
  44. return $output;
  45. }
  46. /**
  47. * @section
  48. * Configuration Form
  49. */
  50. /**
  51. * A Configuration form for this module
  52. *
  53. * @ingroup tripal_bulk_loader
  54. */
  55. function tripal_bulk_loader_configuration_form($form_state = NULL) {
  56. $form = [];
  57. $form['space'] = [
  58. '#type' => 'fieldset',
  59. '#title' => t('Enable/Disable Functionality'),
  60. ];
  61. $form['space']['keep_track_inserted'] = [
  62. '#type' => 'checkbox',
  63. '#title' => t('Keep track of inserted record IDs'),
  64. '#description' => t('This enables the ability to revert an entire loading job even if '
  65. . 'it completed successfully. Furthermore, it displays the number of records '
  66. . 'successfully inserted into each table.'),
  67. '#default_value' => variable_get('tripal_bulk_loader_keep_track_inserted', FALSE),
  68. ];
  69. $form['speed'] = [
  70. '#type' => 'fieldset',
  71. '#title' => t('Possible Speed Improvements'),
  72. ];
  73. $form['speed']['prepare'] = [
  74. '#type' => 'checkbox',
  75. '#title' => t('Use Prepared Statements'),
  76. '#description' => t('SQL Prepared Statements allow for SQL queries which will be run '
  77. . 'many times to be parsed, rewritten and planned only once rather then every time '
  78. . 'the query is run. In the case of the bulk loader, this ensures that planning only '
  79. . 'occurs once for each "record" in your bulk loading template.'),
  80. '#default_value' => variable_get('tripal_bulk_loader_prepare', TRUE),
  81. ];
  82. $form['speed']['disable_triggers'] = [
  83. '#type' => 'checkbox',
  84. '#title' => t('Delay Constraint Checking during loading job.'),
  85. '#description' => t('This delays the constraint checking until the end of the
  86. loading proccess.'),
  87. '#default_value' => variable_get('tripal_bulk_loader_disable_triggers', TRUE),
  88. ];
  89. $form['speed']['no_validate'] = [
  90. '#type' => 'checkbox',
  91. '#title' => t('Skip Validation at the Tripal Core API level'),
  92. '#description' => t('If an error is encountered, the Tripal core API will try
  93. to provide informative error messages. With this turned off, you will not benifit
  94. from these more informative error messages; however, your job will load faster
  95. since it doesn\'t have to do the additional checking before inserting.'),
  96. '#default_value' => variable_get('tripal_bulk_loader_skip_validation', FALSE),
  97. ];
  98. $form['speed']['transactions'] = [
  99. '#type' => 'radios',
  100. '#title' => t('Transaction Rollback when an error is encountered'),
  101. '#options' => [
  102. 'all' => t('Rollback the last constant set.'
  103. . '<div class="description"If you added more then one constant set then the
  104. successfully loaded constant sets will not be rolled back. However, once an error
  105. is encountered no further constant sets will be loaded either.</div>'),
  106. 'row' => t('Only Rollback the last line of the input file.'
  107. . '<div class="description">This option may allow you to restart the job after
  108. fixing the error (manual intervention needed).</div>'),
  109. 'none' => t('Do not use transactions<div class="description">This is not recommended.</div>'),
  110. ],
  111. '#default_value' => variable_get('tripal_bulk_loader_transactions', 'row'),
  112. ];
  113. $form['speed']['lock'] = [
  114. '#type' => 'radios',
  115. '#title' => t('Lock Type'),
  116. '#description' => t('The type of lock used by the bulk loading jobs. The lock is '
  117. . 'acquired at the beginning of the job and kept till the end. A lock of the type '
  118. . 'selected will be acquired for every table being inserted into.'),
  119. '#options' => [
  120. 'ROW EXCLUSIVE' => t('ROW EXCLUSIVE: The default lock type for insert queries.'),
  121. 'EXCLUSIVE' => t('EXCLUSIVE: Only Select Queries can access the table.'),
  122. 'ACCESS EXCLUSIVE' => t('ACCESS EXCLUSIVE: No other queries can access the table.'),
  123. ],
  124. '#default_value' => variable_get('tripal_bulk_loader_lock', 'ROW EXCLUSIVE'),
  125. ];
  126. $form['submit1'] = [
  127. '#type' => 'submit',
  128. '#value' => t('Save'),
  129. ];
  130. return $form;
  131. }
  132. /**
  133. * A Configuration form for this module (Submit)
  134. *
  135. * @ingroup tripal_bulk_loader
  136. */
  137. function tripal_bulk_loader_configuration_form_submit($form, $form_state) {
  138. variable_set('tripal_bulk_loader_prepare', $form_state['values']['prepare']);
  139. variable_set('tripal_bulk_loader_disable_triggers', $form_state['values']['disable_triggers']);
  140. variable_set('tripal_bulk_loader_skip_validation', $form_state['values']['no_validate']);
  141. variable_set('tripal_bulk_loader_transactions', $form_state['values']['transactions']);
  142. variable_set('tripal_bulk_loader_lock', $form_state['values']['lock']);
  143. variable_set('tripal_bulk_loader_keep_track_inserted', $form_state['values']['keep_track_inserted']);
  144. }