map = new MigrateSQLMap( $this->machineName, array( 'boardid' => array( 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, ), ), MigrateDestinationTerm::getKeySchema() ); $query = Database::getConnection('default', 'forum') ->select('wbb1_1_board', 'b') ->fields('b', array( 'boardid', 'parentid', 'title', 'description', 'allowdescriptionhtml', 'boardtype', 'image', 'externalurl', 'time', 'prefixes', 'prefixrequired', 'styleid', 'enforcestyle', 'daysprune', 'sortfield', 'sortorder', 'isclosed', 'countuserposts', 'isinvisible', 'showsubboards', 'clicks', 'threads', 'posts', )) ->orderBy('parentid', 'ASC'); $query ->leftJoin('wbb1_1_board_structure', 's', 'b.boardid = s.boardid'); $query ->fields('s', array( 'position', )); $this->source = new MigrateSourceSQL($query, array(), NULL, array('map_joinable' => FALSE)); $this->destination = new MigrateDestinationTerm('forums'); $this->addFieldMapping('name', 'title'); $this->addFieldMapping('description', 'description'); $this->addFieldMapping('parent', 'parentid') ->sourceMigration($this->machineName); $this->addFieldMapping('parent_name'); $this->addFieldMapping('weight', 'position'); } public function complete($entity, stdClass $row) { if (!$entity->parent || !$entity->parent[0]) { $this->addedContainers[] = $entity->tid; } } public function postImport() { $containers = variable_get('forum_containers', array()); foreach ($this->addedContainers as $container) { if (!in_array($entity->tid, $containers)) { $containers[] = $container; } } variable_set('forum_containers', $containers); } public function completeRollback($entity_id) { $this->deletedContainers[] = $entity_id; } public function postRollback() { $containers = variable_get('forum_containers', array()); $remaining = array(); foreach ($containers as $container) { if (!in_array($container, $this->deletedContainers) && !in_array($container, $remaining)) { $remaining[] = $container; } } variable_set('forum_containers', $remaining); } } class ConsoleroThreadMigration extends Migration { public function __construct() { parent::__construct(); $this->dependencies = array('ConsoleroBoard', 'ConsoleroUser'); $this->map = new MigrateSQLMap( $this->machineName, array( 'threadid' => array( 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, ), ), MigrateDestinationNode::getKeySchema() ); $query = Database::getConnection('default', 'forum') ->select('wbb1_1_thread', 't') ->fields('t', array( 'threadid', 'boardid', 'languageid', 'prefix', 'topic', 'firstpostid', 'firstpostpreview', 'time', 'userid', 'username', 'lastposttime', 'lastposterid', 'lastposter', 'replies', 'views', 'ratings', 'rating', 'attachments', 'polls', 'isannouncement', 'issticky', 'isdisabled', 'everenabled', 'isclosed', 'isdeleted', 'movedthreadid', 'deletetime', 'deletedby', 'deletedbyid', )); $query ->join('wbb1_1_post', 'p', 't.firstpostid = p.postid'); $query ->fields('p', array( 'message', // @todo: Weitere Felder nötig? )); $this->source = new MigrateSourceSQL($query, array(), NULL, array('map_joinable' => FALSE)); $this->destination = new MigrateDestinationNode('forum', array('text_format' => 'bbcode')); $this->addFieldMapping('is_new') ->defaultValue(TRUE); $this->addFieldMapping('uid', 'userid') ->sourceMigration('ConsoleroUser'); $this->addFieldMapping('created', 'time'); $this->addFieldMapping('status') ->defaultValue(1); $this->addFieldMapping('promote') ->defaultValue(0); $this->addFieldMapping('title', 'topic'); $this->addFieldMapping(NULL, 'prefix'); $this->addFieldMapping('taxonomy_forums', 'boardid') ->sourceMigration('ConsoleroBoard') ->arguments(array('source_type' => 'tid')); $this->addFieldMapping('body', 'message'); $this->addFieldMapping('comment') ->defaultValue(COMMENT_NODE_OPEN); } public function prepareRow(stdClass $row) { if ($row->prefix) { $row->topic = $row->prefix . ' ' . $row->topic; } } } class ConsoleroPostMigration extends Migration { public function __construct() { parent::__construct(); $this->dependencies = array('ConsoleroThread'); $this->map = new MigrateSQLMap( $this->machineName, array( 'postid' => array( 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, ), ), MigrateDestinationComment::getKeySchema() ); $query = Database::getConnection('default', 'forum') ->select('wbb1_1_post', 'p') ->fields('p', array( 'postid', 'threadid', 'parentpostid', 'userid', 'username', 'subject', 'message', 'time', 'isdeleted', 'everenabled', 'isdisabled', 'isclosed', 'editor', 'editorid', 'lastedittime', 'editcount', 'deletetime', 'deletedby', 'deletedbyid', 'attachments', 'pollid', 'enablesmilies', 'enablehtml', 'enablebbcodes', 'showsignature', 'ipaddress', )); $query ->join('wbb1_1_thread', 't', 't.threadid = p.threadid AND p.postid != t.firstpostid'); $query ->orderBy('postid', 'ASC'); $this->source = new MigrateSourceSQL($query, array(), NULL, array('map_joinable' => FALSE)); $this->destination = new MigrateDestinationComment( 'comment_node_forum', array('text_format' => 'bbcode') ); $this->addFieldMapping('nid', 'threadid') ->sourceMigration('ConsoleroThread'); $this->addFieldMapping('uid', 'userid') ->sourceMigration('ConsoleroUser'); $this->addFieldMapping('subject', 'subject'); $this->addFieldMapping('hostname', 'ipaddress'); $this->addFieldMapping('created', 'time'); $this->addFieldMapping('changed', 'lastedittime'); $this->addFieldMapping('status') ->defaultValue(COMMENT_PUBLISHED); $this->addFieldMapping('name', 'username'); $this->addFieldMapping('comment_body', 'message'); } public function prepareRow(stdClass $row) { // Überlange Titel abschneiden if (drupal_strlen($row->subject) > 50) { $row->subject = drupal_substr($row->subject, 0, 50) . '...'; } } }