tripal_project.install 4.0 KB

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