tripal_project.install 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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_cvs();
  47. tripal_project_add_cvterms();
  48. }
  49. /**
  50. * Implementation of hook_uninstall().
  51. */
  52. function tripal_project_uninstall() {
  53. }
  54. /**
  55. * Implementation of hook_schema().
  56. */
  57. function tripal_project_schema() {
  58. $schema['chado_project'] = array(
  59. 'fields' => array(
  60. 'nid' => array(
  61. 'type' => 'int',
  62. 'unsigned' => TRUE,
  63. 'not null' => TRUE,
  64. ),
  65. 'vid' => array(
  66. 'type' => 'int',
  67. 'not null' => TRUE,
  68. ),
  69. 'project_id' => array(
  70. 'type' => 'int',
  71. 'unsigned' => TRUE,
  72. 'not null' => TRUE,
  73. ),
  74. ),
  75. 'primary key' => array('nid', 'vid', 'project_id'),
  76. );
  77. return $schema;
  78. }
  79. /**
  80. *
  81. */
  82. function tripal_project_add_cvs() {
  83. tripal_cv_add_cv('project_property', 'Contains properties for projects');
  84. // Add cv for relationship types
  85. tripal_cv_add_cv(
  86. 'project_relationship_types',
  87. 'Contains Types of relationships between projects.'
  88. );
  89. }
  90. /**
  91. *
  92. */
  93. function tripal_project_add_cvterms() {
  94. // Insert cvterm 'Project Description' into cvterm table of chado
  95. // database. This CV term is used to keep track of the project
  96. // description in the projectprop table.
  97. tripal_cv_add_cvterm(
  98. array(
  99. 'name' => 'Project Description',
  100. 'def' => 'Description of a project'
  101. ),
  102. 'project_property', 0, 1, 'tripal'
  103. );
  104. tripal_cv_add_cvterm(
  105. array(
  106. 'name' => 'Project Type',
  107. 'def' => 'The short few word description of the type of project.'
  108. ),
  109. 'project_property', 0, 1, 'tripal'
  110. );
  111. tripal_cv_add_cvterm(
  112. array(
  113. 'name' => 'Funding Source',
  114. 'def' => 'The funding source for this project.'
  115. ),
  116. 'project_property', 0, 1, 'tripal'
  117. );
  118. }
  119. /**
  120. * This is the required update for tripal_project when upgrading from Drupal core API 6.x.
  121. */
  122. function tripal_project_update_7000() {
  123. // For Tripal in Drupal 6 the project_description cvterm was stored in the
  124. // 'tripal' CV. It should be stored in the new project_property CV that
  125. // is added by this module for Tripal 2.0 and Drupal 7. So, we need to
  126. // reset the CV ID for that term and rename the term to 'Project Description'
  127. tripal_project_add_cvs();
  128. $cv = tripal_cv_get_cv_by_name('project_property');
  129. $cvterm = tripal_cv_get_cvterm_by_name('project_description', $cv->cv_id);
  130. $match = array(
  131. 'cvterm_id' => $cvterm->cvterm_id,
  132. );
  133. $values = array(
  134. 'name' => 'Project Description',
  135. );
  136. tripal_core_chado_update('cvterm', $match, $values);
  137. if (!$success) {
  138. throw new DrupalUpdateException('Failed to move project properties to new project_property CV.');
  139. }
  140. // add in new CVterms
  141. tripal_project_add_cvterms();
  142. }