You are here

public function WordPressItemMigration::__construct in WordPress Migrate 7.2

Same name and namespace in other branches
  1. 7 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 145
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);

  // WordPress post type
  $this->postType = $this->arguments['post_type'];

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

  // Save tag/category fields (used in prepare()).
  if (isset($arguments['tag_field'])) {
    $this->tagField = $arguments['tag_field'];
  }
  if (isset($arguments['category_field'])) {
    $this->categoryField = $arguments['category_field'];
  }

  // post_id is the unique ID of items in WordPress
  $this->map = new MigrateSQLMap($this->machineName, array(
    'wp: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, $this->postType, $this->machineName, $this->arguments['namespaces']);
  $this->destination = new MigrateDestinationNode($bundle);

  // Default mappings, applying to most or all migrations
  $this
    ->addFieldMapping('title', 'title')
    ->xpath('title');
  $this
    ->addFieldMapping('created', 'wp:post_date')
    ->xpath('wp:post_date')
    ->description('Empty dates handled in prepare()');
  $this
    ->addFieldMapping('changed', 'wp:post_date')
    ->xpath('wp:post_date')
    ->description('Empty dates handled in prepare()');

  // If we have a separate author migration, use it here
  $uid_mapping = $this
    ->addFieldMapping('uid', 'dc:creator')
    ->xpath('dc:creator')
    ->description('Use matching username if any, otherwise current user');
  if ($this->blog
    ->getWxrVersion() != '1.0') {
    if (!empty($arguments['author_migration'])) {
      $author_migration = $arguments['author_migration'];
    }
    else {
      $author_migration = $this->group
        ->getName() . 'Author';
    }
    $uid_mapping
      ->sourceMigration($author_migration);
  }
  $this
    ->addFieldMapping('body', 'content');
  $this
    ->addFieldMapping('body:summary', 'excerpt:encoded')
    ->xpath('excerpt:encoded');
  $this
    ->addFieldMapping('body:format')
    ->defaultValue($this->arguments['text_format']);
  if (module_exists('comment')) {
    $this
      ->addFieldMapping('comment', 'wp:comment_status')
      ->xpath('wp: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, 'wp:post_parent')
    ->xpath('wp:post_parent')
    ->description('Only applies to attachments');
  $this
    ->addFieldMapping('sticky', 'wp:is_sticky')
    ->xpath('wp:is_sticky');
  if (module_exists('path')) {
    switch ($this->arguments['path_action']) {

      // Do not set path aliases
      case 0:
        $this
          ->addFieldMapping('path');
        if (!module_exists('redirect')) {
          $this
            ->addFieldMapping(NULL, 'link');
        }
        if (module_exists('pathauto')) {
          $this
            ->addFieldMapping('pathauto')
            ->defaultValue(0);
        }
        break;

      // Set path aliases to their original WordPress values
      case 1:
        $this
          ->addFieldMapping('path', 'link');
        if (module_exists('pathauto')) {
          $this
            ->addFieldMapping('pathauto')
            ->defaultValue(0);
        }
        break;

      // Have pathauto generate new aliases
      case 2:
        $this
          ->addFieldMapping('path');
        if (!module_exists('redirect')) {
          $this
            ->addFieldMapping(NULL, 'link');
        }
        if (module_exists('pathauto')) {
          $this
            ->addFieldMapping('pathauto')
            ->defaultValue(1);
        }
        break;
    }
  }
  if (module_exists('redirect')) {
    if ($this->arguments['generate_redirects']) {
      $this
        ->addFieldMapping('migrate_redirects', 'link');
    }
    else {
      $this
        ->addFieldMapping('migrate_redirects');
      $this
        ->addFieldMapping(NULL, 'link');
    }
  }
  if (module_exists('taxonomy')) {

    // Map the source fields to the configured vocabularies. Note the nicename
    // (WordPress machine name) is used for matching on sourceMigration - we
    // pull the actual tag/category separately in case we need to handle it
    // in prepare().
    if ($this->tagField) {
      $this
        ->addFieldMapping($this->tagField, 'tag')
        ->sourceMigration($arguments['group_name'] . $arguments['tag_migration'])
        ->xpath('category[@domain="post_tag"]/@nicename');
      $this
        ->addFieldMapping(NULL, 'tag_value')
        ->xpath('category[@domain="post_tag"]');
      $this
        ->addFieldMapping($this->tagField . ':source_type')
        ->defaultValue('tid');
    }
    else {
      $this
        ->addFieldMapping(NULL, 'tag');
    }
    if ($this->categoryField) {
      $this
        ->addFieldMapping($this->categoryField, 'category')
        ->sourceMigration($arguments['group_name'] . $arguments['category_migration'])
        ->xpath('category[@domain="category"]/@nicename');
      $this
        ->addFieldMapping(NULL, 'category_value')
        ->xpath('category[@domain="category"]');
      $this
        ->addFieldMapping($this->categoryField . ':source_type')
        ->defaultValue('tid');
    }
    else {
      $this
        ->addFieldMapping(NULL, 'category');
    }
  }

  // If podcast migration is requested, add the mapping.
  $podcast_field = $this->arguments['podcast_field'];
  if ($podcast_field) {
    $this
      ->addFieldMapping($podcast_field, 'enclosure')
      ->callbacks(array(
      $this,
      'handleEnclosure',
    ));
  }

  // If an attachment field is configured, document the mapping.
  $attachment_field = $this->arguments['attachment_field'];
  if ($attachment_field) {
    $this
      ->addFieldMapping($attachment_field)
      ->description('Attachment field populated later by attachment migration');
  }

  // Unmapped destination fields
  $this
    ->addUnmigratedDestinations(array(
    'is_new',
    'revision',
    'language',
    'promote',
    'revision_uid',
    'log',
    'tnid',
    'translate',
    'body:language',
  ));

  // Unmapped source fields
  $this
    ->addUnmigratedSources(array(
    'wp:post_id',
    'wp:menu_order',
    'wp:post_type',
  ));
  $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, 'pubDate')
    ->description('Use post_date')
    ->issueGroup(t('DNM'));
  $this
    ->addFieldMapping(NULL, 'wp:post_date_gmt')
    ->description('Use post_date')
    ->issueGroup(t('DNM'));
  $this
    ->addFieldMapping(NULL, 'wp:ping_status')
    ->description('What does this mean?')
    ->issueGroup(t('Open issues'))
    ->issuePriority(MigrateFieldMapping::ISSUE_PRIORITY_MEDIUM);
  $this
    ->addFieldMapping(NULL, 'wp:post_name')
    ->description('Looks like last component of path')
    ->issueGroup(t('DNM'));
  $this
    ->addFieldMapping(NULL, 'wp:post_password')
    ->description('???')
    ->issueGroup(t('DNM'));
}