Пример миграции контента из vBulletin 3 в Drupal 7: ответы в темах (комментарии)

Опубликовано в ср, 11/01/2012 - 22:48
drupal migrate vbulletin импорт работа с комментариями
Завершающий пост про миграцию данных из vBulletin в Drupal.

Импорт комментариев:

class CommentsMigration extends Migration {
  public function __construct() {
    parent::__construct();
    $this->dependencies = array(
      'Threads', // http://xandeadx.ru/blog/drupal/513
      'Users',   // http://xandeadx.ru/blog/drupal/510
    );
 
    // Source
    $query = Database::getConnection('default', 'vbulletin')->select('post', 'p');
    $query->fields('p', array('postid', 'threadid', 'title', 'pagetext', 'userid', 'username', 'dateline', 'ipaddress', 'visible'));
    $query->innerJoin('thread', 't', 't.threadid = p.threadid');
    $query->where('p.postid != t.firstpostid');
    $query->orderBy('p.postid');
    $this->source = new MigrateSourceSQL($query, array(), NULL, array('map_joinable' => FALSE));
 
    // Destination
    $this->destination = new MigrateDestinationComment('comment_node_post');
 
    // Key schema
    $source_key_schema = array('postid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE));
    $this->map = new MigrateSQLMap($this->machineName, $source_key_schema, MigrateDestinationComment::getKeySchema());
 
    // Mapping
    $this->addFieldMapping('nid', 'threadid')->sourceMigration('Threads');
    $this->addFieldMapping('uid', 'userid')->sourceMigration('Users');
    $this->addFieldMapping('subject', 'title');
    $this->addFieldMapping('comment_body', 'pagetext');
    $this->addFieldMapping('comment_body:format')->defaultValue('filtered_html');
    $this->addFieldMapping('hostname', 'ipaddress');
    $this->addFieldMapping('created', 'dateline');
    $this->addFieldMapping('status', 'visible');
    $this->addFieldMapping('name', 'username');
  }
 
  public function prepareRow($row) {
    // Title
    $row->title = htmlspecialchars_decode($row->title);
    $row->title = drupal_substr($row->title, 0, 64);
 
    // Body
    $row->pagetext = bbcode_to_html($row->pagetext); // http://bit.ly/OrFVN5
 
    // Status
    if ($row->visible == 2) {
      $row->visible = 0;
    }
    else {
      $row->visible = 1;
    }
  }
}

Написанное актуально для
Migrate 7.x-2.4
Теги:
migrate, vbulletin, импорт, работа с комментариями
Добавлено: 30 Июля 2018 07:27:23 Добавил: Андрей Ковальчук Нравится 0
Добавить
Комментарии:
Нету комментариев для вывода...