Drupal → Пример миграции контента из vBulletin 3 в Drupal 7: ответы в темах (комментарии)
Завершающий пост про миграцию данных из vBulletin в Drupal.
Импорт комментариев:
class CommentsMigration extends Migration { public function __construct($arguments) { parent::__construct($arguments); $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) { if (parent::prepareRow($row) === FALSE) { return FALSE; } // 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; } } }
Оставить комментарий