tripal_stock.install

  1. 2.x tripal_stock/tripal_stock.install
  2. 3.x legacy/tripal_stock/tripal_stock.install
  3. 1.x tripal_stock/tripal_stock.install

Install the tripal stock module including it's content type

File

tripal_stock/tripal_stock.install
View source
  1. <?php
  2. /**
  3. * Install the tripal stock module including it's content type
  4. * @file
  5. */
  6. /**
  7. * Implementation of hook_install().
  8. */
  9. function tripal_stock_install() {
  10. // create the module's data directory
  11. tripal_create_moddir('tripal_stock');
  12. // create the stock tables
  13. drupal_install_schema('tripal_stock');
  14. }
  15. /**
  16. * Implementation of hook_uninstall().
  17. */
  18. function tripal_stock_uninstall() {
  19. drupal_uninstall_schema('tripal_stock');
  20. // Get the list of nodes to remove
  21. $sql_lib_id = "SELECT nid, vid ".
  22. "FROM {node} ".
  23. "WHERE type='chado_stock'";
  24. $result = db_query($sql_lib_id);
  25. //delete all nodes
  26. while ($node = db_fetch_object($result)) {
  27. node_delete($node->nid);
  28. }
  29. }
  30. /**
  31. * Implementation of hook_schema().
  32. */
  33. function tripal_stock_schema() {
  34. $schema['chado_stock'] = array(
  35. 'fields' => array(
  36. 'vid' => array(
  37. 'type' => 'int',
  38. 'unsigned' => TRUE,
  39. 'not null' => TRUE,
  40. ),
  41. 'nid' => array(
  42. 'type' => 'int',
  43. 'unsigned' => TRUE,
  44. 'not null' => TRUE,
  45. ),
  46. 'stock_id' => array(
  47. 'type' => 'int',
  48. 'unsigned' => TRUE,
  49. 'not null' => TRUE,
  50. ),
  51. ),
  52. 'indexes' => array(
  53. 'stock_id' => array('stock_id'),
  54. 'nid' => array('nid'),
  55. ),
  56. 'unique' => array(
  57. 'stock_id' => array('stock_id'),
  58. ),
  59. 'primary key' => array('vid'),
  60. );
  61. return $schema;
  62. }
  63. /**
  64. * Implementation of hook_requirements().
  65. *
  66. */
  67. function tripal_stock_requirements($phase) {
  68. $requirements = array();
  69. if ($phase == 'install') {
  70. // make sure chado is installed
  71. if (!tripal_core_is_chado_installed()) {
  72. $requirements ['tripal_stock'] = array(
  73. 'title' => "tripal_stock",
  74. 'value' => "ERROR: Chado most be installed before this module can be enabled",
  75. 'severity' => REQUIREMENT_ERROR,
  76. );
  77. }
  78. }
  79. return $requirements;
  80. }