You are here

public function MigratePathEntityHandler::prepare in Migrate 7.2

File

plugins/destinations/path.inc, line 24
Support for paths in core Drupal objects

Class

MigratePathEntityHandler
@file Support for paths in core Drupal objects

Code

public function prepare($entity, stdClass $row) {
  if (module_exists('path') && isset($entity->path)) {

    // Make sure the alias doesn't already exist
    $query = db_select('url_alias')
      ->condition('alias', $entity->path)
      ->condition('language', $entity->language);
    $query
      ->addExpression('1');
    $query
      ->range(0, 1);
    if (!$query
      ->execute()
      ->fetchField()) {
      $path = $entity->path;
      $entity->path = array();
      $entity->path['alias'] = $path;
    }
    else {
      unset($entity->path);
    }
  }
}