Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- abstract class NodesMigration extends Migration {
- public function __construct(array $arguments) {
- parent::__construct();
- $type = isset($arguments['type']) ? $arguments['type'] : NULL;
- $new_type = isset($arguments['new type']) ? $arguments['new type'] : $type;
- $this->description = t('Migrate nodes');
- $this->map = new MigrateSQLMap($this->machineName,
- array(
- 'nid' => array(
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'description' => 'D5 Unique User ID',
- 'alias' => 'n',
- )
- ),
- MigrateDestinationNode::getKeySchema()
- );
- $query = $this->node_query($type);
- $this->set_highwater_field();
- $this->set_source($query);
- $this->destination = new MigrateDestinationNode($new_type);
- $this->node_field_mapping();
- }
- public function set_highwater_field() {
- $this->highwaterField = array(
- 'name' => 'changed',
- 'alias' => 'n',
- );
- }
- public function node_query($type) {
- $query = Database::getConnection('d5')
- ->select('node', 'n')
- ->fields('n', array('nid', 'vid', 'title', 'uid', 'status', 'created', 'changed', 'comment', 'promote', 'moderate', 'sticky'))
- ->condition('n.type', $type);
- $query->join('node_revisions', 'nr', 'nr.vid = n.vid');
- $query->fields('nr', array('body', 'teaser', 'format'));
- return $query;
- }
- public function set_source($query) {
- $this->source = new MigrateSourceSQL($query);
- $this->source->setMapJoinable(FALSE);
- }
- public function node_field_mapping() {
- $body_arguments = MigrateTextFieldHandler::arguments(array('source_field' => 'teaser'), array('source_field' => 'format'), NULL);
- // Make the mappings
- $this->addFieldMapping('nid', 'nid');
- $this->addFieldMapping('vid', 'vid');
- $this->addFieldMapping('title', 'title');
- $this->addFieldMapping('uid', 'uid');
- $this->addFieldMapping('status', 'status');
- $this->addFieldMapping('created', 'created');
- $this->addFieldMapping('changed', 'changed');
- $this->addFieldMapping('comment', 'comment');
- $this->addFieldMapping('promote', 'promote');
- $this->addFieldMapping('moderate', 'moderate');
- $this->addFieldMapping('sticky', 'sticky');
- $this->addFieldMapping('body', 'body')->arguments($body_arguments);
- $this->addFieldMapping('language')->defaultValue('und');
- $this->addFieldMapping('is_new')->defaultValue(TRUE);
- }
- public function prepareRow($current_row) {
- $formats = array(
- '1' => 'filtered_html',
- '2' => 'php_code',
- '3' => 'full_html',
- );
- $current_row->format = isset($formats[$current_row->format]) ? $formats[$current_row->format] : 'plain_text';
- }
- }
- class NodeLinkMigration extends NodesMigration {
- public function __construct() {
- parent::__construct(array('type' => 'link'));
- }
- public function node_query() {
- $query = Database::getConnection('d5')
- ->select('links_links', 'll')
- ->fields('ll', array('name', 'description', 'active', 'url'));
- $query->join('links_categories', 'lc', 'll.category = lc.id');
- $query->fields('lc', array('name'));
- return $query;
- }
- public function set_highwater_field() {}
- public function node_field_mapping() {
- $body_arguments = MigrateTextFieldHandler::arguments(array('source_field' => 'description'));
- // Make the mappings
- $this->addFieldMapping('title', 'name');
- $this->addFieldMapping('uid')->defaultValue(2);
- $this->addFieldMapping('status', 'active');
- $this->addFieldMapping('body', 'description')->arguments($body_arguments);
- $this->addFieldMapping('language')->defaultValue('und');
- $this->addFieldMapping('is_new')->defaultValue(TRUE);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment