tripal_project.install 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. }
  114. /**
  115. * This is the required update for tripal_project when upgrading from Drupal core API 6.x.
  116. *
  117. * @ingroup tripal_project
  118. */
  119. function tripal_project_update_7000() {
  120. // add the project_property CV
  121. try {
  122. $check = db_query("SELECT cv_id FROM chado.cv WHERE name = 'project_property'")->fetchObject();
  123. if (!$check->cv_id) {
  124. $sql = "INSERT INTO chado.cv (name, definition) VALUES (
  125. 'project_property','Contains properties for projects.')
  126. ";
  127. db_query($sql);
  128. }
  129. }
  130. catch (\PDOException $e) {
  131. $error = $e->getMessage();
  132. throw new DrupalUpdateException('Failed to add project_property vocabulary: '. $error);
  133. }
  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. // We cannot use the Tripal API calls'because during upgrade the tripal_core
  139. // should also be disabled
  140. $sql = "
  141. UPDATE chado.cvterm CVT
  142. SET
  143. name = 'Project Description',
  144. cv_id = (SELECT cv_id FROM chado.cv WHERE name = 'project_property')
  145. WHERE
  146. name = 'project_description' AND
  147. cv_id = (SELECT cv_id FROM chado.cv WHERE name = 'tripal')
  148. ";
  149. try {
  150. db_query($sql);
  151. }
  152. catch (\PDOException $e) {
  153. $error = $e->getMessage();
  154. throw new DrupalUpdateException('Failed to change project_description property type to the project_property CV and update the name: '. $error);
  155. }
  156. }