Needs review
Project:
Redirect
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
14 Mar 2019 at 21:57 UTC
Updated:
13 Sep 2024 at 05:29 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
charginghawk commentedComment #3
charginghawk commentedThe above doesn't actually work in D8, nor does it apply to 8.x-1.3. Here's a patch does both.
Comment #4
bobbysaul commentedI believe the default code should be 301 since that is what it is on the UI form page. Also, code 0 will throw an error.
Comment #5
bobbysaul commentedThe patch in #3 works except the drush log fails because the URL object needs its toString() function to be called to print. Attached is the updated patch, along with the changes to the default code from my above comment. It should be noted that this patch is for drush 8.
Comment #6
bobbysaul commentedI missed the toString call in the check for loops.
I also made the command available for drush 9.
Comment #7
charginghawk commentedWhen I created this issue, I used a migration job before I got a chance to try it out. Ran into this use case again, tried the patch out and it works gangbusters. Thanks @bobbysaul!
Comment #8
bobbysaul commentedI am re-uploading my patch since the new files were not added with my last upload because I forgot
git diffdoes not include untracked files.This patch should include the new files for drush 9 support for this feature.
Comment #9
berdiris the php requirement really necessary? with 8.8, drupal core requires PHP 7 anyway.
afaik it makes sense to specify ^9 || ^10 now.
Per #2920454: Setting 300 Code as Default Redirect causes Fatal error (300 not supported by symfony http-foundation), this should be 301-307.
Maybe just "Redirect Drush commands". The current documentation seems copied from an example.
nitpick: empty line above /**
I think there are replacements available for these functions in D9+, $this->logger() and $this->io()->error() I believe.
Comment #10
lolcode commentedThe patch was no longer applying for me on Drupal 8.8 and redirect 1.6.
I have updated it and covered almost everything in #9 except the use of $this->io() which gave me an error. $this->logger() was fine.
Other changes:
It looked to me like there was some confusion over the name between the class and the hook_drush_commands?
One was using "redirect-create" and the other was "create-redirect".
I used the value from the class. If the other way is preferred I would be happy to change.
I called the class in the redirect.drush.inc so that the code was all in one place.
Comment #11
lolcode commentedPlease ignore #10. I forgot to add the new files to the git diff. The patch did not contain the class.
Comment #12
lolcode commentedSorry, please ignore #11. This time without extra git diff output that caused the fail.
Comment #13
berdirseems unnecessary to specify the defaults in the constructor when we need to initialize it in the function again anyway?
Comment #14
lolcode commentedWhat is the issue with the composer.json changes?
I allowed my IDE to update the indenting from 4 to 2. I checked that 4 spaces is correct for Drupal projects.
Looking at the patch it looks like it has the intended effect?
Comment #15
berdirIgnore that, I just ad that accidentally still selected, the comment is just about the constructor. Not very fond of making unrelated changes like that in patches, but not so important.
Comment #16
lolcode commentedI have updated the constructor to remove the default spec.
I also removed two unused imports now that the hook uses the class.
Comment #17
fjgarlin commentedWhen adding a redirect that is already there.
Error: Call to undefined function Drupal\redirect\Commands\drush_set_error() in /var/www/html/web/modules/contrib/redirect/src/Commands/RedirectCommands.phpTested with drush version : 10.6.2
Comment #18
ushma commentedDrush 10 does not support drush_set_error() function. I have replaced it with throw new \Exception()
Comment #19
ushma commentedComment #20
fjgarlin commentedRe-roll patch as it didn't apply anymore.
Comment #21
Oussama OUDRHIRI commentedUsing this patch "drush_create_redirect-3040413-20.patch"
this command : drush redirect-create '/test' 'test-redirected' --code=301
=>returns this error message : "The "--code" option does not accept a value."
the same command with no "--code" option: drush redirect-create '/test/1' 'test-redirected/1'
=>set's the status_code to "NULL" in the database and when editing from the Back Office the changes are not persisted
Issue: the options are not taken into consideration.
Fix => I have updated the constructor to add the default spec.
Note: also fixed some SonarLint warnings
Comment #22
joey-santiago commentedThe patch #21 seems to work fine for me. Also the --code parameter seems to work fine.
Comment #23
joey-santiago commentedComment #24
Oussama OUDRHIRI commentedWhen creating redirects in large quantities, we frequently encounter situations where certain source paths are already being redirected. In Patch #21, an exception is raised specifically for this scenario. However, when the redirect is successfully saved, no information is displayed in the terminal.
In Patch #24:
Comment #25
berdirThis needs to be a merge request now and .drush.inc shouldn't be touched, no need to add that anymore.
Comment #28
malcomio commentedhttps://git.drupalcode.org/project/redirect/-/merge_requests/117 seems to be working - please review