1 comment.module _comment_close_all()

Close all comments that meet the current threshold.

File

core/modules/comment/comment.module, line 2381
Enables users to comment on published content.

Code

function _comment_close_all() {
  $content_types = node_type_get_names();

  foreach ($content_types as $type => $name) {
    // Get the content type settings.
    $node_type = node_type_load($type);
    $days = $node_type->settings['comment_close_days'];
    $enable = $node_type->settings['comment_close_enabled'];

    // If a day is set, do this one.
    if (!empty($enable) && !empty($days)) {
      $oldest_allowed = strtotime("-$days days", REQUEST_TIME);

      // Fetch nodes that should have comments closed.
      $result = db_query("SELECT nid FROM {node} WHERE created < :oldest AND comment_close_override = 0 AND type = :type AND comment = :comment", 
      array(':oldest' => $oldest_allowed, ':type' => $type, ':comment' => COMMENT_NODE_OPEN)
      );
      $nids = $result->fetchCol();

      // Update those rows.
      foreach ($nids as $nid) {
        $node = node_load($nid);
        $node->comment = COMMENT_NODE_CLOSED;
        node_save($node);
      }

      $count = $result->rowCount();
      if ($count) {
        $vars = array(
          '!count' => $count,
          '@type' => $name,
          '!date' => format_date($oldest_allowed),
        );
        $msg = 'Closed comments on !count @type posts created at, or before, !date.';
        watchdog('comment', $msg, $vars, WATCHDOG_NOTICE);
      }
    }
  }
}