Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Patch is forthcoming...
Comment | File | Size | Author |
---|---|---|---|
#23 | 1301594_drush_add_redirect-23.patch | 2.93 KB | jfhovinne |
Comments
Comment #1
acrollet CreditAttribution: acrollet commentedPatch attached - I see this command as being very handy for doing quick & dirty imports for many redirects. Ate my own dogfood and used it to add about 100 redirects that I had in a CSV file. Here's a script example:
Comment #2
AaronBaumanworks as advertised, very straightforward patch, and very helpful; thanks.
Comment #3
moskito CreditAttribution: moskito commentedVery useful. Patch still working. Should be committed.
Comment #4
mvci was just about to write this patch myself to import ~100 aliases. thanks, acrollet!
one tiny suggestion: make the default option 0, which will use whatever default redirection option is configured at admin/config/search/redirect/settings. trivial new patch attached.
Comment #5
AaronBauman#4 works as advertised, still
RTBC++
This is the oldest RTBC issue in the queue.
Can we get it in, or at least reviewed by a maintainer?
Comment #6
gregglesIn general I agree this is RTBC. I tested it out a bit and it worked to create redirects.
If I put on my super-picky-hat, here are things that could be improved:
1. The comment about redirect loops is not a sentence and not capitalized.
2. Several lines are longer than 80 characters
3. The error about redirect hash being in use doesn't have a comment (either both error conditions should have comments or neither should).
4. The $dest variable is an abbreviation that is not a word and it is not consistent with the module's code - throughout the module the "dest" is generally called a redirect
Comment #7
gregglesAttached patch addresses the nitpicking in #6. I actually kept the $dest variable (though renamed it to $destination) because otherwise there is a string variable $redirect and a newly created $redirect object clobbers it. I guess this is an example of procedural and OO code not mixing well.
Added docblock information for the function and used the optional $defaults second parameter to redirect_object_prepare instead of just overwriting the resulting object properties.
Comment #8
tannerjfco CreditAttribution: tannerjfco commentedPatch in #7 seems to break the "code" argument. Using the example command
drush add-redirect 'node/1' 'http://google.com' 302
Adds the redirect, but redirect code is always the Default (301) regardless of what code is entered in the drush command for me.
Patch in #4 works as expected with the example command.
Comment #9
gregglesPerhaps it should be using status_code as the arry key instead of redirect_object_prepare?
Comment #10
gregglesYep, that's how it's used in redirect.admin.inc
Comment #11
tannerjfco CreditAttribution: tannerjfco commented#10 works as expected for me!
Comment #12
Dave ReidShould use "return drush_set_error(...);" here.
Same here.
Then there's no need for this. Simpilfied!
Comment #13
acrosmanAn updated patch with the suggested improvements.
Comment #14
acrosmanComment #15
mvclooks good here, acrosman
Comment #16
ivan_pinatti CreditAttribution: ivan_pinatti at CI&T commentedHi,
I used the patch #13 last week for ~70 redirects and worked like a charm. Do you guys have any expectation date to commit it?
One thing that I think that could be very useful, add a -f flag, so it can overwrite a existent redirect with a new one.
Thanks all.
Regards,
Comment #17
ivan_pinatti CreditAttribution: ivan_pinatti commentedComment #18
joseph.olstadlooks promising, looking for a language parameter
Comment #19
joseph.olstadOk, here's a newer patch that supports the language parameter instead of just default "language_undefined"
language is needed especially for multilingual or bilingual sites when redirecting internal paths.
Comment #20
acrosmanI think a language code makes a lot of sense, but probably as an optional parameter at the end of the command. Seems likely that it's the least common use case compared to the other parameters.
Comment #21
mvcI agree that the language parameter should be optional, and that the simplest way to do that would be to put it last.
Adding a -f flag would be nice but shouldn't block this patch.
Comment #22
jfhovinne CreditAttribution: jfhovinne commentedUpdated patch with optional language and status code.
Comment #23
jfhovinne CreditAttribution: jfhovinne commentedHere is the previous patch with default language value fixed.
Comment #24
joseph.olstadNice work @jfhovinne ,
RTBC patch 23
Comment #25
pifagorComment #26
pifagorRTBC
Comment #27
alex_optimNice work. +1
Comment #28
pifagorComment #31
pifagor