tripal_core.install 8.5 KB

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