tripal_bulk_loader.install 7.2 KB

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