You are here

function MigrateDestinationPrivatemsg::_privatemsg_migrate_save in Migrate Extras 6.2

1 call to MigrateDestinationPrivatemsg::_privatemsg_migrate_save()
MigrateDestinationPrivatemsg::import in ./privatemsg.inc
Import a single private message.

File

./privatemsg.inc, line 61
Support for the Privatemsg module.

Class

MigrateDestinationPrivatemsg
Destination class implementing

Code

function _privatemsg_migrate_save($message) {

  // @TODO: We should probably be running this here. Though $message is in
  // the wrong format to do it and I'm not sure what other implications it
  // will have. Same goes for the privatemsg_message_insert() hook at the
  // end of this function.
  // drupal_alter('privatemsg_message_presave', $message);
  // Save the message body.
  db_query("INSERT INTO {pm_message} (subject, author, body, format, timestamp) VALUES ('%s', %d, '%s', %d, %d)", $message->subject, $message->author, $message->body, $message->format, $message->timestamp);
  $mid = db_last_insert_id('pm_message', 'mid');
  $message->mid = $mid;

  // Save message to recipients.
  // @TODO: If we want to support importing of threaded messages, then this
  // needs some work.
  // Set the thread to match the message
  $message->thread_id = $mid;
  $index_sql = "INSERT INTO {pm_index} (mid, thread_id, uid, is_new, deleted) VALUES (%d, %d, %d, %d, %d)";
  db_query($index_sql, $mid, $message->thread_id, $message->recipient, $message->recipient_is_new, $message->recipient_del);

  // Also add a record for the author to the pm_index table.
  db_query($index_sql, $mid, $message->thread_id, $message->author, $message->author_is_new, $message->recipient_del);

  // module_invoke_all('privatemsg_message_insert', $message);
  // Assuming success
  $message->success = TRUE;
  return $message;
}