You are here

function devel_create_comments in Devel 5

1 call to devel_create_comments()
devel_generate_content in ./devel_generate.inc

File

./devel_generate.inc, line 128

Code

function devel_create_comments($records, $users, $nodes, $comments) {
  $users = array_merge($users, array(
    '0',
  ));

  // Insert new data:
  for ($i = 1; $i <= $records; $i++) {
    $comment->cid = db_next_id("{comments}_cid");
    $comment->nid = array_rand($nodes);
    switch ($i % 3) {
      case 1:
        $comment->pid = db_result(db_query("SELECT cid FROM {comments} WHERE pid = 0 AND nid = %d ORDER BY RAND() LIMIT 1", $comment->nid));
        break;
      case 2:
        $comment->pid = db_result(db_query("SELECT cid FROM {comments} WHERE pid > 0 AND nid = %d ORDER BY RAND() LIMIT 1", $comment->nid));
        break;
      default:
        $comment->pid = 0;
    }
    $comment->subject = "comment #" . $comment->cid;
    $comment->comment = "body of comment #" . $comment->cid;
    $comment->uid = $users[array_rand($users)];
    db_query("INSERT INTO {comments} (cid, nid, pid, uid, subject, comment, status, thread, timestamp) VALUES (%d, %d, %d, %d, '%s', '%s', %d, %d, %d)", $comment->cid, $comment->nid, $comment->pid, $comment->uid, $comment->subject, $comment->comment, 0, 0, time());
  }

  // update comments statistics
  foreach ($nodes as $nid => $type) {
    _comment_update_node_statistics($nid);
  }
}