tripal_core.install 7.9 KB

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