tripal_bulk_loader.admin.inc 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. /**
  3. * @file
  4. * Bulk Loader Administration (Miscellaneous)
  5. */
  6. /**
  7. * Provides a description page and quick links for template management
  8. *
  9. * @ingroup tripal_bulk_loader
  10. */
  11. function tripal_bulk_loader_admin_manage_templates() {
  12. $output = '';
  13. $output .= '<br /><h3>Quick Links:</h3>';
  14. $output .= '<ul>'
  15. . '<li>'
  16. . t('<a href="@create">Create</a> a new template',
  17. array('@create' => url('admin/tripal/tripal_bulk_loader_template/manage_templates/create')))
  18. . '</li>'
  19. . '<li>'
  20. . t('<a href="@edit">Edit</a> an existing template',
  21. array('@edit' => url('admin/tripal/tripal_bulk_loader_template/manage_templates/edit')))
  22. . '</li>'
  23. . '<li>'
  24. . t('<a href="@delete">Delete</a> an existing template',
  25. array('@delete' => url('admin/tripal/tripal_bulk_loader_template/manage_templates/delete')))
  26. . '</li>'
  27. . '<li>'
  28. . t('<a href="@import">Import</a> a new template',
  29. array('@import' => url('admin/tripal/tripal_bulk_loader_template/manage_templates/import')))
  30. . '</li>'
  31. . '<li>'
  32. . t('<a href="@export">Export</a> an existing template',
  33. array('@export' => url('admin/tripal/tripal_bulk_loader_template/manage_templates/export')))
  34. . '</li>'
  35. . '</ul>';
  36. $output .= '<p>' . t('Templates, as the term is used for this module, refer to plans
  37. describing how the columns in the data file supplied to a bulk loading job map to tables
  38. and fields in chado. Templates are created independently of bulk loading jobs so that
  39. they can be re-used. Thus you only need one template to load any number of files of the
  40. same format.') . '</p>';
  41. return $output;
  42. }
  43. /**
  44. * Provides a listing of bulk loader jobs and links for administration
  45. *
  46. * @ingroup tripal_bulk_loader
  47. */
  48. function tripal_bulk_loader_admin_jobs() {
  49. $output = '';
  50. $num_jobs_per_page = 50;
  51. $output .= '<p>' . t('Jobs are not automatically submitted to the tripal jobs management
  52. system when they are first created. Any jobs listed below with a status of "Initialized"
  53. will not have a Job ID until you go to the bulk loader page and submit the job.') . '</p>';
  54. $header = array(
  55. array('data' => 'Job ID', 'field' => 'job_id', 'sort' => 'DESC'),
  56. array('data' => 'Name', 'field' => 'loader_name'),
  57. array('data' => 'Template', 'field' => 'template_name'),
  58. array('data' => 'Status', 'field' => 'job_status'),
  59. array('data' => 'Progress', 'field' => 'progress'),
  60. '');
  61. $rows = array();
  62. $resource = pager_query("SELECT n.*, t.name as template_name, j.progress
  63. FROM {tripal_bulk_loader} n
  64. LEFT JOIN {tripal_bulk_loader_template} t ON cast(n.template_id as integer) = t.template_id
  65. LEFT JOIN {tripal_jobs} j ON n.job_id = j.job_id"
  66. . tablesort_sql($header),
  67. $num_jobs_per_page);
  68. while ($n = db_fetch_object($resource)) {
  69. $rows[] = array(
  70. l($n->job_id, 'admin/tripal/tripal_jobs/view/' . $n->job_id),
  71. l($n->loader_name, 'node/' . $n->nid),
  72. l($n->template_name, 'admin/tripal/tripal_bulk_loader_template/manage_templates/edit', array('query' => 'template_id=' . $n->template_id)),
  73. $n->job_status,
  74. ($n->progress) ? $n->progress . '%' : '',
  75. l('View', 'node/' . $n->nid) . ' | ' . l('Edit', 'node/' . $n->nid . '/edit')
  76. );
  77. }
  78. $output .= theme_table($header, $rows);
  79. $output .= theme('pager');
  80. return $output;
  81. }
  82. /**
  83. * @section
  84. * Configuration Form
  85. */
  86. /**
  87. * A Configuration form for this module
  88. *
  89. * @ingroup tripal_bulk_loader
  90. */
  91. function tripal_bulk_loader_configuration_form($form_state = NULL) {
  92. $form = array();
  93. $form['space'] = array(
  94. '#type' => 'fieldset',
  95. '#title' => t('Enable/Disable Functionality'),
  96. );
  97. $form['space']['keep_track_inserted'] = array(
  98. '#type' => 'checkbox',
  99. '#title' => t('Keep track of inserted record IDs'),
  100. '#description' => t('This enables the ability to revert an entire loading job even if '
  101. .'it completed successfully. Furthermore, it displays the number of records '
  102. .'successfully inserted into each table.'),
  103. '#default_value' => variable_get('tripal_bulk_loader_keep_track_inserted', FALSE),
  104. );
  105. $form['speed'] = array(
  106. '#type' => 'fieldset',
  107. '#title' => t('Possible Speed Improvements'),
  108. );
  109. $form['speed']['prepare'] = array(
  110. '#type' => 'checkbox',
  111. '#title' => t('Use Prepared Statements'),
  112. '#description' => t('SQL Prepared Statements allow for SQL queries which will be run '
  113. .'many times to be parsed, rewritten and planned only once rather then every time '
  114. .'the query is run. In the case of the bulk loader, this ensures that planning only '
  115. .'occurs once for each "record" in your bulk loading template.'),
  116. '#default_value' => variable_get('tripal_bulk_loader_prepare', TRUE),
  117. );
  118. $form['speed']['disable_triggers'] = array(
  119. '#type' => 'checkbox',
  120. '#title' => t('Delay Constraint Checking during loading job.'),
  121. '#description' => t('This delays the constraint checking until the end of the
  122. loading proccess.'),
  123. '#default_value' => variable_get('tripal_bulk_loader_disable_triggers', TRUE),
  124. );
  125. $form['speed']['no_validate'] = array(
  126. '#type' => 'checkbox',
  127. '#title' => t('Skip Validation at the Tripal Core API level'),
  128. '#description' => t('If an error is encountered, the Tripal core API will try
  129. to provide informative error messages. With this turned off, you will not benifit
  130. from these more informative error messages; however, your job will load faster
  131. since it doesn\'t have to do the additional checking before inserting.'),
  132. '#default_value' => variable_get('tripal_bulk_loader_skip_validation', FALSE),
  133. );
  134. $form['speed']['transactions'] = array(
  135. '#type' => 'radios',
  136. '#title' => t('Transaction Rollback when an error is encountered'),
  137. '#options' => array(
  138. 'all' => t('Rollback the last constant set.'
  139. .'<div class="description"If you added more then one constant set then the
  140. successfully loaded constant sets will not be rolled back. However, once an error
  141. is encountered no further constant sets will be loaded either.</div>'),
  142. 'row' => t('Only Rollback the last line of the input file.'
  143. .'<div class="description">This option may allow you to restart the job after
  144. fixing the error (manual intervention needed).</div>'),
  145. 'none' => t('Do not use transactions<div class="description">This is not recommended.</div>')
  146. ),
  147. '#default_value' => variable_get('tripal_bulk_loader_transactions', 'row')
  148. );
  149. $form['speed']['lock'] = array(
  150. '#type' => 'radios',
  151. '#title' => t('Lock Type'),
  152. '#description' => t('The type of lock used by the bulk loading jobs. The lock is '
  153. .'acquired at the beginning of the job and kept till the end. A lock of the type '
  154. .'selected will be acquired for every table being inserted into.'),
  155. '#options' => array(
  156. 'ROW EXCLUSIVE' => t('ROW EXCLUSIVE: The default lock type for insert queries.'),
  157. 'EXCLUSIVE' => t('EXCLUSIVE: Only Select Queries can access the table.'),
  158. 'ACCESS EXCLUSIVE' => t('ACCESS EXCLUSIVE: No other queries can access the table.'),
  159. ),
  160. '#default_value' => variable_get('tripal_bulk_loader_lock', 'ROW EXCLUSIVE'),
  161. );
  162. $form['submit1'] = array(
  163. '#type' => 'submit',
  164. '#value' => t('Save')
  165. );
  166. return $form;
  167. }
  168. /**
  169. * A Configuration form for this module (Submit)
  170. *
  171. * @ingroup tripal_bulk_loader
  172. */
  173. function tripal_bulk_loader_configuration_form_submit($form, $form_state) {
  174. variable_set('tripal_bulk_loader_prepare', $form_state['values']['prepare']);
  175. variable_set('tripal_bulk_loader_disable_triggers', $form_state['values']['disable_triggers']);
  176. variable_set('tripal_bulk_loader_skip_validation', $form_state['values']['no_validate']);
  177. variable_set('tripal_bulk_loader_transactions', $form_state['values']['transactions']);
  178. variable_set('tripal_bulk_loader_lock', $form_state['values']['lock']);
  179. variable_set('tripal_bulk_loader_keep_track_inserted', $form_state['values']['keep_track_inserted']);
  180. }