Closed (outdated)
Project:
Redirect
Version:
7.x-1.0-beta3
Component:
Miscellaneous
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
14 Sep 2011 at 21:13 UTC
Updated:
20 May 2025 at 20:03 UTC
Jump to comment: Most recent
Comments
Comment #1
sanguis commentedComment #2
chrowe commentedI am also interested in this.
It looks like http://drupal.org/node/622700#mappingapi documents how to do this kind of thing.
There is also a similar module http://drupal.org/project/cck_redirection for D6 that is listed on http://drupal.org/node/856780
Comment #3
westie commentedManaged to get this working in own custom module for D7, however the cavet is that you have to run the import twice with the option to update the node. The reason for this is that I didnt know the nid to use when creating the Redirect as the node was not created yet. If anyone know a way round this I would be thankful :)
Also I think it would be a nice feature for the Redirect module to integrate with Feeds, if other people agree I can try get a patch going.
Comment #4
dubs commentedYes, it would be great if this was included in Feeds. Thanks for adding this really useful code.
Comment #5
dshields commentedany progress on importing redirects with feeds?
Comment #6
dddbbb commentedThis is a great idea. Feeds import of redirect info would be really handy. +1
Comment #7
osopolarThe problem with the code in #3 is, that its not working for new nodes, only for updates. But this could be easily done using hook_node_save() and hook_node_insert() to do the work.
I was currently doing this for D6 and path_redirect, but I guess its similar for D7 with the redirect module (instead of
hook_nodeapiusehook_node_insertandhook_node_update()). Instead ofpath_redirect_load_by_source()you may useredirect_load_by_hash(redirect_hash($redirect)).Code for Drupal 6:
Comment #8
pere orgaComment #9
RivkiTzipory commentedFeeds Node Import with Redirect
1
Install Redirect module
https://www.drupal.org/project/redirect
2
In the Article content Type add field to save the old_url
3
Map the old_url in the Importer
/admin/structure/feeds/article_import/mapping
4
Add hook_node_insert with code like this
function hook_node_insert($node) {
if($node->type == 'article' && isset($node->field_old_url_for_redirect))
{
// Use Database API to retrieve current redirect sources.
$query = db_select('redirect', 'r');
$query->fields('r', array('source'));
$redirect_sources = $query->execute()->fetchCol();
// The old path
$url = $node->field_old_url_for_redirect['und'][0]['value'];
// Check node id exists and there is no current redirect set for it
if (isset($node->nid) && (!in_array($url, $redirect_sources))){
$redirect = new stdClass();
module_invoke(
'redirect',
'object_prepare',
$redirect,
array(
'source' => $url,
'source_options' => array(),
'redirect' => 'node/' . $node->nid,
'redirect_options' => array(),
'language' => LANGUAGE_NONE,
)
);
module_invoke('redirect', 'save', $redirect);
}
}
}
Comment #10
zapo commentedJust tried out solution #9 and it works! Thanks @RivkiTzipory
Comment #11
aumcara commentedHello RivkiTzipory and all,
I am recently in need to crawl a bit deeper in Drupal and I would love to apply your method.
But therefore, I need to learn about the hook operations .... and I just don't know where to start!
Do you mind to let me know from where I could start cause I am seriously interested by applying your method.
To apply hook is there a special module to install or so, I am just a bit lost.
Sorry, if my post is not supposed to be made here.
Thanks.
Comment #12
wylbur commentedAnother solution is to use the Path Redirect Import module to import redirect paths.
Closing this as Outdated as Drupal 7 is EOL.