tripal_core.install 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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. * Implementation of hook_schema().
  22. *
  23. * @ingroup tripal_core
  24. */
  25. function tripal_core_schema() {
  26. $schema = tripal_core_get_schemas();
  27. return $schema;
  28. }
  29. /************************************************************************
  30. * Implementation of hook_uninstall()
  31. *
  32. * @ingroup tripal_core
  33. */
  34. function tripal_core_uninstall(){
  35. drupal_uninstall_schema('tripal_core');
  36. }
  37. /************************************************************************
  38. * This function simply defines all tables needed for the module to work
  39. * correctly. By putting the table definitions in a separate function we
  40. * can easily provide the entire list for hook_install or individual
  41. * tables for an update.
  42. *
  43. * @ingroup tripal_core
  44. */
  45. function tripal_core_get_schemas (){
  46. $schema = array();
  47. // get all the various schema parts and join them together
  48. $temp = tripal_core_jobs_schema();
  49. foreach ($temp as $table => $arr){
  50. $schema[$table] = $arr;
  51. }
  52. $temp = tripal_core_mviews_schema();
  53. foreach ($temp as $table => $arr){
  54. $schema[$table] = $arr;
  55. }
  56. $temp = tripal_core_views_schema();
  57. foreach ($temp as $table => $arr){
  58. $schema[$table] = $arr;
  59. }
  60. return $schema;
  61. }
  62. /************************************************************************
  63. *
  64. *
  65. * @ingroup tripal_core
  66. */
  67. function tripal_core_mviews_schema(){
  68. $schema = array();
  69. $schema['tripal_mviews'] = array(
  70. 'fields' => array(
  71. 'mview_id' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
  72. 'name' => array('type' => 'varchar','length' => 255, 'not null' => TRUE),
  73. 'modulename' => array('type' => 'varchar','length' => 50, 'not null' => TRUE, 'description' => 'The module name that provides the callback for this job'),
  74. 'mv_table' => array('type' => 'varchar','length' => 128, 'not null' => TRUE),
  75. 'mv_specs' => array('type' => 'text', 'size' => 'normal', 'not null' => TRUE),
  76. 'indexed' => array('type' => 'text', 'size' => 'normal', 'not null' => TRUE),
  77. 'query' => array('type' => 'text', 'size' => 'normal', 'not null' => TRUE),
  78. 'special_index' => array('type' => 'text', 'size' => 'normal', 'not null' => FALSE),
  79. 'last_update' => array('type' => 'int', 'not null' => FALSE, 'description' => 'UNIX integer time'),
  80. ),
  81. 'indexes' => array(
  82. 'mview_id' => array('mview_id')
  83. ),
  84. 'unique keys' => array(
  85. 'mv_table' => array('mv_table'),
  86. 'mv_name' => array('name'),
  87. ),
  88. 'primary key' => array('mview_id'),
  89. );
  90. return $schema;
  91. }
  92. /************************************************************************
  93. *
  94. *
  95. * @ingroup tripal_core
  96. */
  97. function tripal_core_jobs_schema(){
  98. $schema = array();
  99. $schema['tripal_jobs'] = array(
  100. 'fields' => array(
  101. 'job_id' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
  102. 'uid' => array ('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'description' => 'The Drupal userid of the submitee'),
  103. 'job_name' => array('type' => 'varchar','length' => 255, 'not null' => TRUE),
  104. 'modulename' => array('type' => 'varchar','length' => 50, 'not null' => TRUE, 'description' => 'The module name that provides the callback for this job'),
  105. 'callback' => array('type' => 'varchar','length' => 255, 'not null' => TRUE),
  106. 'arguments' => array('type' => 'text', 'size' => 'normal', 'not null' => FALSE),
  107. 'progress' => array('type' => 'int', 'unsigned' => TRUE, 'default' => 0, 'not null' => FALSE, 'description' => 'a value from 0 to 100 indicating percent complete'),
  108. 'status' => array('type' => 'varchar','length' => 50, 'not null' => TRUE),
  109. 'submit_date' => array ('type' => 'int', 'not null' => TRUE, 'description' => 'UNIX integer submit time'),
  110. 'start_time' => array ('type' => 'int', 'not null' => FALSE, 'description' => 'UNIX integer start time'),
  111. 'end_time' => array ('type' => 'int', 'not null' => FALSE, 'description' => 'UNIX integer end time'),
  112. 'error_msg' => array('type' => 'text','size' => 'normal', 'not null' => FALSE),
  113. 'pid' => array ('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'description' => 'The process id for the job'),
  114. 'priority' => array ('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => '0', 'description' => 'The job priority'),
  115. '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'),
  116. 'lock' => array ('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'description' => 'If set to 1 then all jobs are held until this one finishes'),
  117. ),
  118. 'indexes' => array(
  119. 'job_id' => array('job_id'),
  120. 'job_name' => array('job_name')
  121. ),
  122. 'primary key' => array('job_id'),
  123. );
  124. return $schema;
  125. }
  126. /************************************************************************
  127. *
  128. *
  129. * @ingroup tripal_core
  130. */
  131. function tripal_core_views_schema(){
  132. $schema = array();
  133. $schema['tripal_views'] = array(
  134. 'description' => 'contains the setupes, their materialized view id and base table name that was used.',
  135. 'fields' => array(
  136. 'setup_id' => array(
  137. 'description' => 'the id of the setup',
  138. 'type' => 'serial',
  139. 'unsigned' => TRUE,
  140. 'not null' => TRUE,
  141. ),
  142. 'mview_id' => array(
  143. 'description' => 'the materialized view used for this setup',
  144. 'type' => 'int',
  145. 'unsigned' => TRUE,
  146. ),
  147. 'table_name' => array(
  148. 'description' => 'the base table name to be used when using this setup. Use this field when not using a materialized view',
  149. 'type' => 'varchar',
  150. 'length' => 255,
  151. 'not null' => TRUE,
  152. 'default' => '',
  153. ),
  154. 'name' => array(
  155. 'description' => 'Human readable name of this setup',
  156. 'type' => 'varchar',
  157. 'length' => 255,
  158. 'not null' => TRUE,
  159. 'default' => '',
  160. ),
  161. 'comment' => array(
  162. 'description' => 'add notes about this views setup',
  163. 'type' => 'text',
  164. 'size' => 'normal',
  165. 'not null' => FALSE,
  166. 'default' => '',
  167. ),
  168. ),
  169. 'unique_keys' => array(
  170. 'setup_id' => array('setup_id'),
  171. ),
  172. 'primary key' => array('setup_id'),
  173. );
  174. $schema['tripal_views_join'] = array(
  175. 'description' => 'coordinate the joining of tables',
  176. 'fields' => array(
  177. 'view_join_id' => array(
  178. 'description' => 'the id of the join',
  179. 'type' => 'serial',
  180. 'unsigned' => TRUE,
  181. 'not null' => TRUE,
  182. ),
  183. 'setup_id' => array(
  184. 'description' => 'setup id from tripal_views table',
  185. 'type' => 'int',
  186. 'unsigned' => TRUE,
  187. 'not null'=> TRUE,
  188. ),
  189. 'base_table' => array(
  190. 'description' => 'the name of the base table',
  191. 'type' => 'varchar',
  192. 'length' => '255',
  193. 'not null' => TRUE,
  194. 'default' => '',
  195. ),
  196. 'base_field' => array(
  197. 'description' => 'the name of the base table column that will be joined',
  198. 'type' => 'varchar',
  199. 'length' => '255',
  200. 'not null' => TRUE,
  201. 'default' => '',
  202. ),
  203. 'left_table' => array(
  204. 'description' => 'the table on which to perform a left join',
  205. 'type' => 'varchar',
  206. 'length' => '255',
  207. 'not null' => TRUE,
  208. 'default' => '',
  209. ),
  210. 'left_field' => array(
  211. 'description' => 'the column on which to perform a left join',
  212. 'type' => 'varchar',
  213. 'length' => '255',
  214. 'not null' => TRUE,
  215. 'default' => '',
  216. ),
  217. ),
  218. 'unique_keys' => array(
  219. 'setup_id' => array('view_join_id'),
  220. ),
  221. 'primary key' => array('view_join_id'),
  222. );
  223. $schema['tripal_views_handlers'] = array(
  224. 'description' => 'in formation for views: column and views handler name',
  225. 'fields' => array(
  226. 'handler_id' => array(
  227. 'description' => 'the id of the handler',
  228. 'type' => 'serial',
  229. 'unsigned' => TRUE,
  230. 'not null' => TRUE,
  231. ),
  232. 'setup_id' => array(
  233. 'description' => 'setup id from the tripal_views table',
  234. 'type' => 'int',
  235. 'unsigned' => TRUE,
  236. 'not null'=> TRUE,
  237. ),
  238. 'column_name' => array(
  239. 'description' => '',
  240. 'type' => 'varchar',
  241. 'length' => '255',
  242. 'not null' => TRUE,
  243. 'default' => '',
  244. ),
  245. 'handler_type' => array(
  246. 'description' => 'identifies the type of hander (e.g. field, filter, sort, argument, relationship, etc.)',
  247. 'type' => 'varchar',
  248. 'length' => '50',
  249. 'not null' => TRUE,
  250. 'default' => '',
  251. ),
  252. 'handler_name' => array(
  253. 'description' => 'the name of the handler',
  254. 'type' => 'varchar',
  255. 'length' => '255',
  256. 'not null' => TRUE,
  257. 'default' => '',
  258. ),
  259. 'arguments' => array(
  260. 'description' => 'arguments that may get passed to the handler',
  261. 'type' => 'text',
  262. 'size' => 'normal',
  263. 'not null' => FALSE,
  264. 'default' => '',
  265. ),
  266. ),
  267. 'unique_keys' => array(
  268. 'setup_id' => array('handler_id'),
  269. ),
  270. 'primary key' => array('handler_id'),
  271. );
  272. return $schema;
  273. }
  274. /************************************************************************
  275. *
  276. *
  277. * @ingroup tripal_core
  278. */
  279. function tripal_core_update_6000(){
  280. $schema = tripal_core_views_schema();
  281. $ret = array();
  282. foreach ($schema as $name => $table) {
  283. db_create_table($ret, $name, $table);
  284. }
  285. return $ret;
  286. }
  287. ?>