tripal_project.install 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. /**
  3. * @file
  4. * This file contains all the functions which describe and implement drupal database tables
  5. * needed by this module. This module was developed by Chad N.A. Krilow and Lacey-Anne Sanderson,
  6. * University of Saskatchewan.
  7. *
  8. * The project manamgenet module allows you to sync data in a chado/Tripal instance with
  9. * multiple project/mysql instances as well as manage and create such project instances
  10. */
  11. /**
  12. * Disable default views when module is disabled
  13. */
  14. function tripal_project_disable() {
  15. // Disable all default views provided by this module
  16. require_once("tripal_project.views_default.inc");
  17. $views = tripal_project_views_default_views();
  18. foreach (array_keys($views) as $view_name) {
  19. tripal_views_admin_disable_view($view_name,FALSE,array('suppress_error' => TRUE));
  20. }
  21. }
  22. /**
  23. * Implementation of hook_requirements().
  24. *
  25. */
  26. function tripal_project_requirements($phase) {
  27. $requirements = array();
  28. if ($phase == 'install') {
  29. // make sure chado is installed
  30. if (!$GLOBALS["chado_is_installed"]) {
  31. $requirements ['tripal_project'] = array(
  32. 'title' => "tripal_project",
  33. 'value' => "ERROR: Chado must be installed before this module can be enabled",
  34. 'severity' => REQUIREMENT_ERROR,
  35. );
  36. }
  37. }
  38. return $requirements;
  39. }
  40. /**
  41. * Implementation of hook_install().
  42. */
  43. function tripal_project_install() {
  44. // create the module's data directory
  45. tripal_create_moddir('tripal_project');
  46. tripal_project_add_cvterms();
  47. }
  48. /**
  49. * Implementation of hook_uninstall().
  50. */
  51. function tripal_project_uninstall() {
  52. }
  53. /**
  54. * Implementation of hook_schema().
  55. */
  56. function tripal_project_schema() {
  57. $schema['chado_project'] = array(
  58. 'fields' => array(
  59. 'nid' => array(
  60. 'type' => 'int',
  61. 'unsigned' => TRUE,
  62. 'not null' => TRUE,
  63. ),
  64. 'vid' => array(
  65. 'type' => 'int',
  66. 'not null' => TRUE,
  67. ),
  68. 'project_id' => array(
  69. 'type' => 'int',
  70. 'unsigned' => TRUE,
  71. 'not null' => TRUE,
  72. ),
  73. ),
  74. 'primary key' => array('nid', 'vid', 'project_id'),
  75. );
  76. return $schema;
  77. }
  78. /**
  79. *
  80. */
  81. function tripal_project_add_cvs() {
  82. tripal_cv_add_cv('project_property', 'Contains properties for projects');
  83. }
  84. /**
  85. *
  86. */
  87. function tripal_project_add_cvterms() {
  88. // Insert cvterm 'Project Description' into cvterm table of chado
  89. // database. This CV term is used to keep track of the project
  90. // description in the projectprop table.
  91. tripal_cv_add_cvterm(
  92. array(
  93. 'name' => 'Project Description',
  94. 'def' => 'Description of a project'
  95. ),
  96. 'project_property', 0, 1, 'tripal'
  97. );
  98. tripal_cv_add_cvterm(
  99. array(
  100. 'name' => 'Project Type',
  101. 'def' => 'The short few word description of the type of project.'
  102. ),
  103. 'project_property', 0, 1, 'tripal'
  104. );
  105. tripal_cv_add_cvterm(
  106. array(
  107. 'name' => 'Funding Source',
  108. 'def' => 'The funding source for this project.'
  109. ),
  110. 'project_property', 0, 1, 'tripal'
  111. );
  112. }
  113. /**
  114. * This is the required update for tripal_project when upgrading from Drupal core API 6.x.
  115. */
  116. function tripal_project_update_7000() {
  117. // For Tripal in Drupal 6 the project_description cvterm was stored in the
  118. // 'tripal' CV. It should be stored in the new project_property CV that
  119. // is added by this module for Tripal 2.0 and Drupal 7. So, we need to
  120. // reset the CV ID for that term and rename the term to 'Project Description'
  121. tripal_project_add_cvs();
  122. $cv = tripal_cv_get_cv_by_name('project_property');
  123. $cvterm = tripal_cv_get_cvterm_by_name('project_description', $cv->cv_id);
  124. $match = array(
  125. 'cvterm_id' => $cvterm->cvterm_id,
  126. );
  127. $values = array(
  128. 'name' => 'Project Description',
  129. );
  130. tripal_core_chado_update('cvterm', $match, $values);
  131. if (!$success) {
  132. throw new DrupalUpdateException('Failed to move project properties to new project_property CV.');
  133. }
  134. // add in new CVterms
  135. tripal_project_add_cvterms();
  136. }