123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- <?php
- class MigrateDestinationPrivateMsg extends MigrateDestinationEntity {
-
- var $importedIds = array();
- static public function getKeySchema() {
- return array(
- 'mid' => array(
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- ),
- );
- }
-
- public function __construct(array $options = array()) {
- parent::__construct('privatemsg_message', 'privatemsg_message', $options);
- }
-
- public function fields() {
- $fields = array(
-
- 'subject' => 'Subject',
- 'body' => 'Body',
- 'format' => 'Text format name for the Body',
- 'recipients' => 'User IDs of recipients',
- 'timestamp' => 'Timestamp',
- 'author' => 'User ID of author',
- 'is_new' => 'TRUE if unread by recipient, FALSE if read by recipient',
- );
-
- $fields += migrate_handler_invoke_all('Entity', 'fields', $this->entityType, $this->bundle);
- $fields += migrate_handler_invoke_all('PrivateMsg', 'fields', $this->entityType, $this->bundle);
- return $fields;
- }
-
- public function rollback(array $id) {
- migrate_instrument_start(__METHOD__);
-
- db_delete('pm_index')
- ->condition('mid', reset($id))
- ->execute();
-
- db_delete('pm_message')
- ->condition('mid', reset($id))
- ->execute();
- migrate_instrument_stop(__METHOD__);
- }
-
- public function import(stdClass $entity, stdClass $row) {
- $this->prepare($entity, $row);
-
-
-
-
- $options = array();
- if (isset($entity->timestamp)) $options['timestamp'] = Migration::timestamp($entity->timestamp);
- if (isset($entity->author)) $options['author'] = user_load($entity->author);
- if (isset($entity->format)) $options['format'] = $entity->format;
- if (!is_array($entity->recipients)) {
- $entity->recipients = array($entity->recipients);
- }
- foreach ($entity->recipients as $uid) {
- $entity->to[] = user_load($uid);
- }
-
- $return = privatemsg_new_thread($entity->to, $entity->subject, $entity->body, $options);
- if (!empty($return['success'])) {
- $this->complete((object)$return, $row);
-
-
- $mid = $return['message']->mid;
- if (isset($entity->is_new) && $entity->is_new == PRIVATEMSG_READ) {
- foreach ($entity->to as $account) {
- privatemsg_message_change_status($mid, $entity->is_new, $account);
- }
- }
- return array($mid);
- }
- else {
- $migration = Migration::currentMigration();
- $migration->saveMessage(reset($return['messages']['error']));
- return FALSE;
- }
- }
- }
|