function privatemsg_devel_generate_new_thread in Privatemsg 6.2
Same name and namespace in other branches
- 7.2 privatemsg.devel_generate.inc \privatemsg_devel_generate_new_thread()
Single Message Generation
2 calls to privatemsg_devel_generate_new_thread()
- privatemsg_devel_generate_batch_new_thread in ./
privatemsg.devel_generate.inc - privatemsg_devel_generate_threads in ./
privatemsg.devel_generate.inc - Mass Message Generation
File
- ./
privatemsg.devel_generate.inc, line 164
Code
function privatemsg_devel_generate_new_thread($values) {
module_load_include('inc', 'devel_generate');
$uids = devel_get_users();
// Do not allow anonymous (key) to send/receive private messages
unset($uids[key($uids)]);
$author = privatemsg_user_load($uids[array_rand($uids)]);
$subject = devel_create_greeking(rand(1, $values['subject_length']), TRUE);
$body = devel_create_content();
$timestamp = rand(0, $values['time_range']);
$options = array(
'author' => $author,
'timestamp' => time() - $timestamp,
);
// Remove author when adding new recipients.
unset($uids[array_search($author->uid, $uids)]);
// Get a random amount of user ids.
$recipient_uids = array_rand($uids, rand($values['min_recipients'], $values['max_recipients']));
$recipients = privatemsg_user_load($recipient_uids);
// Convert to array if just a single user has been loaded.
if (!is_array($recipients)) {
$recipients = array(
$recipients,
);
}
// Remove recipients that failed to load.
// @todo: privatemsg_user_load() should only return successfully loaded user
// objects.
$recipients = array_filter($recipients);
// Generate message.
$validated = privatemsg_new_thread($recipients, $subject, $body, $options);
// Get thread information for generating replies.
$thread_id = $validated['message']['thread_id'];
$num_replies = rand(0, $values['max_thread_length']);
$reply_timestamp = $options['timestamp'];
// Add author back in to possible senders.
$recipients[$author->uid] = $author;
// Generate thread replies.
for ($j = 0; $j <= $num_replies; $j++) {
$reply_body = devel_create_content();
$reply_author = $recipients[array_rand($recipients)];
$reply_timestamp = rand(0, $reply_timestamp);
$reply_options = array(
'author' => $reply_author,
'timestamp' => time() - $reply_timestamp,
);
privatemsg_reply($thread_id, $reply_body, $reply_options);
}
}