paragraphs.install 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the paragraphs module.
  5. */
  6. /**
  7. * Implements hook_schema().
  8. */
  9. function paragraphs_schema() {
  10. $schema = array();
  11. $schema['paragraphs_bundle'] = array(
  12. 'description' => 'Stores information about paragraphs bundles.',
  13. 'fields' => array(
  14. 'bundle' => array(
  15. 'description' => 'The machine-readable name of this bundle.',
  16. 'type' => 'varchar',
  17. 'length' => 32,
  18. 'not null' => TRUE,
  19. ),
  20. 'name' => array(
  21. 'description' => 'The human-readable name of this bundle.',
  22. 'type' => 'varchar',
  23. 'length' => 255,
  24. 'not null' => TRUE,
  25. 'default' => '',
  26. 'translatable' => TRUE,
  27. ),
  28. 'locked' => array(
  29. 'description' => 'A boolean indicating whether the administrator can change the machine name of this bundle.',
  30. 'type' => 'int',
  31. 'not null' => TRUE,
  32. 'default' => 0,
  33. 'size' => 'tiny',
  34. ),
  35. ),
  36. 'primary key' => array('bundle'),
  37. );
  38. $schema['paragraphs_item'] = array(
  39. 'description' => 'Stores information about paragraph items.',
  40. 'fields' => array(
  41. 'item_id' => array(
  42. 'type' => 'serial',
  43. 'not null' => TRUE,
  44. 'description' => 'Primary Key: Unique paragraph item ID.',
  45. ),
  46. 'revision_id' => array(
  47. 'type' => 'int',
  48. 'not null' => TRUE,
  49. 'description' => 'Default revision ID.',
  50. ),
  51. 'bundle' => array(
  52. 'description' => 'The bundle of this paragraph item.',
  53. 'type' => 'varchar',
  54. 'length' => 32,
  55. 'not null' => TRUE,
  56. ),
  57. 'field_name' => array(
  58. 'description' => 'Field name of the host entity.',
  59. 'type' => 'varchar',
  60. 'length' => 32,
  61. 'not null' => TRUE,
  62. ),
  63. 'archived' => array(
  64. 'description' => 'Boolean indicating whether the paragraph item is archived.',
  65. 'type' => 'int',
  66. 'not null' => TRUE,
  67. 'default' => 0,
  68. ),
  69. ),
  70. 'primary key' => array('item_id'),
  71. );
  72. $schema['paragraphs_item_revision'] = array(
  73. 'description' => 'Stores revision information about paragraph items.',
  74. 'fields' => array(
  75. 'revision_id' => array(
  76. 'type' => 'serial',
  77. 'not null' => TRUE,
  78. 'description' => 'Primary Key: Unique revision ID.',
  79. ),
  80. 'item_id' => array(
  81. 'type' => 'int',
  82. 'not null' => TRUE,
  83. 'description' => 'Paragraph item ID.',
  84. ),
  85. ),
  86. 'primary key' => array('revision_id'),
  87. 'indexes' => array(
  88. 'item_id' => array('item_id'),
  89. ),
  90. 'foreign keys' => array(
  91. 'versioned_paragraphs_item' => array(
  92. 'table' => 'paragraphs_item',
  93. 'columns' => array('item_id' => 'item_id'),
  94. ),
  95. ),
  96. );
  97. return $schema;
  98. }
  99. /**
  100. * Implements hook_field_schema().
  101. */
  102. function paragraphs_field_schema($field) {
  103. $columns = array();
  104. if ($field['type'] == 'paragraphs') {
  105. $columns = array(
  106. 'value' => array(
  107. 'type' => 'int',
  108. 'not null' => FALSE,
  109. 'description' => 'The paragraph item id.',
  110. ),
  111. 'revision_id' => array(
  112. 'type' => 'int',
  113. 'not null' => FALSE,
  114. 'description' => 'The paragraph item revision id.',
  115. ),
  116. );
  117. }
  118. return array(
  119. 'columns' => $columns,
  120. );
  121. }
  122. /**
  123. * Make sure all paragraph fields have the new index on revision_id.
  124. */
  125. function paragraphs_update_7100() {
  126. // Update the paragraphs_field_schema columns for all tables.
  127. foreach (field_read_fields(array('type' => 'paragraphs')) as $field) {
  128. field_update_field($field);
  129. }
  130. }
  131. /**
  132. * Make sure the entitycache table exists.
  133. */
  134. function paragraphs_update_7101() {
  135. if (module_exists('entitycache') && !db_table_exists("cache_entity_paragraphs_item")) {
  136. drupal_load('module', 'entitycache');
  137. $cache_schema = drupal_get_schema_unprocessed('system', 'cache');
  138. $cache_schema['description'] = "Cache table used to store paragraphs_item entity records.";
  139. db_create_table("cache_entity_paragraphs_item", $cache_schema);
  140. }
  141. }