function messaging_store_save in Messaging 6
Same name and namespace in other branches
- 5 messaging.store.inc \messaging_store_save()
- 6.2 messaging.store.inc \messaging_store_save()
- 6.3 messaging.store.inc \messaging_store_save()
Put into database storage, create one line for each destination
If there are many destinations they will be stored as 'multiple'
Parameters
$method: Sending method
$destinations: Array of destinations, the type of elements will depend on sending method
$message: Message array
$sent: Sent timestamp when used for logging
$queue: Should be 1 when this is a regular queue entry
$log: Should be 1 when this entry is to be kept as a log
$cron: Should be 1 when this entry is to be processed on cron (queueing for push methods)
File
- ./
messaging.store.inc, line 268 - Database storage for the messaging framework
Code
function messaging_store_save($message) {
// Normalize some values. Boolean parameters must be 0|1
foreach (array(
'queue',
'log',
'cron',
) as $field) {
$message->{$field} = empty($message->{$field}) ? 0 : 1;
}
// If sender is a user account, save sender field
if (!empty($message->sender_account)) {
$message->sender = $message->sender_account->uid;
}
// We just save the params for current sending method group
$group = messaging_method_info($message->method, 'group');
$params = !empty($params[$group]) ? $params[$group] : array();
// And there's one more optional param that is sender_name
if (!empty($message->sender_name)) {
$params['sender_name'] = $message->sender_name;
}
// Mark for a user if there's an account parameter, produced by messaging_send_user()
if (!empty($message->account)) {
$message->uid = $message->account->uid;
$message->destination = 'user:' . $message->uid;
}
// Save serialized destinations
if (!empty($message->destinations)) {
$params['destinations'] = $message->destinations;
}
// Check destination, but preserve field in case it is already set. I.e. 'all users'
if (empty($message->destination) && !empty($message->destinations)) {
// Check for multiple destinations, just store 'multiple'
// Bulk sending modules may store each destination differently
if (count($message->destinations) > 1) {
$message->destination = 'multiple';
}
elseif ($destination = $message->destinations[0]) {
if (is_string($destination) || is_numeric($destination)) {
$message->destination = $destination;
}
}
}
// Add parameters, timestamp and save
$message->params = $params ? $params : NULL;
$message->created = time();
drupal_write_record('messaging_store', $message);
// Finally, return the message object which should have a unique 'mqid'
return $message;
}