Index: database/updates.inc =================================================================== RCS file: /cvs/drupal/drupal/database/updates.inc,v retrieving revision 1.211 diff -u -F^f -r1.211 updates.inc --- database/updates.inc 6 Mar 2006 14:43:11 -0000 1.211 +++ database/updates.inc 7 Mar 2006 04:41:35 -0000 @@ -1674,3 +1674,74 @@ function system_update_176() { $ret[] = update_sql('ALTER TABLE {filter_formats} ADD UNIQUE (name)'); return $ret; } + +/** + * Update relative paths in node and comment content if case clean_urls are + * enabled. + */ +function system_update_177() { + + if(variable_get('clean_url', 0) == 1) { + + function _update_177_url_fix($content) { + $urlpattern[] = "']+))'isx"; + $urlpattern[] = "']+))'isx"; + + foreach ($urlpattern as $pattern) { + $matches = ''; + preg_match_all($pattern, $content, $matches); + foreach($matches[2] as $url) { + if ($url != '' && !strstr($url, 'mailto:') && !strstr($url, '://') && !strstr($url, '../') && !strstr($url, './') && $url[0] != '/' && $url[0] != '#') { + $content = str_replace($url, base_path(). $url, $content); + } + } + } + + return $content; + } + + // Multi-part update + if (!isset($_SESSION['system_update_177_comment'])) { + $_SESSION['system_update_177_comment'] = 0; + $_SESSION['system_update_177_node'] = 0; + $_SESSION['system_update_177_comment_max'] = db_result(db_query('SELECT MAX(cid) FROM {comments}')); + $_SESSION['system_update_177_node_max'] = db_result(db_query('SELECT MAX(nid) FROM {node_revisions}')); + } + + $limit = 20; + $result = db_query_range("SELECT cid, comment FROM {comments} WHERE cid > %d", $_SESSION['system_update_177_comment'], 0, $limit); + while ($comment = db_fetch_object($result)) { + $_SESSION['system_update_177_comment'] = $comment->cid; + $comment->comment = _update_177_url_fix($comment->comment); + db_query("UPDATE {comments} SET comment = '%s' WHERE cid = %d", $comment->comment, $comment->cid); + } + + $result = db_query_range("SELECT nid, vid, teaser, body FROM {node_revisions} WHERE nid > %d", $_SESSION['system_update_177_node'], 0, $limit); + while ($node = db_fetch_object($result)) { + // Catch the infinite loop for node revisions. We ignore updating + // content past the 20th revision. + if ($_SESSION['system_update_177_node'] == $node->nid) { + $_SESSION['system_update_177_node']++; + } + else { + $_SESSION['system_update_177_node'] = $node->nid; + } + $node->teaser = _update_177_url_fix($node->teaser); + $node->body = _update_177_url_fix($node->body); + db_query('UPDATE {node_revisions} SET body = "%s", teaser = "%s" WHERE nid = %d AND vid = %d', $node->body, $node->teaser, $node->nid, $node->vid); + } + + if ($_SESSION['system_update_177_comment'] == $_SESSION['system_update_177_comment_max'] && + $_SESSION['system_update_177_node'] == $_SESSION['system_update_177_node_max']) { + unset($_SESSION['system_update_177_comment']); + unset($_SESSION['system_update_177_comment_max']); + unset($_SESSION['system_update_177_node']); + unset($_SESSION['system_update_177_node_max']); + return array(); + } + return array('#finished' => $_SESSION['system_update_177_comment'] / $_SESSION['system_update_177_comment_max'] + && $_SESSION['system_update_177_node'] / $_SESSION['system_update_177_node_max']); + } + + return array(); +}