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.
|
2014-07-18 18:56:27 +00:00
|
|
|
$fields = entity_load_multiple_by_properties('field_storage_config', array('type' => 'comment'));
|
2013-09-27 15:34:47 +00:00
|
|
|
foreach ($fields as $field) {
|
|
|
|
$field->delete();
|
2009-01-31 16:31:59 +00:00
|
|
|
}
|
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() {
|
2013-09-27 15:34:47 +00:00
|
|
|
$schema['comment_entity_statistics'] = array(
|
|
|
|
'description' => 'Maintains statistics of entity and comments posts to show "new" and "updated" flags.',
|
2007-12-08 14:06:23 +00:00
|
|
|
'fields' => array(
|
2013-09-27 15:34:47 +00:00
|
|
|
'entity_id' => array(
|
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.',
|
|
|
|
),
|
|
|
|
'entity_type' => array(
|
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.',
|
|
|
|
),
|
2014-06-13 09:34:04 +00:00
|
|
|
'field_name' => array(
|
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.',
|
2007-12-08 14:06:23 +00:00
|
|
|
),
|
2009-11-12 06:46:44 +00:00
|
|
|
'cid' => array(
|
|
|
|
'type' => 'int',
|
|
|
|
'not null' => TRUE,
|
|
|
|
'default' => 0,
|
|
|
|
'description' => 'The {comment}.cid of the last comment.',
|
|
|
|
),
|
2007-12-08 14:06:23 +00:00
|
|
|
'last_comment_timestamp' => array(
|
|
|
|
'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.',
|
2007-12-08 14:06:23 +00:00
|
|
|
),
|
|
|
|
'last_comment_name' => array(
|
|
|
|
'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.',
|
2007-12-08 14:06:23 +00:00
|
|
|
),
|
|
|
|
'last_comment_uid' => array(
|
|
|
|
'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.',
|
2007-12-08 14:06:23 +00:00
|
|
|
),
|
|
|
|
'comment_count' => array(
|
|
|
|
'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.',
|
2007-12-08 14:06:23 +00:00
|
|
|
),
|
|
|
|
),
|
2014-06-13 09:34:04 +00:00
|
|
|
'primary key' => array('entity_id', 'entity_type', 'field_name'),
|
2007-12-18 12:59:22 +00:00
|
|
|
'indexes' => array(
|
2013-09-27 15:34:47 +00:00
|
|
|
'last_comment_timestamp' => array('last_comment_timestamp'),
|
2009-07-30 19:27:11 +00:00
|
|
|
'comment_count' => array('comment_count'),
|
2009-08-09 02:46:27 +00:00
|
|
|
'last_comment_uid' => array('last_comment_uid'),
|
2007-12-18 12:59:22 +00:00
|
|
|
),
|
2009-06-01 22:07:10 +00:00
|
|
|
'foreign keys' => array(
|
2010-08-22 13:55:53 +00:00
|
|
|
'last_comment_author' => array(
|
|
|
|
'table' => 'users',
|
|
|
|
'columns' => array(
|
|
|
|
'last_comment_uid' => 'uid',
|
|
|
|
),
|
|
|
|
),
|
2009-06-01 22:07:10 +00:00
|
|
|
),
|
2007-10-05 14:43:26 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
return $schema;
|
2009-10-10 13:37:11 +00:00
|
|
|
}
|