tripal_core.install 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. return $schema;
  57. }
  58. /************************************************************************
  59. *
  60. *
  61. * @ingroup tripal_core
  62. */
  63. function tripal_core_mviews_schema(){
  64. $schema = array();
  65. $schema['tripal_mviews'] = array(
  66. 'fields' => array(
  67. 'mview_id' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
  68. 'name' => array('type' => 'varchar','length' => 255, 'not null' => TRUE),
  69. 'modulename' => array('type' => 'varchar','length' => 50, 'not null' => TRUE, 'description' => 'The module name that provides the callback for this job'),
  70. 'mv_table' => array('type' => 'varchar','length' => 128, 'not null' => TRUE),
  71. 'mv_specs' => array('type' => 'text', 'size' => 'normal', 'not null' => TRUE),
  72. 'indexed' => array('type' => 'text', 'size' => 'normal', 'not null' => TRUE),
  73. 'query' => array('type' => 'text', 'size' => 'normal', 'not null' => TRUE),
  74. 'special_index' => array('type' => 'text', 'size' => 'normal', 'not null' => FALSE),
  75. 'last_update' => array('type' => 'int', 'not null' => FALSE, 'description' => 'UNIX integer time'),
  76. ),
  77. 'indexes' => array(
  78. 'mview_id' => array('mview_id')
  79. ),
  80. 'unique keys' => array(
  81. 'mv_table' => array('mv_table'),
  82. 'mv_name' => array('name'),
  83. ),
  84. 'primary key' => array('mview_id'),
  85. );
  86. return $schema;
  87. }
  88. /************************************************************************
  89. *
  90. *
  91. * @ingroup tripal_core
  92. */
  93. function tripal_core_jobs_schema(){
  94. $schema = array();
  95. $schema['tripal_jobs'] = array(
  96. 'fields' => array(
  97. 'job_id' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
  98. 'uid' => array ('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'description' => 'The Drupal userid of the submitee'),
  99. 'job_name' => array('type' => 'varchar','length' => 255, 'not null' => TRUE),
  100. 'modulename' => array('type' => 'varchar','length' => 50, 'not null' => TRUE, 'description' => 'The module name that provides the callback for this job'),
  101. 'callback' => array('type' => 'varchar','length' => 255, 'not null' => TRUE),
  102. 'arguments' => array('type' => 'text', 'size' => 'normal', 'not null' => FALSE),
  103. 'progress' => array('type' => 'int', 'unsigned' => TRUE, 'default' => 0, 'not null' => FALSE, 'description' => 'a value from 0 to 100 indicating percent complete'),
  104. 'status' => array('type' => 'varchar','length' => 50, 'not null' => TRUE),
  105. 'submit_date' => array ('type' => 'int', 'not null' => TRUE, 'description' => 'UNIX integer submit time'),
  106. 'start_time' => array ('type' => 'int', 'not null' => FALSE, 'description' => 'UNIX integer start time'),
  107. 'end_time' => array ('type' => 'int', 'not null' => FALSE, 'description' => 'UNIX integer end time'),
  108. 'error_msg' => array('type' => 'text','size' => 'normal', 'not null' => FALSE),
  109. 'pid' => array ('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'description' => 'The process id for the job'),
  110. 'priority' => array ('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => '0', 'description' => 'The job priority'),
  111. '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'),
  112. 'lock' => array ('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'description' => 'If set to 1 then all jobs are held until this one finishes'),
  113. ),
  114. 'indexes' => array(
  115. 'job_id' => array('job_id'),
  116. 'job_name' => array('job_name')
  117. ),
  118. 'primary key' => array('job_id'),
  119. );
  120. return $schema;
  121. }
  122. ?>