tripal_ds.install 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * @file
  4. * Fieldgroup module install file.
  5. */
  6. /**
  7. * Implements hook_schema().
  8. */
  9. function tripal_ds_schema() {
  10. $schema['tripal_ds'] = array(
  11. 'description' => t('Table that contains the Tripal Pane fieldsets.'),
  12. 'fields' => array(
  13. 'id' => array(
  14. 'type' => 'serial',
  15. 'not null' => TRUE,
  16. 'description' => 'The primary identifier for a group',
  17. 'no export' => TRUE,
  18. ),
  19. 'tripal_ds_field_label' => array(
  20. 'type' => 'varchar',
  21. 'length' => 255,
  22. 'not null' => TRUE,
  23. 'default' => '',
  24. 'description' => 'The label of this Tripal Pane.',
  25. ),
  26. 'tripal_ds_field_name' => array(
  27. 'type' => 'varchar',
  28. 'length' => 255,
  29. 'not null' => TRUE,
  30. 'default' => '',
  31. 'description' => 'The name of this Tripal Pane.',
  32. ),
  33. 'bundle' => array(
  34. 'type' => 'varchar',
  35. 'length' => 128,
  36. 'not null' => TRUE,
  37. 'default' => ''
  38. ),
  39. 'weight' => array(
  40. 'type' => 'int',
  41. 'not null' => TRUE,
  42. 'default' => 1,
  43. ),
  44. ),
  45. 'primary key' => array('id'),
  46. );
  47. return $schema;
  48. }
  49. /**
  50. * Implements hook_disable().
  51. */
  52. function tripal_ds_disable(){
  53. //Check if any tripal panes currently exist.
  54. //Grab all the bundles to cycle through them.
  55. $entities_with_tripal_panes = array();
  56. $bundles = db_select('tripal_bundle', 'tb')
  57. ->fields('tb')
  58. ->execute()
  59. ->fetchAll();
  60. foreach($bundles as $bundles => $bundle){
  61. $field_groups = field_group_info_groups('TripalEntity', $bundle->name);
  62. foreach($field_groups['default'] as $field_names => $field_name){
  63. if($field_name->format_type == 'tripalpane'){
  64. array_push($entities_with_tripal_panes, $bundle->label);
  65. continue 2;
  66. }
  67. }
  68. }
  69. $output = 'You have disabled the Tripal DS module but Tripal Panes were found in the following Content Types: ';
  70. $output .= '<ul>';
  71. foreach ($entities_with_tripal_panes as $item) {
  72. $output .= '<li> ' . $item . '</li>';
  73. }
  74. $output .= '</ul>';
  75. if(!empty($entities_with_tripal_panes)){
  76. drupal_set_message($output, 'warning');
  77. }
  78. }
  79. /**
  80. * Add a weight column to the tripal_ds table.
  81. */
  82. function tripal_ds_update_7300() {
  83. try {
  84. db_add_field('tripal_ds', 'weight', array(
  85. 'type' => 'int',
  86. 'not null' => TRUE,
  87. 'default' => 1,
  88. ));
  89. }
  90. catch (\PDOException $e) {
  91. $transaction->rollback();
  92. $error = $e->getMessage();
  93. throw new DrupalUpdateException('Could not perform update: '. $error);
  94. }
  95. }