tripal_core.install 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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('type' => 'serial', 'unsigned' => TRUE, 'not NULL' => TRUE),
  88. 'name' => array('type' => 'varchar', 'length' => 255, 'not NULL' => TRUE),
  89. 'modulename' => array('type' => 'varchar', 'length' => 50, 'not NULL' => TRUE, 'description' => 'The module name that provides the callback for this job'),
  90. 'mv_table' => array('type' => 'varchar', 'length' => 128, 'not NULL' => FALSE),
  91. 'mv_specs' => array('type' => 'text', 'size' => 'normal', 'not NULL' => FALSE),
  92. 'mv_schema' => array('type' => 'text', 'size' => 'normal', 'not NULL' => FALSE),
  93. 'indexed' => array('type' => 'text', 'size' => 'normal', 'not NULL' => FALSE),
  94. 'query' => array('type' => 'text', 'size' => 'normal', 'not NULL' => TRUE),
  95. 'special_index' => array('type' => 'text', 'size' => 'normal', 'not NULL' => FALSE),
  96. 'last_update' => array('type' => 'int', 'not NULL' => FALSE, 'description' => 'UNIX integer time'),
  97. 'status' => array('type' => 'text', 'size' => 'normal', 'not NULL' => FALSE),
  98. 'comment' => array('type' => 'text', 'size' => 'normal', 'not NULL' => FALSE),
  99. ),
  100. 'indexes' => array(
  101. 'mview_id' => array('mview_id')
  102. ),
  103. 'unique keys' => array(
  104. 'mv_table' => array('mv_table'),
  105. 'mv_name' => array('name'),
  106. ),
  107. 'primary key' => array('mview_id'),
  108. );
  109. return $schema;
  110. }
  111. /**
  112. * Describes the Tripal Jobs (tripal_jobs) table
  113. * This table keeps track of all tripal jobs including their current status and is used
  114. * by tripal_launch_jobs to determine which jobs need to be run
  115. *
  116. * @ingroup tripal_core
  117. */
  118. function tripal_core_jobs_schema() {
  119. $schema = array();
  120. $schema['tripal_jobs'] = array(
  121. 'fields' => array(
  122. 'job_id' => array('type' => 'serial', 'unsigned' => TRUE, 'not NULL' => TRUE),
  123. 'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not NULL' => TRUE, 'description' => 'The Drupal userid of the submitee'),
  124. 'job_name' => array('type' => 'varchar', 'length' => 255, 'not NULL' => TRUE),
  125. 'modulename' => array('type' => 'varchar', 'length' => 50, 'not NULL' => TRUE, 'description' => 'The module name that provides the callback for this job'),
  126. 'callback' => array('type' => 'varchar', 'length' => 255, 'not NULL' => TRUE),
  127. 'arguments' => array('type' => 'text', 'size' => 'normal', 'not NULL' => FALSE),
  128. 'progress' => array('type' => 'int', 'unsigned' => TRUE, 'default' => 0, 'not NULL' => FALSE, 'description' => 'a value from 0 to 100 indicating percent complete'),
  129. 'status' => array('type' => 'varchar', 'length' => 50, 'not NULL' => TRUE),
  130. 'submit_date' => array('type' => 'int', 'not NULL' => TRUE, 'description' => 'UNIX integer submit time'),
  131. 'start_time' => array('type' => 'int', 'not NULL' => FALSE, 'description' => 'UNIX integer start time'),
  132. 'end_time' => array('type' => 'int', 'not NULL' => FALSE, 'description' => 'UNIX integer end time'),
  133. 'error_msg' => array('type' => 'text', 'size' => 'normal', 'not NULL' => FALSE),
  134. 'pid' => array('type' => 'int', 'unsigned' => TRUE, 'not NULL' => FALSE, 'description' => 'The process id for the job'),
  135. 'priority' => array('type' => 'int', 'unsigned' => TRUE, 'not NULL' => TRUE, 'default' => '0', 'description' => 'The job priority'),
  136. 'mlock' => array('type' => 'int', 'unsigned' => TRUE, 'not NULL' => FALSE, 'description' => 'If set to 1 then all jobs for the module are held until this one finishes'),
  137. 'lock' => array('type' => 'int', 'unsigned' => TRUE, 'not NULL' => FALSE, 'description' => 'If set to 1 then all jobs are held until this one finishes'),
  138. ),
  139. 'indexes' => array(
  140. 'job_id' => array('job_id'),
  141. 'job_name' => array('job_name')
  142. ),
  143. 'primary key' => array('job_id'),
  144. );
  145. return $schema;
  146. }
  147. /**
  148. * Describes the Tripal Custom Tables (tripal_custom_tables) table
  149. * This keeps track of tables created by Tripal and stored in chado that may or may not
  150. * also be materialized views.
  151. *
  152. * @ingroup tripal_core
  153. */
  154. function tripal_core_custom_tables_schema() {
  155. $schema = array();
  156. $schema['tripal_custom_tables'] = array(
  157. 'fields' => array(
  158. 'table_id' => array('type' => 'serial', 'unsigned' => TRUE, 'not NULL' => TRUE),
  159. 'table_name' => array('type' => 'varchar', 'length' => 255, 'not NULL' => TRUE),
  160. 'schema' => array('type' => 'text', 'not NULL' => TRUE),
  161. ),
  162. 'indexes' => array(
  163. 'table_id' => array('table_id'),
  164. ),
  165. 'primary key' => array('table_id'),
  166. );
  167. return $schema;
  168. }