Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/docroot/sites/all/modules/contrib/redirect/redirect.migrate.inc b/docroot/sites/all/modules/contrib/redirect/redirect.migrate.inc
- index a215cbd..5994d42 100644
- --- a/docroot/sites/all/modules/contrib/redirect/redirect.migrate.inc
- +++ b/docroot/sites/all/modules/contrib/redirect/redirect.migrate.inc
- @@ -18,7 +18,10 @@ class MigrateRedirectEntityHandler extends MigrateDestinationHandler {
- * Overrides fields().
- */
- public function fields() {
- - return array('migrate_redirects' => t('Original path(s) to redirect from.'));
- + return array(
- + 'migrate_redirects' => t('Original path(s) to redirect from.'),
- + 'migrate_redirects_language' => t('The language this redirect applies to.')
- + );
- }
- /**
- @@ -38,17 +41,24 @@ class MigrateRedirectEntityHandler extends MigrateDestinationHandler {
- // 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);
- + $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;
- }
- }
- @@ -68,14 +78,43 @@ class MigrateRedirectEntityHandler extends MigrateDestinationHandler {
- else {
- $migrate_redirects = isset($entity->migrate_redirects) ? $entity->migrate_redirects : NULL;
- }
- +
- // If it is not an array already, make it one now.
- if ($migrate_redirects && !is_array($migrate_redirects)) {
- $migrate_redirects = array($migrate_redirects);
- }
- +
- return $migrate_redirects;
- }
- /**
- + * This determines the language for the current redirect.
- + *
- + * @param $entity
- + * @param $row
- + * @return string
- + */
- + protected function getRedirectLanguage($entity, $row) {
- + //Defaults to the previous way.
- + $language = empty($entity->language) ? LANGUAGE_NONE : $entity->language;
- +
- + /**
- + * This allows for more granular control. It also allows us to support
- + * entity translations as well as node translations.
- + *
- + * Preference is given to a language specified in the mappings.
- + */
- + if (!empty($row->migrate_redirects_language)) {
- + $language = $row->migrate_redirects_language;
- + }
- + else if (!empty($entity->migrate_redirects_language)) {
- + $language = $entity->migrate_redirects_language;
- + }
- +
- + return $language;
- + }
- +
- + /**
- * Overrides complete().
- *
- * @param object $entity
- @@ -88,22 +127,26 @@ class MigrateRedirectEntityHandler extends MigrateDestinationHandler {
- $destination = $migration->getDestination();
- $entity_type = $destination->getEntityType();
- $migrate_redirects = $this->getRedirects($entity, $row);
- + $redirect_destination = entity_uri($entity_type, $entity);
- // We looked up the destination entity_type in the constructor.
- - if (!empty($migrate_redirects) && ($redirect_destination = entity_uri($entity_type, $entity))) {
- + if (!empty($migrate_redirects) && !empty($redirect_destination)) {
- foreach ($migrate_redirects as $path) {
- $redirect_defaults = array(
- 'status_code' => 301,
- );
- +
- if (isset($entity->uid)) {
- $redirect_defaults['uid'] = $entity->uid;
- }
- - $redirect_defaults['language'] = empty($entity->language) ? LANGUAGE_NONE : $entity->language;
- +
- + $redirect_defaults['language'] = $this->getRedirectLanguage($entity, $row);
- $redirect = new stdClass();
- redirect_object_prepare($redirect, $redirect_defaults);
- $redirect->redirect = $redirect_destination['path'];
- $parsed = redirect_parse_url($path);
- $redirect->source = isset($parsed['path']) ? ltrim($parsed['path'], '/') : '';
- +
- if (!empty($parsed['query'])) {
- $redirect->source_options['query'] = $parsed['query'];
- }
- @@ -114,6 +157,10 @@ class MigrateRedirectEntityHandler extends MigrateDestinationHandler {
- }
- }
- }
- + else if (!empty($migrate_redirects) && empty($redirect_destination)) {
- + $migration->saveMessage(t('The redirect path is empty.'),
- + MigrationBase::MESSAGE_INFORMATIONAL);
- + }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement