tripal_core.install 8.6 KB

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