You are here

protected static function Messaging_Store::message_prepare in Messaging 6.4

Prepare for storage

1 call to Messaging_Store::message_prepare()
Messaging_Store::message_save in includes/messaging_store.class.inc
Put into database storage, create one line for each destination

File

includes/messaging_store.class.inc, line 443
Database storage for the messaging framework

Class

Messaging_Store
Default storage and queueing system for Messaging

Code

protected static function message_prepare($message) {

  // On this store we can just save messages prepared and rendered
  $message
    ->prepare();
  $message
    ->render();

  // Set created date if not previously set
  if (empty($message->created)) {
    $message->created = time();
  }

  // Normalize some values. Boolean parameters must be 0|1
  foreach (array(
    'queue',
    'log',
    'cron',
  ) as $field) {
    $message->{$field} = empty($message->{$field}) ? 0 : 1;
  }

  // Add fields to serialize. All persistent properties that are not in the schema
  $schema = drupal_get_schema(self::DB_TABLE);
  $serialize_fields = array_diff($message
    ->data_fields(), array_keys($schema['fields']));
  foreach ($serialize_fields as $field) {
    if (isset($message->{$field})) {
      $data[$field] = $message->{$field};
    }
  }
  $message->data = !empty($data) ? $data : NULL;
}