comment.install

  1. drupal
    1. 5 modules/comment/comment.install
    2. 6 modules/comment/comment.install
    3. 7 modules/comment/comment.install
    4. 8 core/modules/comment/comment.install

Install, update and uninstall functions for the Comment module.

Functions & methods

NameDescription
comment_enableImplements hook_enable().
comment_modules_enabledImplements hook_modules_enabled().
comment_schemaImplements hook_schema().
comment_uninstallImplements hook_uninstall().
comment_update_8000Renames {comment}.language to {comment}.langcode.

File

core/modules/comment/comment.install
View source
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the Comment module.
  5. */
  6. /**
  7. * Implements hook_uninstall().
  8. */
  9. function comment_uninstall() {
  10. // Delete comment_body field.
  11. field_delete_field('comment_body');
  12. // Remove variables.
  13. variable_del('comment_block_count');
  14. $node_types = array_keys(node_type_get_types());
  15. foreach ($node_types as $node_type) {
  16. field_attach_delete_bundle('comment', 'comment_node_' . $node_type);
  17. variable_del('comment_' . $node_type);
  18. variable_del('comment_anonymous_' . $node_type);
  19. variable_del('comment_controls_' . $node_type);
  20. variable_del('comment_default_mode_' . $node_type);
  21. variable_del('comment_default_order_' . $node_type);
  22. variable_del('comment_default_per_page_' . $node_type);
  23. variable_del('comment_form_location_' . $node_type);
  24. variable_del('comment_preview_' . $node_type);
  25. variable_del('comment_subject_field_' . $node_type);
  26. }
  27. }
  28. /**
  29. * Implements hook_enable().
  30. */
  31. function comment_enable() {
  32. // Insert records into the node_comment_statistics for nodes that are missing.
  33. $query = db_select('node', 'n');
  34. $query->leftJoin('node_comment_statistics', 'ncs', 'ncs.nid = n.nid');
  35. $query->addField('n', 'created', 'last_comment_timestamp');
  36. $query->addField('n', 'uid', 'last_comment_uid');
  37. $query->addField('n', 'nid');
  38. $query->addExpression('0', 'comment_count');
  39. $query->addExpression('NULL', 'last_comment_name');
  40. $query->isNull('ncs.comment_count');
  41. db_insert('node_comment_statistics')
  42. ->from($query)
  43. ->execute();
  44. }
  45. /**
  46. * Implements hook_modules_enabled().
  47. *
  48. * Creates comment body fields for node types existing before the Comment module
  49. * is enabled. We use hook_modules_enabled() rather than hook_enable() so we can
  50. * react to node types of existing modules, and those of modules being enabled
  51. * both before and after the Comment module in the loop of module_enable().
  52. *
  53. * There is a separate comment bundle for each node type to allow for
  54. * per-node-type customization of comment fields. Each one of these bundles
  55. * needs a comment body field instance. A comment bundle is needed even for
  56. * node types whose comments are disabled by default, because individual nodes
  57. * may override that default.
  58. *
  59. * @see comment_node_type_insert()
  60. */
  61. function comment_modules_enabled($modules) {
  62. // Only react if the Comment module is one of the modules being enabled.
  63. // hook_node_type_insert() is used to create body fields while the comment
  64. // module is enabled.
  65. if (in_array('comment', $modules)) {
  66. // Ensure that the list of node types reflects newly enabled modules.
  67. node_types_rebuild();
  68. // Create comment body fields for each node type, if needed.
  69. foreach (node_type_get_types() as $type => $info) {
  70. _comment_body_field_create($info);
  71. }
  72. }
  73. }
  74. /**
  75. * Implements hook_schema().
  76. */
  77. function comment_schema() {
  78. $schema['comment'] = array(
  79. 'description' => 'Stores comments and associated data.',
  80. 'fields' => array(
  81. 'cid' => array(
  82. 'type' => 'serial',
  83. 'not null' => TRUE,
  84. 'description' => 'Primary Key: Unique comment ID.',
  85. ),
  86. 'pid' => array(
  87. 'type' => 'int',
  88. 'not null' => TRUE,
  89. 'default' => 0,
  90. 'description' => 'The {comment}.cid to which this comment is a reply. If set to 0, this comment is not a reply to an existing comment.',
  91. ),
  92. 'nid' => array(
  93. 'type' => 'int',
  94. 'not null' => TRUE,
  95. 'default' => 0,
  96. 'description' => 'The {node}.nid to which this comment is a reply.',
  97. ),
  98. 'uid' => array(
  99. 'type' => 'int',
  100. 'not null' => TRUE,
  101. 'default' => 0,
  102. 'description' => 'The {users}.uid who authored the comment. If set to 0, this comment was created by an anonymous user.',
  103. ),
  104. 'subject' => array(
  105. 'type' => 'varchar',
  106. 'length' => 64,
  107. 'not null' => TRUE,
  108. 'default' => '',
  109. 'description' => 'The comment title.',
  110. ),
  111. 'hostname' => array(
  112. 'type' => 'varchar',
  113. 'length' => 128,
  114. 'not null' => TRUE,
  115. 'default' => '',
  116. 'description' => "The author's host name.",
  117. ),
  118. 'created' => array(
  119. 'type' => 'int',
  120. 'not null' => TRUE,
  121. 'default' => 0,
  122. 'description' => 'The time that the comment was created, as a Unix timestamp.',
  123. ),
  124. 'changed' => array(
  125. 'type' => 'int',
  126. 'not null' => TRUE,
  127. 'default' => 0,
  128. 'description' => 'The time that the comment was last edited, as a Unix timestamp.',
  129. ),
  130. 'status' => array(
  131. 'type' => 'int',
  132. 'unsigned' => TRUE,
  133. 'not null' => TRUE,
  134. 'default' => 1,
  135. 'size' => 'tiny',
  136. 'description' => 'The published status of a comment. (0 = Not Published, 1 = Published)',
  137. ),
  138. 'thread' => array(
  139. 'type' => 'varchar',
  140. 'length' => 255,
  141. 'not null' => TRUE,
  142. 'description' => "The alphadecimal representation of the comment's place in a thread, consisting of a base 36 string prefixed by an integer indicating its length.",
  143. ),
  144. 'name' => array(
  145. 'type' => 'varchar',
  146. 'length' => 60,
  147. 'not null' => FALSE,
  148. 'description' => "The comment author's name. Uses {users}.name if the user is logged in, otherwise uses the value typed into the comment form.",
  149. ),
  150. 'mail' => array(
  151. 'type' => 'varchar',
  152. 'length' => 64,
  153. 'not null' => FALSE,
  154. 'description' => "The comment author's e-mail address from the comment form, if user is anonymous, and the 'Anonymous users may/must leave their contact information' setting is turned on.",
  155. ),
  156. 'homepage' => array(
  157. 'type' => 'varchar',
  158. 'length' => 255,
  159. 'not null' => FALSE,
  160. 'description' => "The comment author's home page address from the comment form, if user is anonymous, and the 'Anonymous users may/must leave their contact information' setting is turned on.",
  161. ),
  162. 'langcode' => array(
  163. 'description' => 'The {language}.langcode of this comment.',
  164. 'type' => 'varchar',
  165. 'length' => 12,
  166. 'not null' => TRUE,
  167. 'default' => '',
  168. ),
  169. ),
  170. 'indexes' => array(
  171. 'comment_status_pid' => array('pid', 'status'),
  172. 'comment_num_new' => array('nid', 'status', 'created', 'cid', 'thread'),
  173. 'comment_uid' => array('uid'),
  174. 'comment_nid_langcode' => array('nid', 'langcode'),
  175. 'comment_created' => array('created'),
  176. ),
  177. 'primary key' => array('cid'),
  178. 'foreign keys' => array(
  179. 'comment_node' => array(
  180. 'table' => 'node',
  181. 'columns' => array('nid' => 'nid'),
  182. ),
  183. 'comment_author' => array(
  184. 'table' => 'users',
  185. 'columns' => array('uid' => 'uid'),
  186. ),
  187. ),
  188. );
  189. $schema['node_comment_statistics'] = array(
  190. 'description' => 'Maintains statistics of node and comments posts to show "new" and "updated" flags.',
  191. 'fields' => array(
  192. 'nid' => array(
  193. 'type' => 'int',
  194. 'unsigned' => TRUE,
  195. 'not null' => TRUE,
  196. 'default' => 0,
  197. 'description' => 'The {node}.nid for which the statistics are compiled.',
  198. ),
  199. 'cid' => array(
  200. 'type' => 'int',
  201. 'not null' => TRUE,
  202. 'default' => 0,
  203. 'description' => 'The {comment}.cid of the last comment.',
  204. ),
  205. 'last_comment_timestamp' => array(
  206. 'type' => 'int',
  207. 'not null' => TRUE,
  208. 'default' => 0,
  209. 'description' => 'The Unix timestamp of the last comment that was posted within this node, from {comment}.changed.',
  210. ),
  211. 'last_comment_name' => array(
  212. 'type' => 'varchar',
  213. 'length' => 60,
  214. 'not null' => FALSE,
  215. 'description' => 'The name of the latest author to post a comment on this node, from {comment}.name.',
  216. ),
  217. 'last_comment_uid' => array(
  218. 'type' => 'int',
  219. 'not null' => TRUE,
  220. 'default' => 0,
  221. 'description' => 'The user ID of the latest author to post a comment on this node, from {comment}.uid.',
  222. ),
  223. 'comment_count' => array(
  224. 'type' => 'int',
  225. 'unsigned' => TRUE,
  226. 'not null' => TRUE,
  227. 'default' => 0,
  228. 'description' => 'The total number of comments on this node.',
  229. ),
  230. ),
  231. 'primary key' => array('nid'),
  232. 'indexes' => array(
  233. 'node_comment_timestamp' => array('last_comment_timestamp'),
  234. 'comment_count' => array('comment_count'),
  235. 'last_comment_uid' => array('last_comment_uid'),
  236. ),
  237. 'foreign keys' => array(
  238. 'statistics_node' => array(
  239. 'table' => 'node',
  240. 'columns' => array('nid' => 'nid'),
  241. ),
  242. 'last_comment_author' => array(
  243. 'table' => 'users',
  244. 'columns' => array(
  245. 'last_comment_uid' => 'uid',
  246. ),
  247. ),
  248. ),
  249. );
  250. return $schema;
  251. }
  252. /**
  253. * @addtogroup updates-7.x-to-8.x
  254. * @{
  255. */
  256. /**
  257. * Renames {comment}.language to {comment}.langcode.
  258. */
  259. function comment_update_8000() {
  260. db_drop_index('comment', 'comment_nid_language');
  261. $langcode_spec = array(
  262. 'type' => 'varchar',
  263. 'length' => 12,
  264. 'not null' => TRUE,
  265. 'default' => '',
  266. 'description' => "Language code, e.g. 'de' or 'en-US'.",
  267. );
  268. db_change_field('comment', 'language', 'langcode', $langcode_spec);
  269. db_add_index('comment', 'comment_nid_langcode', array('nid', 'langcode'));
  270. }
  271. /**
  272. * @} End of "addtogroup updates-7.x-to-8.x"
  273. * The next series of updates should start at 9000.
  274. */
Login or register to post comments