tripal_core.install 4.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 tables that manage materialized views and jobs
  16. drupal_install_schema('tripal_core');
  17. }
  18. /************************************************************************
  19. * Implementation of hook_schema().
  20. */
  21. function tripal_core_schema() {
  22. $schema = tripal_core_get_schemas();
  23. return $schema;
  24. }
  25. /************************************************************************
  26. * Implementation of hook_uninstall()
  27. */
  28. function tripal_core_uninstall(){
  29. drupal_uninstall_schema('tripal_core');
  30. }
  31. /************************************************************************
  32. * This function simply defines all tables needed for the module to work
  33. * correctly. By putting the table definitions in a separate function we
  34. * can easily provide the entire list for hook_install or individual
  35. * tables for an update.
  36. */
  37. function tripal_core_get_schemas (){
  38. $schema = array();
  39. $schema['tripal_jobs'] = array(
  40. 'fields' => array(
  41. 'job_id' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
  42. 'uid' => array ('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'description' => 'The Drupal userid of the submitee'),
  43. 'job_name' => array('type' => 'varchar','length' => 255, 'not null' => TRUE),
  44. 'modulename' => array('type' => 'varchar','length' => 50, 'not null' => TRUE, 'description' => 'The module name that provides the callback for this job'),
  45. 'callback' => array('type' => 'varchar','length' => 255, 'not null' => TRUE),
  46. 'arguments' => array('type' => 'text', 'size' => 'normal', 'not null' => FALSE),
  47. 'progress' => array('type' => 'int', 'unsigned' => TRUE, 'default' => 0, 'not null' => FALSE, 'description' => 'a value from 0 to 100 indicating percent complete'),
  48. 'status' => array('type' => 'varchar','length' => 50, 'not null' => TRUE),
  49. 'submit_date' => array ('type' => 'int', 'not null' => TRUE, 'description' => 'UNIX integer submit time'),
  50. 'start_time' => array ('type' => 'int', 'not null' => FALSE, 'description' => 'UNIX integer start time'),
  51. 'end_time' => array ('type' => 'int', 'not null' => FALSE, 'description' => 'UNIX integer end time'),
  52. 'error_msg' => array('type' => 'text','size' => 'normal', 'not null' => FALSE),
  53. 'pid' => array ('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'description' => 'The process id for the job'),
  54. 'priority' => array ('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => '0', 'description' => 'The job priority'),
  55. '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'),
  56. 'lock' => array ('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'description' => 'If set to 1 then all jobs are held until this one finishes'),
  57. ),
  58. 'indexes' => array(
  59. 'job_id' => array('job_id'),
  60. 'job_name' => array('job_name')
  61. ),
  62. 'primary key' => array('job_id'),
  63. );
  64. $schema['tripal_mviews'] = array(
  65. 'fields' => array(
  66. 'mview_id' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
  67. 'name' => array('type' => 'varchar','length' => 255, 'not null' => TRUE),
  68. 'modulename' => array('type' => 'varchar','length' => 50, 'not null' => TRUE, 'description' => 'The module name that provides the callback for this job'),
  69. 'mv_table' => array('type' => 'varchar','length' => 128, 'not null' => TRUE),
  70. 'mv_specs' => array('type' => 'text', 'size' => 'normal', 'not null' => TRUE),
  71. 'indexed' => array('type' => 'text', 'size' => 'normal', 'not null' => TRUE),
  72. 'query' => array('type' => 'text', 'size' => 'normal', 'not null' => TRUE),
  73. 'special_index' => array('type' => 'text', 'size' => 'normal', 'not null' => FALSE),
  74. 'last_update' => array ('type' => 'int', 'not null' => FALSE, 'description' => 'UNIX integer time'),
  75. ),
  76. 'indexes' => array(
  77. 'mview_id' => array('mview_id')
  78. ),
  79. 'unique keys' => array(
  80. 'mv_table' => array('mv_table'),
  81. 'mv_name' => array('name'),
  82. ),
  83. 'primary key' => array('mview_id'),
  84. );
  85. return $schema;
  86. }
  87. ?>