2006-12-13 10:24:58 +00:00
|
|
|
<?php
|
|
|
|
|
2009-05-13 19:42:18 +00:00
|
|
|
/**
|
|
|
|
* @file
|
2012-01-03 04:36:15 +00:00
|
|
|
* Install, update and uninstall functions for the Comment module.
|
2009-05-13 19:42:18 +00:00
|
|
|
*/
|
|
|
|
|
2014-07-11 10:37:14 +00:00
|
|
|
use Drupal\Core\Entity\EntityTypeInterface;
|
2014-07-18 18:56:27 +00:00
|
|
|
use Drupal\field\Entity\FieldStorageConfig;
|
2014-06-13 09:34:04 +00:00
|
|
|
|
2009-01-19 01:23:39 +00:00
|
|
|
/**
|
2009-12-04 16:49:48 +00:00
|
|
|
* Implements hook_uninstall().
|
2009-01-19 01:23:39 +00:00
|
|
|
*/
|
|
|
|
function comment_uninstall() {
|
2013-09-27 15:34:47 +00:00
|
|
|
// Remove the comment fields.
|
2019-04-30 07:41:05 +00:00
|
|
|
$storage = \Drupal::entityTypeManager()->getStorage('field_storage_config');
|
|
|
|
$fields = $storage->loadByProperties(['type' => 'comment']);
|
|
|
|
$storage->delete($fields);
|
2012-11-14 10:23:00 +00:00
|
|
|
|
2013-09-27 15:34:47 +00:00
|
|
|
// Remove state setting.
|
2013-09-16 03:58:06 +00:00
|
|
|
\Drupal::state()->delete('comment.node_comment_statistics_scale');
|
2009-01-19 01:23:39 +00:00
|
|
|
}
|
|
|
|
|
2006-12-13 10:24:58 +00:00
|
|
|
/**
|
2013-09-19 16:22:53 +00:00
|
|
|
* Implements hook_install().
|
2006-12-13 10:24:58 +00:00
|
|
|
*/
|
2013-09-19 16:22:53 +00:00
|
|
|
function comment_install() {
|
2013-09-27 15:34:47 +00:00
|
|
|
// By default, maintain entity statistics for comments.
|
2014-08-13 00:40:09 +00:00
|
|
|
// @see \Drupal\comment\CommentStatisticsInterface
|
2013-09-27 15:34:47 +00:00
|
|
|
\Drupal::state()->set('comment.maintain_entity_statistics', TRUE);
|
2007-07-15 10:05:18 +00:00
|
|
|
}
|
|
|
|
|
2007-10-05 14:43:26 +00:00
|
|
|
/**
|
2009-12-04 16:49:48 +00:00
|
|
|
* Implements hook_schema().
|
2007-10-05 14:43:26 +00:00
|
|
|
*/
|
|
|
|
function comment_schema() {
|
2017-03-04 01:20:24 +00:00
|
|
|
$schema['comment_entity_statistics'] = [
|
2013-09-27 15:34:47 +00:00
|
|
|
'description' => 'Maintains statistics of entity and comments posts to show "new" and "updated" flags.',
|
2017-03-04 01:20:24 +00:00
|
|
|
'fields' => [
|
|
|
|
'entity_id' => [
|
2007-12-08 14:06:23 +00:00
|
|
|
'type' => 'int',
|
|
|
|
'unsigned' => TRUE,
|
|
|
|
'not null' => TRUE,
|
|
|
|
'default' => 0,
|
2013-09-27 15:34:47 +00:00
|
|
|
'description' => 'The entity_id of the entity for which the statistics are compiled.',
|
2017-03-04 01:20:24 +00:00
|
|
|
],
|
|
|
|
'entity_type' => [
|
2015-05-05 16:42:09 +00:00
|
|
|
'type' => 'varchar_ascii',
|
2013-09-27 15:34:47 +00:00
|
|
|
'not null' => TRUE,
|
|
|
|
'default' => 'node',
|
2014-07-11 10:37:14 +00:00
|
|
|
'length' => EntityTypeInterface::ID_MAX_LENGTH,
|
2013-09-27 15:34:47 +00:00
|
|
|
'description' => 'The entity_type of the entity to which this comment is a reply.',
|
2017-03-04 01:20:24 +00:00
|
|
|
],
|
|
|
|
'field_name' => [
|
2015-05-05 16:42:09 +00:00
|
|
|
'type' => 'varchar_ascii',
|
2013-09-27 15:34:47 +00:00
|
|
|
'not null' => TRUE,
|
2014-06-13 09:34:04 +00:00
|
|
|
'default' => '',
|
2014-07-18 18:56:27 +00:00
|
|
|
'length' => FieldStorageConfig::NAME_MAX_LENGTH,
|
2014-06-13 09:34:04 +00:00
|
|
|
'description' => 'The field_name of the field that was used to add this comment.',
|
2017-03-04 01:20:24 +00:00
|
|
|
],
|
|
|
|
'cid' => [
|
2009-11-12 06:46:44 +00:00
|
|
|
'type' => 'int',
|
|
|
|
'not null' => TRUE,
|
|
|
|
'default' => 0,
|
|
|
|
'description' => 'The {comment}.cid of the last comment.',
|
2017-03-04 01:20:24 +00:00
|
|
|
],
|
|
|
|
'last_comment_timestamp' => [
|
2007-12-08 14:06:23 +00:00
|
|
|
'type' => 'int',
|
|
|
|
'not null' => TRUE,
|
|
|
|
'default' => 0,
|
2011-08-02 00:23:15 +00:00
|
|
|
'description' => 'The Unix timestamp of the last comment that was posted within this node, from {comment}.changed.',
|
2017-03-04 01:20:24 +00:00
|
|
|
],
|
|
|
|
'last_comment_name' => [
|
2007-12-08 14:06:23 +00:00
|
|
|
'type' => 'varchar',
|
|
|
|
'length' => 60,
|
|
|
|
'not null' => FALSE,
|
2008-12-03 16:32:22 +00:00
|
|
|
'description' => 'The name of the latest author to post a comment on this node, from {comment}.name.',
|
2017-03-04 01:20:24 +00:00
|
|
|
],
|
|
|
|
'last_comment_uid' => [
|
2007-12-08 14:06:23 +00:00
|
|
|
'type' => 'int',
|
2012-10-04 20:27:03 +00:00
|
|
|
'unsigned' => TRUE,
|
2007-12-08 14:06:23 +00:00
|
|
|
'not null' => TRUE,
|
|
|
|
'default' => 0,
|
2008-12-03 16:32:22 +00:00
|
|
|
'description' => 'The user ID of the latest author to post a comment on this node, from {comment}.uid.',
|
2017-03-04 01:20:24 +00:00
|
|
|
],
|
|
|
|
'comment_count' => [
|
2007-12-08 14:06:23 +00:00
|
|
|
'type' => 'int',
|
|
|
|
'unsigned' => TRUE,
|
|
|
|
'not null' => TRUE,
|
|
|
|
'default' => 0,
|
2013-09-27 15:34:47 +00:00
|
|
|
'description' => 'The total number of comments on this entity.',
|
2017-03-04 01:20:24 +00:00
|
|
|
],
|
|
|
|
],
|
|
|
|
'primary key' => ['entity_id', 'entity_type', 'field_name'],
|
|
|
|
'indexes' => [
|
|
|
|
'last_comment_timestamp' => ['last_comment_timestamp'],
|
|
|
|
'comment_count' => ['comment_count'],
|
|
|
|
'last_comment_uid' => ['last_comment_uid'],
|
|
|
|
],
|
|
|
|
'foreign keys' => [
|
|
|
|
'last_comment_author' => [
|
2010-08-22 13:55:53 +00:00
|
|
|
'table' => 'users',
|
2017-03-04 01:20:24 +00:00
|
|
|
'columns' => [
|
2010-08-22 13:55:53 +00:00
|
|
|
'last_comment_uid' => 'uid',
|
2017-03-04 01:20:24 +00:00
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
2007-10-05 14:43:26 +00:00
|
|
|
|
|
|
|
return $schema;
|
2009-10-10 13:37:11 +00:00
|
|
|
}
|
2015-11-02 15:17:52 +00:00
|
|
|
|
|
|
|
/**
|
2020-01-21 23:33:30 +00:00
|
|
|
* Implements hook_update_last_removed().
|
2016-10-20 12:33:59 +00:00
|
|
|
*/
|
2020-01-21 23:33:30 +00:00
|
|
|
function comment_update_last_removed() {
|
|
|
|
return 8701;
|
2018-11-26 12:21:16 +00:00
|
|
|
}
|