tripal_core.install 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <?php
  2. /**
  3. * @file
  4. * Contains functions used to install/uninstall tripal_core.
  5. */
  6. /**
  7. * Implementation of hook_install().
  8. *
  9. * @ingroup tripal_core
  10. */
  11. function tripal_core_install() {
  12. // make the data directory for this module
  13. $data_dir = tripal_file_directory_path();
  14. if (!file_prepare_directory($data_dir, FILE_CREATE_DIRECTORY)) {
  15. $message = "Cannot create directory $data_dir. This module may not " .
  16. "behave correctly without this directory. Please create " .
  17. "the directory manually or fix the problem and reinstall.";
  18. drupal_set_message(check_plain($message), 'error');
  19. watchdog('tripal_core', $message, array(), WATCHDOG_ERROR);
  20. }
  21. }
  22. /**
  23. * Implementation of hook_schema().
  24. *
  25. * @ingroup tripal_core
  26. */
  27. function tripal_core_schema() {
  28. // get the schemas defined by this install file
  29. $schema = tripal_core_get_schemas();
  30. // if this module is already installed and enabled, then we want to provide
  31. // the schemas for all of the custom tables. This will allow Views to
  32. // see the schemas. We check if the module is installed because during
  33. // installation we don't want to make these custom tables available as we don't
  34. // want them created in the Drupal database. The custom tables go in the
  35. // Chado database.
  36. if (db_table_exists('tripal_custom_tables')) {
  37. $sql = 'SELECT * FROM {tripal_custom_tables}';
  38. $results = db_query($sql);
  39. foreach ($results as $custom) {
  40. $schema[$custom->table_name] = unserialize($custom->schema);
  41. }
  42. }
  43. return $schema;
  44. }
  45. /**
  46. * Implementation of hook_uninstall().
  47. *
  48. * @ingroup tripal_core
  49. */
  50. function tripal_core_uninstall() {
  51. }
  52. /**
  53. * This function simply defines all tables needed for the module to work
  54. * correctly. By putting the table definitions in a separate function we
  55. * can easily provide the entire list for hook_install or individual
  56. * tables for an update.
  57. *
  58. * @ingroup tripal_core
  59. */
  60. function tripal_core_get_schemas() {
  61. $schema = array();
  62. // get all the various schema parts and join them together
  63. $temp = tripal_core_jobs_schema();
  64. foreach ($temp as $table => $arr) {
  65. $schema[$table] = $arr;
  66. }
  67. $temp = tripal_core_mviews_schema();
  68. foreach ($temp as $table => $arr) {
  69. $schema[$table] = $arr;
  70. }
  71. $temp = tripal_core_custom_tables_schema();
  72. foreach ($temp as $table => $arr) {
  73. $schema[$table] = $arr;
  74. }
  75. return $schema;
  76. }
  77. /**
  78. * Describes the Tripal Materialized View (tripal_mviews) table
  79. * This table keeps track of all materialized views created by Tripal and stored in chado
  80. *
  81. * @ingroup tripal_core
  82. */
  83. function tripal_core_mviews_schema() {
  84. $schema = array();
  85. $schema['tripal_mviews'] = array(
  86. 'fields' => array(
  87. 'mview_id' => array(
  88. 'type' => 'serial',
  89. 'unsigned' => TRUE,
  90. 'not NULL' => TRUE
  91. ),
  92. 'name' => array(
  93. 'type' => 'varchar',
  94. 'length' => 255,
  95. 'not NULL' => TRUE
  96. ),
  97. 'modulename' => array(
  98. 'type' => 'varchar',
  99. 'length' => 50,
  100. 'not NULL' => TRUE,
  101. 'description' => 'The module name that provides the callback for this job'
  102. ),
  103. 'mv_table' => array(
  104. 'type' => 'varchar',
  105. 'length' => 128,
  106. 'not NULL' => FALSE
  107. ),
  108. 'mv_specs' => array(
  109. 'type' => 'text',
  110. 'size' => 'normal',
  111. 'not NULL' => FALSE
  112. ),
  113. 'mv_schema' => array(
  114. 'type' => 'text',
  115. 'size' => 'normal',
  116. 'not NULL' => FALSE
  117. ),
  118. 'indexed' => array(
  119. 'type' => 'text',
  120. 'size' => 'normal',
  121. 'not NULL' => FALSE
  122. ),
  123. 'query' => array(
  124. 'type' => 'text',
  125. 'size' => 'normal',
  126. 'not NULL' => TRUE
  127. ),
  128. 'special_index' => array(
  129. 'type' => 'text',
  130. 'size' => 'normal',
  131. 'not NULL' => FALSE
  132. ),
  133. 'last_update' => array(
  134. 'type' => 'int',
  135. 'not NULL' => FALSE,
  136. 'description' => 'UNIX integer time'
  137. ),
  138. 'status' => array(
  139. 'type' => 'text',
  140. 'size' => 'normal',
  141. 'not NULL' => FALSE
  142. ),
  143. 'comment' => array(
  144. 'type' => 'text',
  145. 'size' => 'normal',
  146. 'not NULL' => FALSE
  147. ),
  148. ),
  149. 'indexes' => array(
  150. 'mview_id' => array('mview_id')
  151. ),
  152. 'unique keys' => array(
  153. 'mv_table' => array('mv_table'),
  154. 'mv_name' => array('name'),
  155. ),
  156. 'primary key' => array('mview_id'),
  157. );
  158. return $schema;
  159. }
  160. /**
  161. * Describes the Tripal Jobs (tripal_jobs) table
  162. * This table keeps track of all tripal jobs including their current status and is used
  163. * by tripal_launch_jobs to determine which jobs need to be run
  164. *
  165. * @ingroup tripal_core
  166. */
  167. function tripal_core_jobs_schema() {
  168. $schema = array();
  169. $schema['tripal_jobs'] = array(
  170. 'fields' => array(
  171. 'job_id' => array(
  172. 'type' => 'serial',
  173. 'unsigned' => TRUE,
  174. 'not NULL' => TRUE
  175. ),
  176. 'uid' => array(
  177. 'type' => 'int',
  178. 'unsigned' => TRUE,
  179. 'not NULL' => TRUE,
  180. 'description' => 'The Drupal userid of the submitee'
  181. ),
  182. 'job_name' => array(
  183. 'type' => 'varchar',
  184. 'length' => 255,
  185. 'not NULL' => TRUE
  186. ),
  187. 'modulename' => array(
  188. 'type' => 'varchar',
  189. 'length' => 50,
  190. 'not NULL' => TRUE,
  191. 'description' => 'The module name that provides the callback for this job'
  192. ),
  193. 'callback' => array(
  194. 'type' => 'varchar',
  195. 'length' => 255,
  196. 'not NULL' => TRUE
  197. ),
  198. 'arguments' => array(
  199. 'type' => 'text',
  200. 'size' => 'normal',
  201. 'not NULL' => FALSE
  202. ),
  203. 'progress' => array(
  204. 'type' => 'int',
  205. 'unsigned' => TRUE,
  206. 'default' => 0,
  207. 'not NULL' => FALSE,
  208. 'description' => 'a value from 0 to 100 indicating percent complete'
  209. ),
  210. 'status' => array(
  211. 'type' => 'varchar',
  212. 'length' => 50,
  213. 'not NULL' => TRUE
  214. ),
  215. 'submit_date' => array(
  216. 'type' => 'int',
  217. 'not NULL' => TRUE,
  218. 'description' => 'UNIX integer submit time'
  219. ),
  220. 'start_time' => array(
  221. 'type' => 'int',
  222. 'not NULL' => FALSE,
  223. 'description' => 'UNIX integer start time'
  224. ),
  225. 'end_time' => array(
  226. 'type' => 'int',
  227. 'not NULL' => FALSE,
  228. 'description' => 'UNIX integer end time'
  229. ),
  230. 'error_msg' => array(
  231. 'type' => 'text',
  232. 'size' => 'normal',
  233. 'not NULL' => FALSE
  234. ),
  235. 'pid' => array(
  236. 'type' => 'int',
  237. 'unsigned' => TRUE,
  238. 'not NULL' => FALSE,
  239. 'description' => 'The process id for the job'
  240. ),
  241. 'priority' => array(
  242. 'type' => 'int',
  243. 'unsigned' => TRUE,
  244. 'not NULL' => TRUE,
  245. 'default' => '0',
  246. 'description' => 'The job priority'
  247. ),
  248. 'mlock' => array(
  249. 'type' => 'int',
  250. 'unsigned' => TRUE,
  251. 'not NULL' => FALSE,
  252. 'description' => 'If set to 1 then all jobs for the module are held until this one finishes'
  253. ),
  254. 'lock' => array(
  255. 'type' => 'int',
  256. 'unsigned' => TRUE,
  257. 'not NULL' => FALSE,
  258. 'description' => 'If set to 1 then all jobs are held until this one finishes'
  259. ),
  260. ),
  261. 'indexes' => array(
  262. 'job_id' => array('job_id'),
  263. 'job_name' => array('job_name')
  264. ),
  265. 'primary key' => array('job_id'),
  266. );
  267. return $schema;
  268. }
  269. /**
  270. * Describes the Tripal Custom Tables (tripal_custom_tables) table
  271. * This keeps track of tables created by Tripal and stored in chado that may or may not
  272. * also be materialized views.
  273. *
  274. * @ingroup tripal_core
  275. */
  276. function tripal_core_custom_tables_schema() {
  277. $schema = array();
  278. $schema['tripal_custom_tables'] = array(
  279. 'fields' => array(
  280. 'table_id' => array(
  281. 'type' => 'serial',
  282. 'unsigned' => TRUE,
  283. 'not NULL' => TRUE
  284. ),
  285. 'table_name' => array(
  286. 'type' => 'varchar',
  287. 'length' => 255,
  288. 'not NULL' => TRUE
  289. ),
  290. 'schema' => array(
  291. 'type' => 'text',
  292. 'not NULL' => TRUE
  293. ),
  294. ),
  295. 'indexes' => array(
  296. 'table_id' => array('table_id'),
  297. ),
  298. 'primary key' => array('table_id'),
  299. );
  300. return $schema;
  301. }