From 9d1d11110ce1a61cdab004be324151b58a3452bd Mon Sep 17 00:00:00 2001
From: Tim Steiner <tsteiner2@unl.edu>
Date: Wed, 3 Nov 2010 21:00:49 +0000
Subject: [PATCH] In the migration tool, when a redirect is found, update the
 link to point to the new location.

git-svn-id: file:///tmp/wdn_thm_drupal/trunk@285 20a16fea-79d4-4915-8869-1ea9d5ebf173
---
 sites/all/modules/unl/unl_migration.php | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/sites/all/modules/unl/unl_migration.php b/sites/all/modules/unl/unl_migration.php
index b2bbc16e..e8e9e129 100644
--- a/sites/all/modules/unl/unl_migration.php
+++ b/sites/all/modules/unl/unl_migration.php
@@ -78,6 +78,7 @@ class Unl_Migration_Tool
     private $_content             = array();
     private $_createdContent      = array();
     private $_lastModifications   = array();
+    private $_redirects           = array();
     private $_hrefTransform       = array();
     private $_hrefTransformFiles  = array();
     private $_menu                = array();
@@ -150,6 +151,9 @@ class Unl_Migration_Tool
                     unset($transforms['']);
                 }
                 foreach ($transforms as $oldPath => &$newPath) {
+                    if (array_key_exists($newPath, $this->_redirects)) {
+                        $newPath = $this->_redirects[$newPath];
+                    }
                     if (array_key_exists($newPath, $this->_hrefTransformFiles)) {
                         $newPath = $this->_hrefTransformFiles[$newPath];
                     }
@@ -639,6 +643,13 @@ class Unl_Migration_Tool
             $location = $headers['Location'];
             $path = substr($location, strlen($this->_baseUrl));
             $this->_addSitePath($path);
+            
+            if (substr($location, 0, strlen($this->_baseUrl)) == $this->_baseUrl) {
+                $this->_redirects[substr($url, strlen($this->_baseUrl))] = substr($location, strlen($this->_baseUrl));
+            } else {
+                $this->_redirects[substr($url, strlen($this->_baseUrl))] = $location;
+            }
+            
             $this->_log('Found a redirect from ' . $url . ' to ' . $location . '. Some links may need to be updated.');
             return FALSE;
         } else if ($meta['http_code'] != 200) {
-- 
GitLab