tripal_bulk_loader.install 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <?php
  2. /**
  3. * @file
  4. * @todo Add file header description
  5. */
  6. /**
  7. * Disable default views when module is disabled
  8. */
  9. function tripal_bulk_loader_disable() {
  10. // Disable all default views provided by this module
  11. require_once("tripal_bulk_loader.views_default.inc");
  12. $views = tripal_bulk_loader_views_default_views();
  13. foreach (array_keys($views) as $view_name) {
  14. tripal_views_admin_disable_view($view_name,FALSE,array('suppress_error' => TRUE));
  15. }
  16. }
  17. /**
  18. * Implements hook_schema
  19. *
  20. * Creates the following tables in the Drupal database:
  21. * - tripal_bulk_loader: Stores extra details for bulk loading jobs (nodes)
  22. * - tripal_bulk_loader_template: Stores all loading templates
  23. * - tripal_bulk_loader_inserted: Keeps track of all records inserted for a given bulk loading job
  24. */
  25. function tripal_bulk_loader_schema() {
  26. $schema = array();
  27. $schema['tripal_bulk_loader'] = array(
  28. 'fields' => array(
  29. 'nid' => array(
  30. 'type' => 'int',
  31. 'unsigned' => TRUE,
  32. 'not null' => TRUE,
  33. ),
  34. 'loader_name' => array(
  35. 'type' => 'varchar',
  36. ),
  37. 'template_id' => array(
  38. 'type' => 'int',
  39. ),
  40. 'file' => array(
  41. 'type' => 'varchar',
  42. 'not null' => TRUE
  43. ),
  44. 'job_id' => array(
  45. 'type' => 'int',
  46. ),
  47. 'job_status' => array(
  48. 'type' => 'varchar',
  49. ),
  50. 'file_has_header' => array(
  51. 'type' => 'int',
  52. 'size' => 'tiny',
  53. 'not null' => TRUE,
  54. 'default' => 0,
  55. ),
  56. 'keep_track_inserted' => array(
  57. 'type' => 'int',
  58. 'size' => 'tiny',
  59. 'not null' => TRUE,
  60. 'default' => 1
  61. ),
  62. ),
  63. 'primary key' => array('nid'),
  64. 'unique keys' => array(
  65. 'name' => array('loader_name')
  66. ),
  67. );
  68. $schema['tripal_bulk_loader_template'] = array(
  69. 'fields' => array(
  70. 'template_id' => array(
  71. 'type' => 'serial',
  72. 'unsigned' => TRUE,
  73. 'not null' => TRUE,
  74. ),
  75. 'name' => array(
  76. 'type' => 'varchar',
  77. ),
  78. 'template_array' => array(
  79. 'type' => 'varchar',
  80. ),
  81. 'created' => array(
  82. 'description' => 'The Unix timestamp when the template was created.',
  83. 'type' => 'int',
  84. 'not null' => TRUE,
  85. 'default' => 0,
  86. ),
  87. 'changed' => array(
  88. 'description' => 'The Unix timestamp when the template was most recently saved.',
  89. 'type' => 'int',
  90. 'not null' => TRUE,
  91. 'default' => 0,
  92. )
  93. ),
  94. 'primary key' => array('template_id'),
  95. 'unique keys' => array(
  96. 'name' => array('name')
  97. ),
  98. );
  99. $schema['tripal_bulk_loader_inserted'] = array(
  100. 'fields' => array(
  101. 'tripal_bulk_loader_inserted_id' => array(
  102. 'type' => 'serial',
  103. 'not null' => TRUE
  104. ),
  105. 'nid' => array(
  106. 'type' => 'int',
  107. 'unsigned' => TRUE,
  108. 'not null' => TRUE,
  109. ),
  110. 'table_inserted_into' => array(
  111. 'type' => 'varchar',
  112. 'not null' => TRUE,
  113. ),
  114. 'table_primary_key' => array(
  115. 'type' => 'varchar',
  116. 'not null' => TRUE,
  117. ),
  118. 'ids_inserted' => array(
  119. 'type' => 'text',
  120. 'not null' => TRUE
  121. ),
  122. ),
  123. 'primary key' => array('tripal_bulk_loader_inserted_id'),
  124. );
  125. $schema['tripal_bulk_loader_constants'] = array(
  126. 'fields' => array(
  127. 'constant_id' => array(
  128. 'type' => 'serial',
  129. 'not null' => TRUE
  130. ),
  131. 'nid' => array(
  132. 'type' => 'int',
  133. 'unsigned' => TRUE,
  134. 'not null' => TRUE,
  135. ),
  136. 'group_id' => array(
  137. 'type' => 'int',
  138. 'unsigned' => TRUE,
  139. 'not null' => TRUE,
  140. 'default' => 0
  141. ),
  142. 'chado_table' => array(
  143. 'type' => 'varchar',
  144. 'not null' => TRUE,
  145. ),
  146. 'chado_field' => array(
  147. 'type' => 'varchar',
  148. 'not null' => TRUE,
  149. ),
  150. 'record_id' => array(
  151. 'type' => 'int',
  152. 'not null' => TRUE
  153. ),
  154. 'field_id' => array(
  155. 'type' => 'int',
  156. 'not null' => TRUE
  157. ),
  158. 'value' => array(
  159. 'type' => 'text',
  160. ),
  161. ),
  162. 'primary key' => array('constant_id'),
  163. );
  164. return $schema;
  165. }
  166. /**
  167. * Update schema for version 6.x-0.3.1b-1.5
  168. * - Add the tripal_bulk_loader_constants table
  169. */
  170. function tripal_bulk_loader_update_6150() {
  171. // Create tripal_bulk_loader_constants table
  172. $schema = tripal_bulk_loader_schema();
  173. db_create_table('tripal_bulk_loader_constants', $schema['tripal_bulk_loader_constants']);
  174. return 'Added support for loader-specific constants.';
  175. }
  176. /**
  177. * Update schema for version 6.x-0.3.1b-1.5
  178. * - Add the tripal_bulk_loader_constants.group_id column
  179. * to allow multiple sets of constants per job
  180. */
  181. function tripal_bulk_loader_update_6151() {
  182. $schema = tripal_bulk_loader_schema();
  183. db_add_field(
  184. 'tripal_bulk_loader_constants',
  185. 'group_id',
  186. array(
  187. 'type' => 'int',
  188. 'unsigned' => TRUE,
  189. 'not null' => TRUE,
  190. 'default' => 0
  191. )
  192. );
  193. return 'Added support for multiple sets of loader-specific constants.';
  194. }
  195. function tripal_bulk_loader_update_6152() {
  196. db_add_field(
  197. 'tripal_bulk_loader',
  198. 'keep_track_inserted',
  199. array(
  200. 'type' => 'int',
  201. 'size' => 'tiny',
  202. 'not null' => TRUE,
  203. 'default' => 1
  204. )
  205. );
  206. return 'Added ability to rollback loading job based on storing loaded ids.';
  207. }
  208. /**
  209. * Update to 7.x-2.0
  210. * -Cast tripal_bulk_loader.template_id to int field
  211. */
  212. function tripal_bulk_loader_update_7201() {
  213. db_change_field(
  214. 'tripal_bulk_loader',
  215. 'template_id',
  216. 'template_id',
  217. array('type' => 'int')
  218. );
  219. db_add_field(
  220. 'tripal_bulk_loader_template',
  221. 'created',
  222. array(
  223. 'description' => 'The Unix timestamp when the template was created.',
  224. 'type' => 'int',
  225. 'not null' => TRUE,
  226. 'default' => 0,
  227. )
  228. );
  229. db_add_field(
  230. 'tripal_bulk_loader_template',
  231. 'changed',
  232. array(
  233. 'description' => 'The Unix timestamp when the template was most recently saved.',
  234. 'type' => 'int',
  235. 'not null' => TRUE,
  236. 'default' => 0,
  237. )
  238. );
  239. return 'Updated tripal_bulk_loader.template_id from character to integer '
  240. . 'and added time created/updated track to templates.';
  241. }
  242. /**
  243. * Implementation of hook_requirements().
  244. */
  245. function tripal_bulk_loader_requirements($phase) {
  246. $requirements = array();
  247. if ($phase == 'install') {
  248. // make sure chado is installed
  249. if (!$GLOBALS["chado_is_installed"]) {
  250. $requirements ['tripal_bulk_loader'] = array(
  251. 'title' => "tripal_bulk_loader",
  252. 'value' => "ERROR: Chado most be installed before this module can be enabled",
  253. 'severity' => REQUIREMENT_ERROR,
  254. );
  255. }
  256. }
  257. return $requirements;
  258. }