From 047afc99c443bfbdcb1eec18d74db2174420c69b Mon Sep 17 00:00:00 2001 From: Tim Steiner <tsteiner2@unl.edu> Date: Fri, 9 Nov 2012 11:27:03 -0600 Subject: [PATCH] [gh-471] Also handle migrated paths with query strings for HTML documents. --- sites/all/modules/unl/unl_migration.php | 43 ++++++++++++++----------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/sites/all/modules/unl/unl_migration.php b/sites/all/modules/unl/unl_migration.php index 9781cbfc8..3566bbc7e 100644 --- a/sites/all/modules/unl/unl_migration.php +++ b/sites/all/modules/unl/unl_migration.php @@ -655,36 +655,38 @@ class Unl_Migration_Tool if (isset($data['lastModified'])) { $this->_lastModifications[$path] = $data['lastModified']; } - if (strpos($data['contentType'], 'html') === FALSE) { - if (!$data['contentType']) { - $this->_log('The file type at ' . $fullPath . ' was not specified. Ignoring.', WATCHDOG_ERROR); - return; - } - - $filePath = $path; - $pathParts = parse_url($path); - // If the path contains a query, we'll have to change it. - if (array_key_exists('query', $pathParts)) { + + $cleanPath = $path; + $pathParts = parse_url($path); + // If the path contains a query, we'll have to change it. + if (array_key_exists('query', $pathParts)) { $matches = array(); if (array_key_exists('Content-Disposition', $data['headers']) && - preg_match('/filename="(.*)"/', $data['headers']['Content-Disposition'], $matches)) { - $filePath = $pathParts['path'] . '/' . $matches[1]; + preg_match('/filename="(.*)"/', $data['headers']['Content-Disposition'], $matches)) { + $cleanPath = $pathParts['path'] . '/' . $matches[1]; } else { - $filePath = $pathParts['path'] . '/' . $pathParts['query']; + $cleanPath = $pathParts['path'] . '/' . $pathParts['query']; } + $cleanPath = strtr($cleanPath, array('%2f' => '/', '%2F' => '/')); + } + + if (strpos($data['contentType'], 'html') === FALSE) { + if (!$data['contentType']) { + $this->_log('The file type at ' . $fullPath . ' was not specified. Ignoring.', WATCHDOG_ERROR); + return; } - @drupal_mkdir('public://' . urldecode(dirname($filePath)), NULL, TRUE); + @drupal_mkdir('public://' . urldecode(dirname($cleanPath)), NULL, TRUE); if (!mb_check_encoding($path, 'UTF-8')) { $path = iconv('ISO-8859-1', 'UTF-8', $path); } try { - $file = file_save_data($data['content'], 'public://' . urldecode($filePath), FILE_EXISTS_REPLACE); + $file = file_save_data($data['content'], 'public://' . urldecode($cleanPath), FILE_EXISTS_REPLACE); } catch (Exception $e) { $this->_log('Could not migrate file "' . $path . '"! File name too long?', WATCHDOG_ERROR); } - $this->_hrefTransformFiles[$path] = $this->_makeRelativeUrl(file_create_url('public://' . $filePath)); + $this->_hrefTransformFiles[$path] = $this->_makeRelativeUrl(file_create_url('public://' . $cleanPath)); return; } $html = $data['content']; @@ -793,8 +795,8 @@ class Unl_Migration_Tool $this->_processLinks($linkNode->getAttribute('src'), $path, $page_base); } - $this->_content[$path] = $maincontentarea; - $this->_pageTitles[$path] = $pageTitle; + $this->_content[$cleanPath] = $maincontentarea; + $this->_pageTitles[$cleanPath] = $pageTitle; // Scan the page for the parent breadcrumb $breadcrumbs = $dom->getElementById('breadcrumbs'); @@ -812,9 +814,12 @@ class Unl_Migration_Tool if ($pageParentLink == $path) { $pageParentLink = ''; } - $this->_pageParentLinks[$path] = $pageParentLink; + $this->_pageParentLinks[$cleanPath] = $pageParentLink; } } + if ($cleanPath != $path) { + $this->_hrefTransformFiles[$path] = $cleanPath; + } } private function _processLinks($originalHref, $path, $page_base = NULL, $tag = NULL) { -- GitLab