tripal_core.install 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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 = file_directory_path() . "/tripal";
  14. if (!file_check_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. // create the tables that manage materialized views and jobs
  22. drupal_install_schema('tripal_core');
  23. }
  24. /**
  25. * Update for Drupal 6.x, Tripal 0.4
  26. * This update
  27. * - adjusts the materialized view by adding status, comment and mv_schema columns
  28. * - changes the specs of mv_table, mv_specs and indexed
  29. * - creates the tripal_custom_tables table
  30. *
  31. * @ingroup tripal_feature
  32. */
  33. function tripal_core_update_6000() {
  34. // add additional columsn to the tripal_mviews table
  35. db_add_field($ret, 'tripal_mviews', 'status', array('type' => 'text', 'size' => 'normal', 'not NULL' => FALSE));
  36. db_add_field($ret, 'tripal_mviews', 'comment', array('type' => 'text', 'size' => 'normal', 'not NULL' => FALSE));
  37. db_add_field($ret, 'tripal_mviews', 'mv_schema', array('type' => 'text', 'size' => 'normal', 'not NULL' => FALSE));
  38. db_change_field($ret, 'tripal_mviews', 'mv_table', 'mv_table', array('type' => 'varchar', 'length' => 128, 'not NULL' => FALSE));
  39. db_change_field($ret, 'tripal_mviews', 'mv_specs', 'mv_specs', array('type' => 'text', 'size' => 'normal', 'not NULL' => FALSE));
  40. db_change_field($ret, 'tripal_mviews', 'indexed', 'indexed', array('type' => 'text', 'size' => 'normal', 'not NULL' => FALSE));
  41. // create the custom tables table
  42. $ret = array();
  43. $schema = tripal_core_custom_tables_schema();
  44. db_create_table($ret, 'tripal_custom_tables', $schema['tripal_custom_tables']);
  45. $ret = array(
  46. '#finished' => 1,
  47. );
  48. return $ret;
  49. }
  50. /**
  51. * Implementation of hook_schema().
  52. *
  53. * @ingroup tripal_core
  54. */
  55. function tripal_core_schema() {
  56. $schema = tripal_core_get_schemas();
  57. // if this module is already installed and enabled, then we want to provide
  58. // the schemas for all of the custom tables. This will allow Views to
  59. // see the schemas. We check if the module is installed because during
  60. // installation we don't want to make these custom tables available as we don't
  61. // want them created in the Drupal database. The custom tables go in the
  62. // Chado database.
  63. $sql = 'SELECT * FROM {tripal_custom_tables}';
  64. $q = db_query($sql);
  65. while ($custom = db_fetch_object($q)) {
  66. $schema[$custom->table_name] = unserialize($custom->schema);
  67. }
  68. return $schema;
  69. }
  70. /**
  71. * Implementation of hook_uninstall().
  72. *
  73. * @ingroup tripal_core
  74. */
  75. function tripal_core_uninstall() {
  76. drupal_uninstall_schema('tripal_core');
  77. }
  78. /**
  79. * This function simply defines all tables needed for the module to work
  80. * correctly. By putting the table definitions in a separate function we
  81. * can easily provide the entire list for hook_install or individual
  82. * tables for an update.
  83. *
  84. * @ingroup tripal_core
  85. */
  86. function tripal_core_get_schemas() {
  87. $schema = array();
  88. // get all the various schema parts and join them together
  89. $temp = tripal_core_jobs_schema();
  90. foreach ($temp as $table => $arr) {
  91. $schema[$table] = $arr;
  92. }
  93. $temp = tripal_core_mviews_schema();
  94. foreach ($temp as $table => $arr) {
  95. $schema[$table] = $arr;
  96. }
  97. $temp = tripal_core_custom_tables_schema();
  98. foreach ($temp as $table => $arr) {
  99. $schema[$table] = $arr;
  100. }
  101. return $schema;
  102. }
  103. /**
  104. * Describes the Tripal Materialized View (tripal_mviews) table
  105. * This table keeps track of all materialized views created by Tripal and stored in chado
  106. *
  107. * @ingroup tripal_core
  108. */
  109. function tripal_core_mviews_schema() {
  110. $schema = array();
  111. $schema['tripal_mviews'] = array(
  112. 'fields' => array(
  113. 'mview_id' => array('type' => 'serial', 'unsigned' => TRUE, 'not NULL' => TRUE),
  114. 'name' => array('type' => 'varchar', 'length' => 255, 'not NULL' => TRUE),
  115. 'modulename' => array('type' => 'varchar', 'length' => 50, 'not NULL' => TRUE, 'description' => 'The module name that provides the callback for this job'),
  116. 'mv_table' => array('type' => 'varchar', 'length' => 128, 'not NULL' => FALSE),
  117. 'mv_specs' => array('type' => 'text', 'size' => 'normal', 'not NULL' => FALSE),
  118. 'mv_schema' => array('type' => 'text', 'size' => 'normal', 'not NULL' => FALSE),
  119. 'indexed' => array('type' => 'text', 'size' => 'normal', 'not NULL' => FALSE),
  120. 'query' => array('type' => 'text', 'size' => 'normal', 'not NULL' => TRUE),
  121. 'special_index' => array('type' => 'text', 'size' => 'normal', 'not NULL' => FALSE),
  122. 'last_update' => array('type' => 'int', 'not NULL' => FALSE, 'description' => 'UNIX integer time'),
  123. 'status' => array('type' => 'text', 'size' => 'normal', 'not NULL' => FALSE),
  124. 'comment' => array('type' => 'text', 'size' => 'normal', 'not NULL' => FALSE),
  125. ),
  126. 'indexes' => array(
  127. 'mview_id' => array('mview_id')
  128. ),
  129. 'unique keys' => array(
  130. 'mv_table' => array('mv_table'),
  131. 'mv_name' => array('name'),
  132. ),
  133. 'primary key' => array('mview_id'),
  134. );
  135. return $schema;
  136. }
  137. /**
  138. * Describes the Tripal Jobs (tripal_jobs) table
  139. * This table keeps track of all tripal jobs including their current status and is used
  140. * by tripal_launch_jobs to determine which jobs need to be run
  141. *
  142. * @ingroup tripal_core
  143. */
  144. function tripal_core_jobs_schema() {
  145. $schema = array();
  146. $schema['tripal_jobs'] = array(
  147. 'fields' => array(
  148. 'job_id' => array('type' => 'serial', 'unsigned' => TRUE, 'not NULL' => TRUE),
  149. 'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not NULL' => TRUE, 'description' => 'The Drupal userid of the submitee'),
  150. 'job_name' => array('type' => 'varchar', 'length' => 255, 'not NULL' => TRUE),
  151. 'modulename' => array('type' => 'varchar', 'length' => 50, 'not NULL' => TRUE, 'description' => 'The module name that provides the callback for this job'),
  152. 'callback' => array('type' => 'varchar', 'length' => 255, 'not NULL' => TRUE),
  153. 'arguments' => array('type' => 'text', 'size' => 'normal', 'not NULL' => FALSE),
  154. 'progress' => array('type' => 'int', 'unsigned' => TRUE, 'default' => 0, 'not NULL' => FALSE, 'description' => 'a value from 0 to 100 indicating percent complete'),
  155. 'status' => array('type' => 'varchar', 'length' => 50, 'not NULL' => TRUE),
  156. 'submit_date' => array('type' => 'int', 'not NULL' => TRUE, 'description' => 'UNIX integer submit time'),
  157. 'start_time' => array('type' => 'int', 'not NULL' => FALSE, 'description' => 'UNIX integer start time'),
  158. 'end_time' => array('type' => 'int', 'not NULL' => FALSE, 'description' => 'UNIX integer end time'),
  159. 'error_msg' => array('type' => 'text', 'size' => 'normal', 'not NULL' => FALSE),
  160. 'pid' => array('type' => 'int', 'unsigned' => TRUE, 'not NULL' => FALSE, 'description' => 'The process id for the job'),
  161. 'priority' => array('type' => 'int', 'unsigned' => TRUE, 'not NULL' => TRUE, 'default' => '0', 'description' => 'The job priority'),
  162. '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'),
  163. 'lock' => array('type' => 'int', 'unsigned' => TRUE, 'not NULL' => FALSE, 'description' => 'If set to 1 then all jobs are held until this one finishes'),
  164. ),
  165. 'indexes' => array(
  166. 'job_id' => array('job_id'),
  167. 'job_name' => array('job_name')
  168. ),
  169. 'primary key' => array('job_id'),
  170. );
  171. return $schema;
  172. }
  173. /**
  174. * Describes the Tripal Custom Tables (tripal_custom_tables) table
  175. * This keeps track of tables created by Tripal and stored in chado that may or may not
  176. * also be materialized views.
  177. *
  178. * @ingroup tripal_core
  179. */
  180. function tripal_core_custom_tables_schema() {
  181. $schema = array();
  182. $schema['tripal_custom_tables'] = array(
  183. 'fields' => array(
  184. 'table_id' => array('type' => 'serial', 'unsigned' => TRUE, 'not NULL' => TRUE),
  185. 'table_name' => array('type' => 'varchar', 'length' => 255, 'not NULL' => TRUE),
  186. 'schema' => array('type' => 'text', 'not NULL' => TRUE),
  187. ),
  188. 'indexes' => array(
  189. 'table_id' => array('table_id'),
  190. ),
  191. 'primary key' => array('table_id'),
  192. );
  193. return $schema;
  194. }