You are here

function migrate_build_url in Migrate 6.2

Same name and namespace in other branches
  1. 7.2 uri_map_redirect.php \migrate_build_url()
1 call to migrate_build_url()
uri_map_redirect.php in ./uri_map_redirect.php
Sample file for handling redirection from old to new URIs. Use an Apache rewrite rule (or equivalent) to map legacy requests to this file. To use, copy or symlink this file to the root of your drupal site. Customize this file to your needs.

File

./uri_map_redirect.php, line 23
Sample file for handling redirection from old to new URIs. Use an Apache rewrite rule (or equivalent) to map legacy requests to this file. To use, copy or symlink this file to the root of your drupal site. Customize this file to your needs.

Code

function migrate_build_url($destid1, $migration_name) {
  global $base_url;

  // TODO: Add an entry for each migration that we need to redirect.
  $patterns = variable_get('migrate_patterns', array(
    'BeerTerm' => 'taxonomy/term/:source_id',
    'BlogEntries' => 'node/:source_id',
    'Slideshows' => 'node/:source_id',
    'TagTerm' => 'taxonomy/term/:source_id',
  ));
  $pattern = $patterns[$migration_name];

  // Swap in the destination ID.
  $destination_uri = str_replace(':source_id', $destid1, $pattern);

  // For speed, we go right to aliases table rather than more bootstrapping.
  if ($uri_clean = db_query("SELECT alias FROM {url_alias} WHERE source = :destination_uri", array(
    ':destination_uri' => $destination_uri,
  ))
    ->fetchField()) {
    $destination_uri = $uri_clean;
  }

  // Build absolute url for 301 redirect.
  return $base_url . '/' . $destination_uri;
}