tripal_bulk_loader.admin.inc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <?php
  2. /**
  3. * @file
  4. * Bulk Loader Administration (Miscellaneous)
  5. */
  6. /**
  7. * Provides a description page and quick links for the bulk loader
  8. *
  9. * @ingroup tripal_bulk_loader
  10. */
  11. function tripal_bulk_loader_admin_template() {
  12. $output = '';
  13. $output .= '<br /><h3>Quick Links:</h3>';
  14. $output .= '<ul>'
  15. . '<li>'
  16. . t('<a href="@link">Configure settings</a>',
  17. array('@link' => url('admin/tripal/tripal_bulk_loader_template/configure')))
  18. . '</li>'
  19. . '<li>'
  20. . t('List <a href="@link">Bulk Loader Jobs</a>',
  21. array('@link' => url('admin/tripal/tripal_bulk_loader_template/jobs')))
  22. . '</li>'
  23. . '<li>'
  24. . t('List <a href="@link">Manage Templates</a>',
  25. array('@link' => url('admin/tripal/tripal_bulk_loader_template/manage_templates')))
  26. . '</li>'
  27. . '<ul>'
  28. . '<li>'
  29. . t('<a href="@create">Create</a> a new template',
  30. array('@create' => url('admin/tripal/tripal_bulk_loader_template/manage_templates/create')))
  31. . '</li>'
  32. . '<li>'
  33. . t('<a href="@edit">Edit</a> an existing template',
  34. array('@edit' => url('admin/tripal/tripal_bulk_loader_template/manage_templates/edit')))
  35. . '</li>'
  36. . '<li>'
  37. . t('<a href="@delete">Delete</a> an existing template',
  38. array('@delete' => url('admin/tripal/tripal_bulk_loader_template/manage_templates/delete')))
  39. . '</li>'
  40. . '<li>'
  41. . t('<a href="@import">Import</a> a new template',
  42. array('@import' => url('admin/tripal/tripal_bulk_loader_template/manage_templates/import')))
  43. . '</li>'
  44. . '<li>'
  45. . t('<a href="@export">Export</a> an existing template',
  46. array('@export' => url('admin/tripal/tripal_bulk_loader_template/manage_templates/export')))
  47. . '</li>'
  48. . '</ul>'
  49. . '</ul>';
  50. $output .= '<h3>Module Description:</h3>';
  51. $output .= '<p>This module provides the ability to create loading templates for any tab-delimited '
  52. . 'data file allowing it to be loaded into chado. The Loading Templates are a direct mapping '
  53. . 'between the columns in your file and the columns in chado tables. As such to use this tool '
  54. . 'you need to be very familar with the chado schema -See '
  55. . l(t('Chado -Getting Started'), 'http://gmod.org/wiki/Chado_-_Getting_Started')
  56. . '. The ability to add constants and specify foreign key contraints is also provided '
  57. . 'in order for the loader to fill chado columns which may be required but are not specified '
  58. . 'in your input file.</p>';
  59. $output .= '<br />';
  60. $output .= '<h3>Setup Instructions</h3>';
  61. $output .= '<p>After intallation of the bulk loader module, the following tasks should be performed:</p>';
  62. $output .= '<ol>';
  63. $output .= '<li><b>Install Theme:</b> In order for Bulk Loading pages to be displayed correctly, '
  64. .'the contents of the Tripal Bulk Loader theme directory ([drupal root]/sites/all/modules/tripal/tripal_bulk_loader/theme) '
  65. .'should be moved to the base directory of the Tripal theme ([drupal root]/sites/all/themes/tripal). '
  66. .'Finally the drupal cache should be cleared for the new theme to take effect -navigate to admin/settings/performance '
  67. .'and click the Clear Cached Data button.</li>';
  68. $output .= '</ol>';
  69. return $output;
  70. }
  71. /**
  72. * Provides a description page and quick links for template management
  73. *
  74. * @ingroup tripal_bulk_loader
  75. */
  76. function tripal_bulk_loader_admin_manage_templates() {
  77. $output = '';
  78. $output .= '<br /><h3>Quick Links:</h3>';
  79. $output .= '<ul>'
  80. . '<li>'
  81. . t('<a href="@create">Create</a> a new template',
  82. array('@create' => url('admin/tripal/tripal_bulk_loader_template/manage_templates/create')))
  83. . '</li>'
  84. . '<li>'
  85. . t('<a href="@edit">Edit</a> an existing template',
  86. array('@edit' => url('admin/tripal/tripal_bulk_loader_template/manage_templates/edit')))
  87. . '</li>'
  88. . '<li>'
  89. . t('<a href="@delete">Delete</a> an existing template',
  90. array('@delete' => url('admin/tripal/tripal_bulk_loader_template/manage_templates/delete')))
  91. . '</li>'
  92. . '<li>'
  93. . t('<a href="@import">Import</a> a new template',
  94. array('@import' => url('admin/tripal/tripal_bulk_loader_template/manage_templates/import')))
  95. . '</li>'
  96. . '<li>'
  97. . t('<a href="@export">Export</a> an existing template',
  98. array('@export' => url('admin/tripal/tripal_bulk_loader_template/manage_templates/export')))
  99. . '</li>'
  100. . '</ul>';
  101. $output .= '<p>' . t('Templates, as the term is used for this module, refer to plans
  102. describing how the columns in the data file supplied to a bulk loading job map to tables
  103. and fields in chado. Templates are created independently of bulk loading jobs so that
  104. they can be re-used. Thus you only need one template to load any number of files of the
  105. same format.') . '</p>';
  106. return $output;
  107. }
  108. /**
  109. * Provides a listing of bulk loader jobs and links for administration
  110. *
  111. * @ingroup tripal_bulk_loader
  112. */
  113. function tripal_bulk_loader_admin_jobs() {
  114. $output = '';
  115. $num_jobs_per_page = 50;
  116. $output .= '<p>' . t('Jobs are not automatically submitted to the tripal jobs management
  117. system when they are first created. Any jobs listed below with a status of "Initialized"
  118. will not have a Job ID until you go to the bulk loader page and submit the job.') . '</p>';
  119. $header = array(
  120. array('data' => 'Job ID', 'field' => 'job_id', 'sort' => 'DESC'),
  121. array('data' => 'Name', 'field' => 'loader_name'),
  122. array('data' => 'Template', 'field' => 'template_name'),
  123. array('data' => 'Status', 'field' => 'job_status'),
  124. array('data' => 'Progress', 'field' => 'progress'),
  125. '');
  126. $rows = array();
  127. $resource = pager_query("SELECT n.*, t.name as template_name, j.progress
  128. FROM {tripal_bulk_loader} n
  129. LEFT JOIN {tripal_bulk_loader_template} t ON cast(n.template_id as integer) = t.template_id
  130. LEFT JOIN {tripal_jobs} j ON n.job_id = j.job_id"
  131. . tablesort_sql($header),
  132. $num_jobs_per_page);
  133. while ($n = db_fetch_object($resource)) {
  134. $rows[] = array(
  135. l($n->job_id, 'admin/tripal/tripal_jobs/view/' . $n->job_id),
  136. l($n->loader_name, 'node/' . $n->nid),
  137. l($n->template_name, 'admin/tripal/tripal_bulk_loader_template/manage_templates/edit', array('query' => 'template_id=' . $n->template_id)),
  138. $n->job_status,
  139. ($n->progress) ? $n->progress . '%' : '',
  140. l('View', 'node/' . $n->nid) . ' | ' . l('Edit', 'node/' . $n->nid . '/edit')
  141. );
  142. }
  143. $output .= theme_table($header, $rows);
  144. $output .= theme('pager');
  145. return $output;
  146. }
  147. /**
  148. * @section
  149. * Configuration Form
  150. */
  151. /**
  152. * A Configuration form for this module
  153. *
  154. * @ingroup tripal_bulk_loader
  155. */
  156. function tripal_bulk_loader_configuration_form($form_state = NULL) {
  157. $form = array();
  158. $form['space'] = array(
  159. '#type' => 'fieldset',
  160. '#title' => t('Enable/Disable Functionality'),
  161. );
  162. $form['space']['keep_track_inserted'] = array(
  163. '#type' => 'checkbox',
  164. '#title' => t('Keep track of inserted record IDs'),
  165. '#description' => t('This enables the ability to revert an entire loading job even if '
  166. .'it completed successfully. Furthermore, it displays the number of records '
  167. .'successfully inserted into each table.'),
  168. '#default_value' => variable_get('tripal_bulk_loader_keep_track_inserted', FALSE),
  169. );
  170. $form['speed'] = array(
  171. '#type' => 'fieldset',
  172. '#title' => t('Possible Speed Improvements'),
  173. );
  174. $form['speed']['prepare'] = array(
  175. '#type' => 'checkbox',
  176. '#title' => t('Use Prepared Statements'),
  177. '#description' => t('SQL Prepared Statements allow for SQL queries which will be run '
  178. .'many times to be parsed, rewritten and planned only once rather then every time '
  179. .'the query is run. In the case of the bulk loader, this ensures that planning only '
  180. .'occurs once for each "record" in your bulk loading template.'),
  181. '#default_value' => variable_get('tripal_bulk_loader_prepare', TRUE),
  182. );
  183. $form['speed']['disable_triggers'] = array(
  184. '#type' => 'checkbox',
  185. '#title' => t('Delay Constraint Checking during loading job.'),
  186. '#description' => t('This delays the constraint checking until the end of the
  187. loading proccess.'),
  188. '#default_value' => variable_get('tripal_bulk_loader_disable_triggers', TRUE),
  189. );
  190. $form['speed']['no_validate'] = array(
  191. '#type' => 'checkbox',
  192. '#title' => t('Skip Validation at the Tripal Core API level'),
  193. '#description' => t('If an error is encountered, the Tripal core API will try
  194. to provide informative error messages. With this turned off, you will not benifit
  195. from these more informative error messages; however, your job will load faster
  196. since it doesn\'t have to do the additional checking before inserting.'),
  197. '#default_value' => variable_get('tripal_bulk_loader_skip_validation', FALSE),
  198. );
  199. $form['speed']['transactions'] = array(
  200. '#type' => 'radios',
  201. '#title' => t('Transaction Rollback when an error is encountered'),
  202. '#options' => array(
  203. 'all' => t('Rollback the last constant set.'
  204. .'<div class="description"If you added more then one constant set then the
  205. successfully loaded constant sets will not be rolled back. However, once an error
  206. is encountered no further constant sets will be loaded either.</div>'),
  207. 'row' => t('Only Rollback the last line of the input file.'
  208. .'<div class="description">This option may allow you to restart the job after
  209. fixing the error (manual intervention needed).</div>'),
  210. 'none' => t('Do not use transactions<div class="description">This is not recommended.</div>')
  211. ),
  212. '#default_value' => variable_get('tripal_bulk_loader_transactions', 'row')
  213. );
  214. $form['speed']['lock'] = array(
  215. '#type' => 'radios',
  216. '#title' => t('Lock Type'),
  217. '#description' => t('The type of lock used by the bulk loading jobs. The lock is '
  218. .'acquired at the beginning of the job and kept till the end. A lock of the type '
  219. .'selected will be acquired for every table being inserted into.'),
  220. '#options' => array(
  221. 'ROW EXCLUSIVE' => t('ROW EXCLUSIVE: The default lock type for insert queries.'),
  222. 'EXCLUSIVE' => t('EXCLUSIVE: Only Select Queries can access the table.'),
  223. 'ACCESS EXCLUSIVE' => t('ACCESS EXCLUSIVE: No other queries can access the table.'),
  224. ),
  225. '#default_value' => variable_get('tripal_bulk_loader_lock', 'ROW EXCLUSIVE'),
  226. );
  227. $form['submit1'] = array(
  228. '#type' => 'submit',
  229. '#value' => t('Save')
  230. );
  231. return $form;
  232. }
  233. /**
  234. * A Configuration form for this module (Submit)
  235. *
  236. * @ingroup tripal_bulk_loader
  237. */
  238. function tripal_bulk_loader_configuration_form_submit($form, $form_state) {
  239. variable_set('tripal_bulk_loader_prepare', $form_state['values']['prepare']);
  240. variable_set('tripal_bulk_loader_disable_triggers', $form_state['values']['disable_triggers']);
  241. variable_set('tripal_bulk_loader_skip_validation', $form_state['values']['no_validate']);
  242. variable_set('tripal_bulk_loader_transactions', $form_state['values']['transactions']);
  243. variable_set('tripal_bulk_loader_lock', $form_state['values']['lock']);
  244. variable_set('tripal_bulk_loader_keep_track_inserted', $form_state['values']['keep_track_inserted']);
  245. }