tripal_bulk_loader.install 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <?php
  2. /**
  3. * @file
  4. * @todo Add file header description
  5. */
  6. /**
  7. * Implements hook_install
  8. */
  9. function tripal_bulk_loader_install() {
  10. drupal_install_schema('tripal_bulk_loader');
  11. }
  12. /**
  13. * Implements hook_uninstall
  14. */
  15. function tripal_bulk_loader_uninstall() {
  16. drupal_uninstall_schema('tripal_bulk_loader');
  17. }
  18. /**
  19. * Implements hook_schema
  20. *
  21. * Creates the following tables in the Drupal database:
  22. * - tripal_bulk_loader: Stores extra details for bulk loading jobs (nodes)
  23. * - tripal_bulk_loader_template: Stores all loading templates
  24. * - tripal_bulk_loader_inserted: Keeps track of all records inserted for a given bulk loading job
  25. */
  26. function tripal_bulk_loader_schema() {
  27. $schema = array();
  28. $schema['tripal_bulk_loader'] = array(
  29. 'fields' => array(
  30. 'nid' => array(
  31. 'type' => 'int',
  32. 'unsigned' => TRUE,
  33. 'not null' => TRUE,
  34. ),
  35. 'loader_name' => array(
  36. 'type' => 'varchar',
  37. ),
  38. 'template_id' => array(
  39. 'type' => 'varchar',
  40. ),
  41. 'file' => array(
  42. 'type' => 'varchar',
  43. 'not null' => TRUE
  44. ),
  45. 'job_id' => array(
  46. 'type' => 'int',
  47. ),
  48. 'job_status' => array(
  49. 'type' => 'varchar',
  50. ),
  51. 'file_has_header' => array(
  52. 'type' => 'int',
  53. 'size' => 'tiny',
  54. 'not null' => TRUE,
  55. 'default' => 0,
  56. ),
  57. 'keep_track_inserted' => array(
  58. 'type' => 'int',
  59. 'size' => 'tiny',
  60. 'not null' => TRUE,
  61. 'default' => 1
  62. ),
  63. ),
  64. 'primary key' => array('nid'),
  65. 'unique keys' => array(
  66. 'name' => array('loader_name')
  67. ),
  68. );
  69. $schema['tripal_bulk_loader_template'] = array(
  70. 'fields' => array(
  71. 'template_id' => array(
  72. 'type' => 'serial',
  73. 'unsigned' => TRUE,
  74. 'not null' => TRUE,
  75. ),
  76. 'name' => array(
  77. 'type' => 'varchar',
  78. ),
  79. 'template_array' => array(
  80. 'type' => 'varchar',
  81. )
  82. ),
  83. 'primary key' => array('template_id'),
  84. 'unique keys' => array(
  85. 'name' => array('name')
  86. ),
  87. );
  88. $schema['tripal_bulk_loader_inserted'] = array(
  89. 'fields' => array(
  90. 'tripal_bulk_loader_inserted_id' => array(
  91. 'type' => 'serial',
  92. 'not null' => TRUE
  93. ),
  94. 'nid' => array(
  95. 'type' => 'int',
  96. 'unsigned' => TRUE,
  97. 'not null' => TRUE,
  98. ),
  99. 'table_inserted_into' => array(
  100. 'type' => 'varchar',
  101. 'not null' => TRUE,
  102. ),
  103. 'table_primary_key' => array(
  104. 'type' => 'varchar',
  105. 'not null' => TRUE,
  106. ),
  107. 'ids_inserted' => array(
  108. 'type' => 'text',
  109. 'not null' => TRUE
  110. ),
  111. ),
  112. 'primary key' => array('tripal_bulk_loader_inserted_id'),
  113. );
  114. $schema['tripal_bulk_loader_constants'] = array(
  115. 'fields' => array(
  116. 'constant_id' => array(
  117. 'type' => 'serial',
  118. 'not null' => TRUE
  119. ),
  120. 'nid' => array(
  121. 'type' => 'int',
  122. 'unsigned' => TRUE,
  123. 'not null' => TRUE,
  124. ),
  125. 'group_id' => array(
  126. 'type' => 'int',
  127. 'unsigned' => TRUE,
  128. 'not null' => TRUE,
  129. 'default' => 0
  130. ),
  131. 'chado_table' => array(
  132. 'type' => 'varchar',
  133. 'not null' => TRUE,
  134. ),
  135. 'chado_field' => array(
  136. 'type' => 'varchar',
  137. 'not null' => TRUE,
  138. ),
  139. 'record_id' => array(
  140. 'type' => 'int',
  141. 'not null' => TRUE
  142. ),
  143. 'field_id' => array(
  144. 'type' => 'int',
  145. 'not null' => TRUE
  146. ),
  147. 'value' => array(
  148. 'type' => 'text',
  149. ),
  150. ),
  151. 'primary key' => array('constant_id'),
  152. );
  153. return $schema;
  154. }
  155. /**
  156. * Update schema for version 6.x-0.3.1b-1.5
  157. * - Add the tripal_bulk_loader_constants table
  158. */
  159. function tripal_bulk_loader_update_6150() {
  160. // Create tripal_bulk_loader_constants table
  161. $schema = tripal_bulk_loader_schema();
  162. $ret = array();
  163. db_create_table($ret, 'tripal_bulk_loader_constants', $schema['tripal_bulk_loader_constants']);
  164. return $ret;
  165. }
  166. /**
  167. * Update schema for version 6.x-0.3.1b-1.5
  168. * - Add the tripal_bulk_loader_constants.group_id column
  169. * to allow multiple sets of constants per job
  170. */
  171. function tripal_bulk_loader_update_6151() {
  172. $ret = array();
  173. $schema = tripal_bulk_loader_schema();
  174. db_add_field(
  175. $ret,
  176. 'tripal_bulk_loader_constants',
  177. 'group_id',
  178. array(
  179. 'type' => 'int',
  180. 'unsigned' => TRUE,
  181. 'not null' => TRUE,
  182. 'default' => 0
  183. )
  184. );
  185. return $ret;
  186. }
  187. function tripal_bulk_loader_update_6152() {
  188. $ret = array();
  189. db_add_field(
  190. $ret,
  191. 'tripal_bulk_loader',
  192. 'keep_track_inserted',
  193. array(
  194. 'type' => 'int',
  195. 'size' => 'tiny',
  196. 'not null' => TRUE,
  197. 'default' => 1
  198. )
  199. );
  200. return $ret;
  201. }
  202. /**
  203. * Implementation of hook_requirements().
  204. */
  205. function tripal_bulk_loader_requirements($phase) {
  206. $requirements = array();
  207. if ($phase == 'install') {
  208. // make sure chado is installed
  209. if (!tripal_core_is_chado_installed()) {
  210. $requirements ['tripal_bulk_loader'] = array(
  211. 'title' => "tripal_bulk_loader",
  212. 'value' => "ERROR: Chado most be installed before this module can be enabled",
  213. 'severity' => REQUIREMENT_ERROR,
  214. );
  215. }
  216. }
  217. return $requirements;
  218. }