tripal_core.install 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /************************************************************************
  3. * Implementation of hook_install();
  4. */
  5. function tripal_core_install(){
  6. // make the data directory for this module
  7. $data_dir = file_directory_path() . "/tripal";
  8. if(!file_check_directory($data_dir,FILE_CREATE_DIRECTORY)){
  9. $message = "Cannot create directory $data_dir. This module may not ".
  10. "behave correctly without this directory. Please create ".
  11. "the directory manually or fix the problem and reinstall.";
  12. drupal_set_message($message,'error');
  13. watchdog('tripal_core',$message,array(),WATCHDOG_ERROR);
  14. }
  15. // create the 'tripal' controlled volcabulary in chado but only if it doesn't already exist
  16. $previous_db = db_set_active('chado'); // use chado database
  17. if(!db_fetch_object(db_query("SELECT * FROM {cv} WHERE name = 'tripal'"))){
  18. $results = db_query("INSERT INTO {cv} (name,definition) ".
  19. "VALUES ('tripal','Terms used by Tripal for modules to manage data such as that stored in property tables like featureprop, analysisprop, etc')");
  20. }
  21. if(!db_fetch_object(db_query("SELECT * FROM {db} WHERE name = 'tripal'"))){
  22. $results = db_query("INSERT INTO {db} (name,description) ".
  23. "VALUES ('tripal','Used as a database placeholder for tripal defined objects such as tripal cvterms')");
  24. }
  25. db_set_active($previous_db); // now use drupal database
  26. // create the tables that manage materialized views and jobs
  27. drupal_install_schema('tripal_core');
  28. }
  29. /************************************************************************
  30. * Implementation of hook_schema().
  31. */
  32. function tripal_core_schema() {
  33. $schema = tripal_core_get_schemas();
  34. return $schema;
  35. }
  36. /************************************************************************
  37. * Implementation of hook_uninstall()
  38. */
  39. function tripal_core_uninstall(){
  40. drupal_uninstall_schema('tripal_core');
  41. }
  42. /************************************************************************
  43. * This function simply defines all tables needed for the module to work
  44. * correctly. By putting the table definitions in a separate function we
  45. * can easily provide the entire list for hook_install or individual
  46. * tables for an update.
  47. */
  48. function tripal_core_get_schemas (){
  49. $schema = array();
  50. $schema['tripal_jobs'] = array(
  51. 'fields' => array(
  52. 'job_id' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
  53. 'uid' => array ('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'description' => 'The Drupal userid of the submitee'),
  54. 'job_name' => array('type' => 'varchar','length' => 255, 'not null' => TRUE),
  55. 'modulename' => array('type' => 'varchar','length' => 50, 'not null' => TRUE, 'description' => 'The module name that provides the callback for this job'),
  56. 'callback' => array('type' => 'varchar','length' => 255, 'not null' => TRUE),
  57. 'arguments' => array('type' => 'text', 'size' => 'normal', 'not null' => FALSE),
  58. 'progress' => array('type' => 'int', 'unsigned' => TRUE, 'default' => 0, 'not null' => FALSE, 'description' => 'a value from 0 to 100 indicating percent complete'),
  59. 'status' => array('type' => 'varchar','length' => 50, 'not null' => TRUE),
  60. 'submit_date' => array ('type' => 'int', 'not null' => TRUE, 'description' => 'UNIX integer submit time'),
  61. 'start_time' => array ('type' => 'int', 'not null' => FALSE, 'description' => 'UNIX integer start time'),
  62. 'end_time' => array ('type' => 'int', 'not null' => FALSE, 'description' => 'UNIX integer end time'),
  63. 'error_msg' => array('type' => 'text','size' => 'normal', 'not null' => FALSE),
  64. 'pid' => array ('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'description' => 'The process id for the job'),
  65. 'priority' => array ('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => '0', 'description' => 'The job priority'),
  66. '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'),
  67. 'lock' => array ('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'description' => 'If set to 1 then all jobs are held until this one finishes'),
  68. ),
  69. 'indexes' => array(
  70. 'job_id' => array('job_id'),
  71. 'job_name' => array('job_name')
  72. ),
  73. 'primary key' => array('job_id'),
  74. );
  75. $schema['tripal_mviews'] = array(
  76. 'fields' => array(
  77. 'mview_id' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
  78. 'name' => array('type' => 'varchar','length' => 255, 'not null' => TRUE),
  79. 'modulename' => array('type' => 'varchar','length' => 50, 'not null' => TRUE, 'description' => 'The module name that provides the callback for this job'),
  80. 'mv_table' => array('type' => 'varchar','length' => 128, 'not null' => TRUE),
  81. 'mv_specs' => array('type' => 'text', 'size' => 'normal', 'not null' => TRUE),
  82. 'indexed' => array('type' => 'text', 'size' => 'normal', 'not null' => TRUE),
  83. 'query' => array('type' => 'text', 'size' => 'normal', 'not null' => TRUE),
  84. 'special_index' => array('type' => 'text', 'size' => 'normal', 'not null' => FALSE),
  85. 'last_update' => array ('type' => 'int', 'not null' => FALSE, 'description' => 'UNIX integer time'),
  86. ),
  87. 'indexes' => array(
  88. 'mview_id' => array('mview_id')
  89. ),
  90. 'unique keys' => array(
  91. 'mv_table' => array('mv_table'),
  92. 'mv_name' => array('name'),
  93. ),
  94. 'primary key' => array('mview_id'),
  95. );
  96. return $schema;
  97. }
  98. ?>