You are here

public function WordPressItemMigration::__construct in WordPress Migrate 7

Same name and namespace in other branches
  1. 7.2 wordpress_item.inc \WordPressItemMigration::__construct()

Set it up

Overrides WordPressMigration::__construct

2 calls to WordPressItemMigration::__construct()
WordPressBlogEntry::__construct in ./wordpress_item.inc
Set it up
WordPressPage::__construct in ./wordpress_item.inc
Set it up
2 methods override WordPressItemMigration::__construct()
WordPressBlogEntry::__construct in ./wordpress_item.inc
Set it up
WordPressPage::__construct in ./wordpress_item.inc
Set it up

File

./wordpress_item.inc, line 163
Support for migrating posts and pages from a WordPress blog into Drupal.

Class

WordPressItemMigration
Intermediate Migration class, implementing behavior common across different types (post_type) of items.

Code

public function __construct(array $arguments = array()) {
  parent::__construct($arguments);
  $this->dependencies = array(
    $this
      ->generateMachineName('WordPressCategory'),
    $this
      ->generateMachineName('WordPressTag'),
  );

  // WordPress post type
  $post_type = $arguments['post_type'];

  // Drupal content type (bundle)
  $bundle = $arguments['bundle'];

  // post_id is the unique ID of items in WordPress
  $this->map = new MigrateSQLMap($this->machineName, array(
    'post_id' => array(
      'type' => 'int',
      'not null' => TRUE,
      'unsigned' => TRUE,
      'description' => 'WordPress post ID',
    ),
  ), MigrateDestinationNode::getKeySchema());

  // Construct the source objects.
  $this->source = new WordPressItemSource($this->wxrFile, $post_type);
  $this->destination = new MigrateDestinationNode($bundle);

  // Default mappings, applying to most or all migrations
  $this
    ->addFieldMapping('title', 'title');
  $this
    ->addFieldMapping('created', 'post_date')
    ->description('Empty dates handled in prepare()');
  $this
    ->addFieldMapping('changed', 'post_date')
    ->description('Empty dates handled in prepare()');
  $this
    ->addFieldMapping('uid', 'creator')
    ->description('Use matching username if any, otherwise current user');
  $text_format = variable_get('wordpress_migrate_text_format', 'filtered_html');
  $arguments = array(
    'source_field' => 'excerpt',
    'format' => $text_format,
  );
  $this
    ->addFieldMapping('body', 'content')
    ->arguments($arguments);
  $this
    ->addFieldMapping(NULL, 'excerpt');
  $this
    ->addFieldMapping('comment', 'comment_status')
    ->description('WP "open" mapped to Drupal COMMENT_NODE_OPEN');
  $this
    ->addFieldMapping('status', 'status')
    ->description('Set Drupal status to 1 iff wp:status=publish');
  $this
    ->addFieldMapping(NULL, 'post_parent')
    ->description('For attachments, indicates item attached to')
    ->issueGroup(t('Open issues'))
    ->issuePriority(MigrateFieldMapping::ISSUE_PRIORITY_MEDIUM);
  $this
    ->addFieldMapping('sticky', 'is_sticky');
  if (module_exists('path')) {
    $this
      ->addFieldMapping('path', 'link')
      ->description(t('If no ? in the link, strip the domain for the path'));
    if (module_exists('pathauto')) {
      $this
        ->addFieldMapping('pathauto_perform_alias')
        ->defaultValue(0)
        ->description('Disable pathauto, we set the alias from the WP link');
    }
  }

  // Map the source fields to the configured vocabularies
  $vocabs = array(
    'tag' => variable_get('wordpress_migrate_tag_vocabulary', ''),
    'category' => variable_get('wordpress_migrate_category_vocabulary', ''),
  );

  // Look through this content type's fields for term references
  foreach ($this->destination
    ->fields() as $machine_name => $description) {
    if (preg_match('/\\(taxonomy_term_reference\\)$/', $description)) {
      $field_info = field_info_field($machine_name);

      // Check this field against each of the configured vocabularies - if
      // a match is found, make the mapping
      foreach ($vocabs as $source_field => $vocab_name) {
        if ($vocab_name == $field_info['settings']['allowed_values'][0]['vocabulary']) {
          if ($source_field == 'tag') {
            $sourceMigration = $this
              ->generateMachineName('WordPressTag');
          }
          else {
            $sourceMigration = $this
              ->generateMachineName('WordPressCategory');
          }
          $this
            ->addFieldMapping($machine_name, $source_field)
            ->arguments(array(
            'source_type' => 'tid',
          ))
            ->sourceMigration($sourceMigration);
          unset($vocabs[$source_field]);
        }
      }
    }
  }

  // If we didn't map one or both of the tag/category fields, indicate so with
  // a DNM mapping.
  foreach ($vocabs as $source_field => $vocab_name) {
    if ($vocab_name) {
      $message = t('!vocab_name vocabulary is not assigned to node type !bundle', array(
        '!vocab_name' => $vocab_name,
        '!bundle' => $bundle,
      ));
    }
    else {
      $message = t('No vocabulary assigned for this field');
    }
    $this
      ->addFieldMapping(NULL, $source_field)
      ->description($message)
      ->issueGroup(t('DNM'));
  }

  // Unmapped destination fields
  $this
    ->addFieldMapping('is_new')
    ->issueGroup(t('DNM'));
  $this
    ->addFieldMapping('revision')
    ->issueGroup(t('DNM'));
  $this
    ->addFieldMapping('language')
    ->issueGroup(t('DNM'));
  $this
    ->addFieldMapping('promote')
    ->issueGroup(t('DNM'));
  $this
    ->addFieldMapping('revision_uid')
    ->issueGroup(t('DNM'));

  // Unmapped source fields
  $this
    ->addFieldMapping(NULL, 'guid')
    ->description('same as link, plus isPermaLink attribute?')
    ->issueGroup(t('DNM'));
  $this
    ->addFieldMapping(NULL, 'description')
    ->description('Always empty?')
    ->issueGroup(t('DNM'));
  $this
    ->addFieldMapping(NULL, 'post_id')
    ->description(t('Primary key of source'))
    ->issueGroup(t('DNM'));
  $this
    ->addFieldMapping(NULL, 'pubDate')
    ->description('Use post_date')
    ->issueGroup(t('DNM'));
  $this
    ->addFieldMapping(NULL, 'post_date_gmt')
    ->description('Use post_date')
    ->issueGroup(t('DNM'));
  $this
    ->addFieldMapping(NULL, 'ping_status')
    ->description('What does this mean?')
    ->issueGroup(t('Open issues'))
    ->issuePriority(MigrateFieldMapping::ISSUE_PRIORITY_MEDIUM);
  $this
    ->addFieldMapping(NULL, 'post_name')
    ->description('Looks like last component of path')
    ->issueGroup(t('DNM'));
  $this
    ->addFieldMapping(NULL, 'menu_order')
    ->issueGroup(t('DNM'));
  $this
    ->addFieldMapping(NULL, 'post_type')
    ->issueGroup(t('DNM'));
  $this
    ->addFieldMapping(NULL, 'post_password')
    ->description('???')
    ->issueGroup(t('DNM'));
}