comment.install 3.39 KB
Newer Older
1 2
<?php

3 4
/**
 * @file
5
 * Install, update and uninstall functions for the Comment module.
6 7
 */

8
use Drupal\Core\Entity\EntityTypeInterface;
9
use Drupal\field\Entity\FieldStorageConfig;
10

11
/**
12
 * Implements hook_uninstall().
13 14
 */
function comment_uninstall() {
15
  // Remove the comment fields.
16
  $fields = entity_load_multiple_by_properties('field_storage_config', array('type' => 'comment'));
17 18
  foreach ($fields as $field) {
    $field->delete();
19
  }
20

21
  // Remove state setting.
22
  \Drupal::state()->delete('comment.node_comment_statistics_scale');
23 24
}

25
/**
26
 * Implements hook_install().
27
 */
28
function comment_install() {
29
  // By default, maintain entity statistics for comments.
30
  // @see \Drupal\comment\CommentStatisticsInterface
31
  \Drupal::state()->set('comment.maintain_entity_statistics', TRUE);
32 33
}

34
/**
35
 * Implements hook_schema().
36 37
 */
function comment_schema() {
38 39
  $schema['comment_entity_statistics'] = array(
    'description' => 'Maintains statistics of entity and comments posts to show "new" and "updated" flags.',
40
    'fields' => array(
41
      'entity_id' => array(
42 43 44 45
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
46 47 48
        'description' => 'The entity_id of the entity for which the statistics are compiled.',
      ),
      'entity_type' => array(
49
        'type' => 'varchar_ascii',
50 51
        'not null' => TRUE,
        'default' => 'node',
52
        'length' => EntityTypeInterface::ID_MAX_LENGTH,
53 54
        'description' => 'The entity_type of the entity to which this comment is a reply.',
      ),
55
      'field_name' => array(
56
        'type' => 'varchar_ascii',
57
        'not null' => TRUE,
58
        'default' => '',
59
        'length' => FieldStorageConfig::NAME_MAX_LENGTH,
60
        'description' => 'The field_name of the field that was used to add this comment.',
61
      ),
62 63 64 65 66 67
      'cid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => 'The {comment}.cid of the last comment.',
      ),
68 69 70 71
      'last_comment_timestamp' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
72
        'description' => 'The Unix timestamp of the last comment that was posted within this node, from {comment}.changed.',
73 74 75 76 77
      ),
      'last_comment_name' => array(
        'type' => 'varchar',
        'length' => 60,
        'not null' => FALSE,
78
        'description' => 'The name of the latest author to post a comment on this node, from {comment}.name.',
79 80 81
      ),
      'last_comment_uid' => array(
        'type' => 'int',
82
        'unsigned' => TRUE,
83 84
        'not null' => TRUE,
        'default' => 0,
85
        'description' => 'The user ID of the latest author to post a comment on this node, from {comment}.uid.',
86 87 88 89 90 91
      ),
      'comment_count' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
92
        'description' => 'The total number of comments on this entity.',
93 94
      ),
    ),
95
    'primary key' => array('entity_id', 'entity_type', 'field_name'),
96
    'indexes' => array(
97
      'last_comment_timestamp' => array('last_comment_timestamp'),
98
      'comment_count' => array('comment_count'),
99
      'last_comment_uid' => array('last_comment_uid'),
100
    ),
101
    'foreign keys' => array(
102 103 104 105 106 107
      'last_comment_author' => array(
        'table' => 'users',
        'columns' => array(
          'last_comment_uid' => 'uid',
        ),
      ),
108
    ),
109 110 111
  );

  return $schema;
112
}