You are here

protected function MigrateRedirectEntityHandler::redirectValidate in Redirect 7

Same name and namespace in other branches
  1. 7.2 redirect.migrate.inc \MigrateRedirectEntityHandler::redirectValidate()

Validates a redirect.

We need to check if a redirect already exists. Calling redirect_save on an already existing redirect will throw a db error due to duplicate entries.

This function is similar to the validate function in the redirect module but the feedback is handled via the Migrate's saveMessage functionality.

Return value

bool TRUE if the redirect is valid and can be saved.

1 call to MigrateRedirectEntityHandler::redirectValidate()
MigrateRedirectEntityHandler::complete in ./redirect.migrate.inc
Overrides complete().

File

./redirect.migrate.inc, line 39
Migrate support for Redirect module.

Class

MigrateRedirectEntityHandler
@file Migrate support for Redirect module.

Code

protected function redirectValidate($redirect) {
  $redirect = (object) $redirect;

  // Check that there there are no redirect loops.
  $migration = Migration::currentMigration();
  if (url($redirect->source) == url($redirect->redirect)) {
    $migration
      ->saveMessage(t('Redirect to self (!redirect) ignored', array(
      '!redirect' => $redirect->redirect,
    )), MigrationBase::MESSAGE_INFORMATIONAL);
    return FALSE;
  }
  redirect_hash($redirect);
  if ($existing = redirect_load_by_hash($redirect->hash)) {
    if ($redirect->rid != $existing->rid) {
      $migration
        ->saveMessage(t('The source path is already being redirected.'), MigrationBase::MESSAGE_INFORMATIONAL);
      return FALSE;
    }
  }
  return TRUE;
}