You are here

protected function WordPressItemMigration::replaceLinks in WordPress Migrate 7

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

If we have a local link of the form ?p=34, translate the WordPress ID into a Drupal nid, and rewrite the link.

Parameters

array $matches:

File

./wordpress_item.inc, line 514
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

protected function replaceLinks(array $matches) {

  // Default to the existing string
  $return = $matches[0];
  $wordpress_id = (int) $matches[1];

  // Check the blog entry and page maps to see if we can map this to a nid
  static $maps = array();
  if (empty($maps)) {
    $machines = array(
      $this
        ->generateMachineName('WordPressBlogEntry'),
      $this
        ->generateMachineName('WordPressPage'),
    );
    foreach ($machines as $machine) {
      $maps[] = MigrationBase::getInstance($machine)
        ->getMap();
    }
  }
  foreach ($maps as $map) {
    $destination_id = $map
      ->lookupDestinationID(array(
      $wordpress_id,
    ), $this);
    if (!empty($destination_id)) {

      // Got a hit! Stop looking...
      $destination_id = reset($destination_id);
      break;
    }
  }

  // Remember if we didn't get a hit, complete() will set up for later review
  if (empty($destination_id)) {
    $this->linksNeedFixing = TRUE;
  }
  else {
    $return = 'href="/node/' . $destination_id . '"';
  }
  return $return;
}