You are here

public function WordPressAttachment::__construct in WordPress Migrate 7

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

Set it up

Overrides WordPressMigration::__construct

File

./wordpress_attachment.inc, line 35

Class

WordPressAttachment
Implementation of WordPressMigration, for attachments

Code

public function __construct(array $arguments = array()) {
  parent::__construct($arguments);
  $this->dependencies = array(
    $this
      ->generateMachineName('WordPressBlogEntry'),
    $this
      ->generateMachineName('WordPressPage'),
  );
  $dest_options = array(
    'copy_file' => TRUE,
  );

  // Make use of the media module if present
  if (module_exists('media') && module_exists('migrate_extras')) {
    $dest_options['source_migrations'] = $this->dependencies;
    $this->destination = new MigrateDestinationMedia('image', $dest_options);
    $keySchema = MigrateDestinationMedia::getKeySchema();
    $this
      ->addFieldMapping('media_title', 'title');
    $this
      ->addFieldMapping('media_description', 'content');
    $this
      ->addFieldMapping('file')
      ->issueGroup(t('DNM'));
  }
  else {
    $this->destination = new MigrateDestinationFile($dest_options);
    $keySchema = MigrateDestinationFile::getKeySchema();
    $this
      ->addFieldMapping(NULL, 'title')
      ->issueGroup(t('DNM'));
    $this
      ->addFieldMapping(NULL, 'content')
      ->issueGroup(t('DNM'));
  }

  // 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',
    ),
  ), $keySchema);

  // Construct the source object.
  $this->source = new WordPressAttachmentSource($this->wxrFile);
  $this
    ->addFieldMapping('fid')
    ->issueGroup(t('DNM'));
  $this
    ->addFieldMapping('uid', 'creator')
    ->description('Use matching username if any, otherwise current user');
  $this
    ->addFieldMapping('filename')
    ->description(t('Defaults to basename(uri)'));
  $this
    ->addFieldMapping('uri', 'attachment_url');
  $this
    ->addFieldMapping('filemime')
    ->description(t('Determined by default'));
  $this
    ->addFieldMapping('status')
    ->defaultValue(FILE_STATUS_PERMANENT);
  $this
    ->addFieldMapping('timestamp', 'post_date');
  $this
    ->addFieldMapping(NULL, 'post_parent')
    ->description('For attachments, indicates item attached to')
    ->issueGroup(t('Open issues'))
    ->issuePriority(MigrateFieldMapping::ISSUE_PRIORITY_MEDIUM);

  // Unmapped destination fields
  $this
    ->addFieldMapping('path')
    ->issueGroup(t('DNM'));

  // Unmapped source fields
  $this
    ->addFieldMapping(NULL, 'link')
    ->issueGroup(t('DNM'));
  $this
    ->addFieldMapping(NULL, 'guid')
    ->issueGroup(t('DNM'));
  $this
    ->addFieldMapping(NULL, 'description')
    ->issueGroup(t('DNM'));
  $this
    ->addFieldMapping(NULL, 'excerpt')
    ->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, 'comment_status')
    ->issueGroup(t('DNM'));
  $this
    ->addFieldMapping(NULL, 'ping_status')
    ->issueGroup(t('DNM'));
  $this
    ->addFieldMapping(NULL, 'post_name')
    ->issueGroup(t('DNM'));
  $this
    ->addFieldMapping(NULL, 'status')
    ->issueGroup(t('DNM'));
  $this
    ->addFieldMapping(NULL, 'menu_order')
    ->issueGroup(t('DNM'));
  $this
    ->addFieldMapping(NULL, 'post_type')
    ->issueGroup(t('DNM'));
  $this
    ->addFieldMapping(NULL, 'post_password')
    ->issueGroup(t('DNM'));
  $this
    ->addFieldMapping(NULL, 'is_sticky')
    ->issueGroup(t('DNM'));
  $this
    ->addFieldMapping(NULL, 'category')
    ->issueGroup(t('DNM'));
  $this
    ->addFieldMapping(NULL, '_wp_attached_file')
    ->issueGroup(t('DNM'));
  $this
    ->addFieldMapping(NULL, '_wp_attachment_metadata')
    ->issueGroup(t('DNM'));
}