Advertisement
patrickt

1116408-118.diff

Feb 19th, 2016
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 4.81 KB | None | 0 0
  1. diff --git a/docroot/sites/all/modules/contrib/redirect/redirect.migrate.inc b/docroot/sites/all/modules/contrib/redirect/redirect.migrate.inc
  2. index a215cbd..5994d42 100644
  3. --- a/docroot/sites/all/modules/contrib/redirect/redirect.migrate.inc
  4. +++ b/docroot/sites/all/modules/contrib/redirect/redirect.migrate.inc
  5. @@ -18,7 +18,10 @@ class MigrateRedirectEntityHandler extends MigrateDestinationHandler {
  6.     * Overrides fields().
  7.     */
  8.    public function fields() {
  9. -    return array('migrate_redirects' => t('Original path(s) to redirect from.'));
  10. +    return array(
  11. +      'migrate_redirects' => t('Original path(s) to redirect from.'),
  12. +      'migrate_redirects_language' => t('The language this redirect applies to.')
  13. +    );
  14.    }
  15.  
  16.    /**
  17. @@ -38,17 +41,24 @@ class MigrateRedirectEntityHandler extends MigrateDestinationHandler {
  18.  
  19.      // Check that there there are no redirect loops.
  20.      $migration = Migration::currentMigration();
  21. +
  22.      if (url($redirect->source) == url($redirect->redirect)) {
  23. -      $migration->saveMessage(t('Redirect to self (!redirect) ignored',
  24. -                              array('!redirect' => $redirect->redirect)),
  25. -                  MigrationBase::MESSAGE_INFORMATIONAL);
  26. +      $migration->saveMessage(
  27. +        t('Redirect to self (!redirect) ignored',
  28. +        array('!redirect' => $redirect->redirect)),
  29. +        MigrationBase::MESSAGE_INFORMATIONAL
  30. +      );
  31. +
  32.        return FALSE;
  33.      }
  34. +
  35.      redirect_hash($redirect);
  36. +
  37.      if ($existing = redirect_load_by_hash($redirect->hash)) {
  38.        if ($redirect->rid != $existing->rid) {
  39.          $migration->saveMessage(t('The source path is already being redirected.'),
  40.            MigrationBase::MESSAGE_INFORMATIONAL);
  41. +
  42.          return FALSE;
  43.        }
  44.      }
  45. @@ -68,14 +78,43 @@ class MigrateRedirectEntityHandler extends MigrateDestinationHandler {
  46.      else {
  47.        $migrate_redirects = isset($entity->migrate_redirects) ? $entity->migrate_redirects : NULL;
  48.      }
  49. +
  50.      // If it is not an array already, make it one now.
  51.      if ($migrate_redirects && !is_array($migrate_redirects)) {
  52.        $migrate_redirects = array($migrate_redirects);
  53.      }
  54. +
  55.      return $migrate_redirects;
  56.    }
  57.  
  58.    /**
  59. +   * This determines the language for the current redirect.
  60. +   *
  61. +   * @param $entity
  62. +   * @param $row
  63. +   * @return string
  64. +   */
  65. +  protected function getRedirectLanguage($entity, $row) {
  66. +    //Defaults to the previous way.
  67. +    $language = empty($entity->language) ? LANGUAGE_NONE : $entity->language;
  68. +
  69. +    /**
  70. +     * This allows for more granular control. It also allows us to support
  71. +     * entity translations as well as node translations.
  72. +     *
  73. +     * Preference is given to a language specified in the mappings.
  74. +     */
  75. +    if (!empty($row->migrate_redirects_language)) {
  76. +      $language = $row->migrate_redirects_language;
  77. +    }
  78. +    else if (!empty($entity->migrate_redirects_language)) {
  79. +      $language = $entity->migrate_redirects_language;
  80. +    }
  81. +
  82. +    return $language;
  83. +  }
  84. +
  85. +  /**
  86.     * Overrides complete().
  87.     *
  88.     * @param object $entity
  89. @@ -88,22 +127,26 @@ class MigrateRedirectEntityHandler extends MigrateDestinationHandler {
  90.      $destination = $migration->getDestination();
  91.      $entity_type = $destination->getEntityType();
  92.      $migrate_redirects = $this->getRedirects($entity, $row);
  93. +    $redirect_destination = entity_uri($entity_type, $entity);
  94.  
  95.      // We looked up the destination entity_type in the constructor.
  96. -    if (!empty($migrate_redirects) && ($redirect_destination = entity_uri($entity_type, $entity))) {
  97. +    if (!empty($migrate_redirects) && !empty($redirect_destination)) {
  98.        foreach ($migrate_redirects as $path) {
  99.          $redirect_defaults = array(
  100.            'status_code' => 301,
  101.          );
  102. +
  103.          if (isset($entity->uid)) {
  104.            $redirect_defaults['uid'] = $entity->uid;
  105.          }
  106. -        $redirect_defaults['language'] = empty($entity->language) ? LANGUAGE_NONE : $entity->language;
  107. +
  108. +        $redirect_defaults['language'] = $this->getRedirectLanguage($entity, $row);
  109.          $redirect = new stdClass();
  110.          redirect_object_prepare($redirect, $redirect_defaults);
  111.          $redirect->redirect = $redirect_destination['path'];
  112.          $parsed = redirect_parse_url($path);
  113.          $redirect->source = isset($parsed['path']) ? ltrim($parsed['path'], '/') : '';
  114. +
  115.          if (!empty($parsed['query'])) {
  116.            $redirect->source_options['query'] = $parsed['query'];
  117.          }
  118. @@ -114,6 +157,10 @@ class MigrateRedirectEntityHandler extends MigrateDestinationHandler {
  119.          }
  120.        }
  121.      }
  122. +    else if (!empty($migrate_redirects) && empty($redirect_destination)) {
  123. +      $migration->saveMessage(t('The redirect path is empty.'),
  124. +        MigrationBase::MESSAGE_INFORMATIONAL);
  125. +    }
  126.    }
  127.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement