comment.install

  1. 7.x drupal-7.x/modules/comment/comment.install
  2. 6.x drupal-6.x/modules/comment/comment.install

File

drupal-6.x/modules/comment/comment.install
View source
  1. <?php
  2. /**
  3. * Implementation of hook_enable().
  4. */
  5. function comment_enable() {
  6. // Insert records into the node_comment_statistics for nodes that are missing.
  7. db_query("INSERT INTO {node_comment_statistics} (nid, last_comment_timestamp, last_comment_name, last_comment_uid, comment_count) SELECT n.nid, n.changed, NULL, n.uid, 0 FROM {node} n LEFT JOIN {node_comment_statistics} c ON n.nid = c.nid WHERE c.comment_count IS NULL");
  8. }
  9. /**
  10. * Changed node_comment_statistics to use node->changed to avoid future timestamps.
  11. */
  12. function comment_update_1() {
  13. // Change any future last comment timestamps to now.
  14. db_query('UPDATE {node_comment_statistics} SET last_comment_timestamp = %d WHERE last_comment_timestamp > %d', time(), time());
  15. // Unstuck node indexing timestamp if needed.
  16. if (($last = variable_get('node_cron_last', FALSE)) !== FALSE) {
  17. variable_set('node_cron_last', min(time(), $last));
  18. }
  19. return array();
  20. }
  21. function comment_update_6001() {
  22. $ret[] = update_sql("ALTER TABLE {comments} DROP score");
  23. $ret[] = update_sql("ALTER TABLE {comments} DROP users");
  24. return $ret;
  25. }
  26. /**
  27. * Changed comment settings from global to per-node -- copy global
  28. * settings to all node types.
  29. */
  30. function comment_update_6002() {
  31. // Comment module might not be enabled when this is run, but we need the
  32. // constants defined by the module for this update.
  33. drupal_load('module', 'comment');
  34. $settings = array(
  35. 'comment_default_mode' => COMMENT_MODE_THREADED_EXPANDED,
  36. 'comment_default_order' => COMMENT_ORDER_NEWEST_FIRST,
  37. 'comment_default_per_page' => 50,
  38. 'comment_controls' => COMMENT_CONTROLS_HIDDEN,
  39. 'comment_anonymous' => COMMENT_ANONYMOUS_MAYNOT_CONTACT,
  40. 'comment_subject_field' => 1,
  41. 'comment_preview' => COMMENT_PREVIEW_REQUIRED,
  42. 'comment_form_location' => COMMENT_FORM_SEPARATE_PAGE,
  43. );
  44. $types = node_get_types();
  45. foreach ($settings as $setting => $default) {
  46. $value = variable_get($setting, $default);
  47. foreach ($types as $type => $object) {
  48. variable_set($setting .'_'. $type, $value);
  49. }
  50. variable_del($setting);
  51. }
  52. return array(array('success' => TRUE, 'query' => 'Global comment settings copied to all node types.'));
  53. }
  54. /**
  55. * Add index to parent ID field.
  56. */
  57. function comment_update_6003() {
  58. $ret = array();
  59. db_add_index($ret, 'comments', 'pid', array('pid'));
  60. return $ret;
  61. }
  62. /**
  63. * @addtogroup updates-6.x-extra
  64. * @{
  65. */
  66. /**
  67. * Add index to to node_comment_statistics on comment_count
  68. */
  69. function comment_update_6004() {
  70. $ret = array();
  71. db_add_index($ret, 'node_comment_statistics', 'comment_count', array('comment_count'));
  72. return $ret;
  73. }
  74. /**
  75. * Add indices to uid fields.
  76. */
  77. function comment_update_6005() {
  78. $ret = array();
  79. db_add_index($ret, 'comments', 'comment_uid', array('uid'));
  80. db_add_index($ret, 'node_comment_statistics', 'last_comment_uid', array('last_comment_uid'));
  81. return $ret;
  82. }
  83. /**
  84. * @} End of "addtogroup updates-6.x-extra".
  85. * The next series of updates should start at 7000.
  86. */
  87. /**
  88. * Implementation of hook_schema().
  89. */
  90. function comment_schema() {
  91. $schema['comments'] = array(
  92. 'description' => 'Stores comments and associated data.',
  93. 'fields' => array(
  94. 'cid' => array(
  95. 'type' => 'serial',
  96. 'not null' => TRUE,
  97. 'description' => 'Primary Key: Unique comment ID.',
  98. ),
  99. 'pid' => array(
  100. 'type' => 'int',
  101. 'not null' => TRUE,
  102. 'default' => 0,
  103. 'description' => 'The {comments}.cid to which this comment is a reply. If set to 0, this comment is not a reply to an existing comment.',
  104. ),
  105. 'nid' => array(
  106. 'type' => 'int',
  107. 'not null' => TRUE,
  108. 'default' => 0,
  109. 'description' => 'The {node}.nid to which this comment is a reply.',
  110. ),
  111. 'uid' => array(
  112. 'type' => 'int',
  113. 'not null' => TRUE,
  114. 'default' => 0,
  115. 'description' => 'The {users}.uid who authored the comment. If set to 0, this comment was created by an anonymous user.',
  116. ),
  117. 'subject' => array(
  118. 'type' => 'varchar',
  119. 'length' => 64,
  120. 'not null' => TRUE,
  121. 'default' => '',
  122. 'description' => 'The comment title.',
  123. ),
  124. 'comment' => array(
  125. 'type' => 'text',
  126. 'not null' => TRUE,
  127. 'size' => 'big',
  128. 'description' => 'The comment body.',
  129. ),
  130. 'hostname' => array(
  131. 'type' => 'varchar',
  132. 'length' => 128,
  133. 'not null' => TRUE,
  134. 'default' => '',
  135. 'description' => "The author's host name.",
  136. ),
  137. 'timestamp' => array(
  138. 'type' => 'int',
  139. 'not null' => TRUE,
  140. 'default' => 0,
  141. 'description' => 'The time that the comment was created, or last edited by its author, as a Unix timestamp.',
  142. ),
  143. 'status' => array(
  144. 'type' => 'int',
  145. 'unsigned' => TRUE,
  146. 'not null' => TRUE,
  147. 'default' => 0,
  148. 'size' => 'tiny',
  149. 'description' => 'The published status of a comment. (0 = Published, 1 = Not Published)',
  150. ),
  151. 'format' => array(
  152. 'type' => 'int',
  153. 'size' => 'small',
  154. 'not null' => TRUE,
  155. 'default' => 0,
  156. 'description' => 'The {filter_formats}.format of the comment body.',
  157. ),
  158. 'thread' => array(
  159. 'type' => 'varchar',
  160. 'length' => 255,
  161. 'not null' => TRUE,
  162. 'description' => "The vancode representation of the comment's place in a thread.",
  163. ),
  164. 'name' => array(
  165. 'type' => 'varchar',
  166. 'length' => 60,
  167. 'not null' => FALSE,
  168. 'description' => "The comment author's name. Uses {users}.name if the user is logged in, otherwise uses the value typed into the comment form.",
  169. ),
  170. 'mail' => array(
  171. 'type' => 'varchar',
  172. 'length' => 64,
  173. 'not null' => FALSE,
  174. '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.",
  175. ),
  176. 'homepage' => array(
  177. 'type' => 'varchar',
  178. 'length' => 255,
  179. 'not null' => FALSE,
  180. '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.",
  181. )
  182. ),
  183. 'indexes' => array(
  184. 'pid' => array('pid'),
  185. 'nid' => array('nid'),
  186. 'comment_uid' => array('uid'),
  187. 'status' => array('status'), // This index is probably unused
  188. ),
  189. 'primary key' => array('cid'),
  190. );
  191. $schema['node_comment_statistics'] = array(
  192. 'description' => 'Maintains statistics of node and comments posts to show "new" and "updated" flags.',
  193. 'fields' => array(
  194. 'nid' => array(
  195. 'type' => 'int',
  196. 'unsigned' => TRUE,
  197. 'not null' => TRUE,
  198. 'default' => 0,
  199. 'description' => 'The {node}.nid for which the statistics are compiled.',
  200. ),
  201. 'last_comment_timestamp' => array(
  202. 'type' => 'int',
  203. 'not null' => TRUE,
  204. 'default' => 0,
  205. 'description' => 'The Unix timestamp of the last comment that was posted within this node, from {comments}.timestamp.',
  206. ),
  207. 'last_comment_name' => array(
  208. 'type' => 'varchar',
  209. 'length' => 60,
  210. 'not null' => FALSE,
  211. 'description' => 'The name of the latest author to post a comment on this node, from {comments}.name.',
  212. ),
  213. 'last_comment_uid' => array(
  214. 'type' => 'int',
  215. 'not null' => TRUE,
  216. 'default' => 0,
  217. 'description' => 'The user ID of the latest author to post a comment on this node, from {comments}.uid.',
  218. ),
  219. 'comment_count' => array(
  220. 'type' => 'int',
  221. 'unsigned' => TRUE,
  222. 'not null' => TRUE,
  223. 'default' => 0,
  224. 'description' => 'The total number of comments on this node.',
  225. ),
  226. ),
  227. 'primary key' => array('nid'),
  228. 'indexes' => array(
  229. 'node_comment_timestamp' => array('last_comment_timestamp'),
  230. 'comment_count' => array('comment_count'),
  231. 'last_comment_uid' => array('last_comment_uid'),
  232. ),
  233. );
  234. return $schema;
  235. }