You are here

protected function WordPressItemSource::populateRow in WordPress Migrate 7

Parse the values out of the item element.

Parameters

SimpleXMLElement $item:

Return value

boolean

File

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

Class

WordPressItemSource
Implementation of MigrateSource, to handle migrating items from WordPress XML dumps.

Code

protected function populateRow($item) {

  // Pull non-namespaced items
  foreach ($item as $name => $value) {
    $this->currentRow->{$name} = (string) $value;
  }

  // Now check each namespace
  $namespaces = $item
    ->getNameSpaces(TRUE);
  foreach ($namespaces as $ns => $nsuri) {
    $item_ns = $item
      ->children($namespaces[$ns]);
    foreach ($item_ns as $name => $value) {

      // Special-case content:encoded and excerpt:encoded, which otherwise
      // would both be saved as "encoded"
      if ($name == 'encoded') {
        $this->currentRow->{$ns} = (string) $value;
      }
      else {
        $this->currentRow->{$name} = (string) $value;
      }
    }
  }

  // Make sure this is the desired post type
  if ($this->currentRow->post_type != $this->postType) {
    $this->currentRow = NULL;
    return FALSE;
  }

  // The category field is now the descriptive name, we want the nicename
  $this->currentRow->category = array();

  // The tag domain changed with WXR version 1.1
  $migration = Migration::currentMigration();
  $wxr_version = $this->xml
    ->xpath('//channel/wp:wxr_version');
  $wxr_version = (double) reset($wxr_version);
  if ($wxr_version < 1.1) {
    $tag_domain = 'tag';
  }
  else {
    $tag_domain = 'post_tag';
  }
  foreach ($item->category as $cat) {
    $attributes = $cat
      ->attributes();
    $domain = $attributes->domain;
    $nicename = $attributes->nicename;
    if ($nicename) {
      $nicename = (string) $nicename[0];
      if ($domain == 'category') {
        $this->currentRow->category[] = $nicename;
      }
      if ($domain == $tag_domain) {
        $this->currentRow->tag[] = $nicename;
      }
    }
  }
  $this->currentKey = array(
    $this->currentRow->post_id,
  );
  return TRUE;
}