From 16405a802e7b2c50407f374369a73a4c9e58081b Mon Sep 17 00:00:00 2001 From: Tim Steiner <tsteiner2@unl.edu> Date: Mon, 4 Oct 2010 17:21:28 +0000 Subject: [PATCH] Migration Tool now migrates Related Links, Contacting Us, and Footers. git-svn-id: file:///tmp/wdn_thm_drupal/branches/drupal-7.x@220 20a16fea-79d4-4915-8869-1ea9d5ebf173 --- sites/all/modules/unl/unl_migration.php | 71 +++++++++++++++++++++---- 1 file changed, 61 insertions(+), 10 deletions(-) diff --git a/sites/all/modules/unl/unl_migration.php b/sites/all/modules/unl/unl_migration.php index 9b42bd24..768d90d6 100644 --- a/sites/all/modules/unl/unl_migration.php +++ b/sites/all/modules/unl/unl_migration.php @@ -85,6 +85,7 @@ class Unl_Migration_Tool private $_nodeMap = array(); private $_pageTitles = array(); private $_log = array(); + private $_blocks = array(); private function __construct($baseUrl, $frontierPath, $frontierUser, $frontierPass) { @@ -113,6 +114,7 @@ class Unl_Migration_Tool // Parse the menu $this->_processMenu(); + $this->_process_blocks(); // Process all of the pages on the site do { @@ -151,6 +153,7 @@ class Unl_Migration_Tool } $this->_createMenu(); + $this->_create_blocks(); } private function _addSitePath($path) @@ -310,15 +313,52 @@ class Unl_Migration_Tool } } + private function _process_blocks() { + $content = $this->_getUrl($this->_baseUrl); + $html = $content['content']; + + $this->_blocks['related_links'] = $this->_get_instance_editable_content($html, 'leftcollinks'); + $this->_blocks['contact_info'] = $this->_get_instance_editable_content($html, 'contactinfo'); + $this->_blocks['optional_footer'] = $this->_get_instance_editable_content($html, 'optionalfooter'); + $this->_blocks['footer_content'] = $this->_get_instance_editable_content($html, 'footercontent'); + + $this->_blocks['related_links'] = trim(strtr($this->_blocks['related_links'], array('<h3>Related Links</h3>' => ''))); + $this->_blocks['contact_info'] = trim(strtr($this->_blocks['contact_info'], array('<h3>Contacting Us</h3>' => ''))); + } + + private function _create_blocks() { + db_update('block_custom') + ->fields(array( + 'body' => $this->_blocks['contact_info'], + )) + ->condition('bid', 101) + ->execute(); + db_update('block_custom') + ->fields(array( + 'body' => $this->_blocks['related_links'], + )) + ->condition('bid', 102) + ->execute(); + db_update('block_custom') + ->fields(array( + 'body' => $this->_blocks['optional_footer'], + )) + ->condition('bid', 103) + ->execute(); + db_update('block_custom') + ->fields(array( + 'body' => $this->_blocks['footer_content'], + )) + ->condition('bid', 104) + ->execute(); + } + private function _processPage($path) { $this->_addProcessedPage($path); $fullPath = $this->_baseUrl . $path; $url = $this->_baseUrl . $path; - $startToken = '<!-- InstanceBeginEditable name="maincontentarea" -->'; - $pageTitleStartToken = '<!-- InstanceBeginEditable name="pagetitle" -->'; - $endToken = '<!-- InstanceEndEditable -->'; $data = $this->_getUrl($url); if (!$data['content']) { @@ -345,16 +385,11 @@ class Unl_Migration_Tool $html = iconv($charset, 'UTF-8', $html); } - $contentStart = strpos($html, $startToken); - $contentEnd = strpos($html, $endToken, $contentStart); - $maincontentarea = substr($html, - $contentStart + strlen($startToken), - $contentEnd - $contentStart - strlen($startToken)); - if (!$maincontentarea || $contentStart === FALSE || $contentEnd === FALSE) { + $maincontentarea = $this->_get_instance_editable_content($html, 'maincontentarea'); + if (!$maincontentarea) { $this->_log('The file at ' . $fullPath . ' has no valid maincontentarea. Ignoring.'); return; } - $maincontentarea = trim($maincontentarea); $dom = new DOMDocument(); $dom->loadHTML($html); @@ -661,5 +696,21 @@ class Unl_Migration_Tool $this->_log[] = $message; drupal_set_message($message, 'status'); } + + private function _get_instance_editable_content($html, $name) { + $start_token = '<!-- InstanceBeginEditable name="' . $name . '" -->'; + $end_token = '<!-- InstanceEndEditable -->'; + + $content_start = strpos($html, $start_token); + $content_end = strpos($html, $end_token, $content_start); + $content = substr($html, + $content_start + strlen($start_token), + $content_end - $content_start - strlen($start_token)); + $content = trim($content); + if (!$content || $content_start === FALSE || $content_end === FALSE) { + return FALSE; + } + return $content; + } } -- GitLab