comment.install 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the Comment module.
  5. */
  6. use Drupal\Core\Entity\EntityTypeInterface;
  7. use Drupal\field\Entity\FieldStorageConfig;
  8. /**
  9. * Implements hook_uninstall().
  10. */
  11. function comment_uninstall() {
  12. // Remove the comment fields.
  13. $fields = entity_load_multiple_by_properties('field_storage_config', array('type' => 'comment'));
  14. foreach ($fields as $field) {
  15. $field->delete();
  16. }
  17. // Remove state setting.
  18. \Drupal::state()->delete('comment.node_comment_statistics_scale');
  19. }
  20. /**
  21. * Implements hook_install().
  22. */
  23. function comment_install() {
  24. // By default, maintain entity statistics for comments.
  25. // @see \Drupal\comment\CommentStatisticsInterface
  26. \Drupal::state()->set('comment.maintain_entity_statistics', TRUE);
  27. }
  28. /**
  29. * Implements hook_schema().
  30. */
  31. function comment_schema() {
  32. $schema['comment_entity_statistics'] = array(
  33. 'description' => 'Maintains statistics of entity and comments posts to show "new" and "updated" flags.',
  34. 'fields' => array(
  35. 'entity_id' => array(
  36. 'type' => 'int',
  37. 'unsigned' => TRUE,
  38. 'not null' => TRUE,
  39. 'default' => 0,
  40. 'description' => 'The entity_id of the entity for which the statistics are compiled.',
  41. ),
  42. 'entity_type' => array(
  43. 'type' => 'varchar_ascii',
  44. 'not null' => TRUE,
  45. 'default' => 'node',
  46. 'length' => EntityTypeInterface::ID_MAX_LENGTH,
  47. 'description' => 'The entity_type of the entity to which this comment is a reply.',
  48. ),
  49. 'field_name' => array(
  50. 'type' => 'varchar_ascii',
  51. 'not null' => TRUE,
  52. 'default' => '',
  53. 'length' => FieldStorageConfig::NAME_MAX_LENGTH,
  54. 'description' => 'The field_name of the field that was used to add this comment.',
  55. ),
  56. 'cid' => array(
  57. 'type' => 'int',
  58. 'not null' => TRUE,
  59. 'default' => 0,
  60. 'description' => 'The {comment}.cid of the last comment.',
  61. ),
  62. 'last_comment_timestamp' => array(
  63. 'type' => 'int',
  64. 'not null' => TRUE,
  65. 'default' => 0,
  66. 'description' => 'The Unix timestamp of the last comment that was posted within this node, from {comment}.changed.',
  67. ),
  68. 'last_comment_name' => array(
  69. 'type' => 'varchar',
  70. 'length' => 60,
  71. 'not null' => FALSE,
  72. 'description' => 'The name of the latest author to post a comment on this node, from {comment}.name.',
  73. ),
  74. 'last_comment_uid' => array(
  75. 'type' => 'int',
  76. 'unsigned' => TRUE,
  77. 'not null' => TRUE,
  78. 'default' => 0,
  79. 'description' => 'The user ID of the latest author to post a comment on this node, from {comment}.uid.',
  80. ),
  81. 'comment_count' => array(
  82. 'type' => 'int',
  83. 'unsigned' => TRUE,
  84. 'not null' => TRUE,
  85. 'default' => 0,
  86. 'description' => 'The total number of comments on this entity.',
  87. ),
  88. ),
  89. 'primary key' => array('entity_id', 'entity_type', 'field_name'),
  90. 'indexes' => array(
  91. 'last_comment_timestamp' => array('last_comment_timestamp'),
  92. 'comment_count' => array('comment_count'),
  93. 'last_comment_uid' => array('last_comment_uid'),
  94. ),
  95. 'foreign keys' => array(
  96. 'last_comment_author' => array(
  97. 'table' => 'users',
  98. 'columns' => array(
  99. 'last_comment_uid' => 'uid',
  100. ),
  101. ),
  102. ),
  103. );
  104. return $schema;
  105. }
  106. /**
  107. * @addtogroup updates-8.0.0-rc
  108. * @{
  109. */
  110. /**
  111. * Clear caches to fix Comment entity list builder and operations Views field.
  112. */
  113. function comment_update_8001() {
  114. // Empty update to cause a cache flush to rebuild comment entity handler
  115. // information, so that comment operation links work.
  116. }
  117. /**
  118. * @} End of "addtogroup updates-8.0.0-rc".
  119. */
  120. /**
  121. * Clear caches to fix Comment Views context filter.
  122. */
  123. function comment_update_8002() {
  124. // Empty update to cause a cache flush.
  125. }