Problem/Motivation
Currently, the module page shows SQL queries to execute for unbanning.
Having dedicated
ban:unban:all
ban:unban:ip
commands would be better DX and should be self-explaining.
As flood_control already has this for its own tables, this should be a simple novice task to do the same for the ban tables:
https://git.drupalcode.org/project/flood_control/-/blob/3.0.x/src/Comman...
Steps to reproduce
Try unbanning an IP using drush - currently needs custom SQL commands.
Proposed resolution
Implement
ban:ban:{IP}
ban:unban:{IP}
ban:flush
drush commands like flood_control does.
Remaining tasks
Implement
Test
Release
User interface changes
None
API changes
None
Data model changes
None
Comments
Comment #2
anybodyComment #3
danrodI'd like to work on this one if you don't mind.
Comment #4
danrodComment #5
anybody@danrod Yes of course, that would be great! Any updates yet? :)
Comment #6
danrodHi @anybody , It's ongoing, I've had some health issues lately, hopefully I'll continue working with this today.
Comment #7
lrwebks commentedComment #8
lrwebks commented@danrod, definitely hope you get well soon! @anybody assigned this task to me in the meantime, hope you don't mind!
Comment #10
danrodHi @lrwebks thanks, yes, it is ok, hopefully I'll be able to check some Drupal issues this weekend.
Comment #11
ysamoylenko commentedThis patch implements the requested Drush unban commands plus additional commands for a complete Drush interface to the Ban module.
What's Included:
- ban:unban:ip - Unban a specific IP address (as requested)
- ban:unban:all - Unban all IP addresses (as requested)
- ban:add - Ban an IP address (bonus feature)
- ban:list - List all banned IPs (bonus feature)
All commands include:
✓ Modern Drush 13 patterns using PHP 8 attributes
✓ Proper dependency injection with AutowireTrait
✓ Multiple aliases for user convenience
✓ IP address validation
✓ Comprehensive error handling
✓ Clear user feedback messages
Testing:
✓ Complete functional test suite (6 test methods)
✓ All tests cover success and error cases
✓ Tests verify command aliases work correctly
✓ Edge cases including IPv6 support
Code Quality:
✓ Zero PHPCS violations (Drupal & DrupalPractice standards)
✓ Zero syntax errors
✓ Full type declarations
✓ Complete PHPDoc documentation
✓ 100% backwards compatible
The patch applies cleanly to the 1.0.x branch and is ready for review.
Comment #12
anybody@ysamoylenko please use MRs not patches. It's 2025 ;D
Comment #14
anybodyI guess the broken tests are from #3540366: Implement phpstan level 8 and unrelated. So this should be reviewed.
Comment #15
grevil commentedCommented.
Comment #16
ysamoylenko commentedComment #17
grevil commentedThanks, @ysamoylenko! LGTM! 👍
Comment #18
anybody@mstrelan any chance to merge this and release next? This would be *REALLY* helpful!
Comment #19
mstrelan commentedHave made you a maintainer. Let's open a 1.1.x branch for this and new features, and if we ever do a big restructure / merge with advban etc we can open 2.x
Comment #20
grevil commentedI created a new 1.1.x Branch, but I don't have the permissions to add the Branch as a dev release, hence I can't target 1.1.x here.
Comment #21
grevil commentedAnd one more thing, maybe we should slightly adjust the command names. It feels quite intuitive to have
ban:unban:ip xxxto unban, butban:add xxxto ban an ip.IMO we should either have:
or:
Also ban:ban:ip and ban:unban:ip could also support multiple ips?
What do you think @anybody.
Comment #22
mstrelan commentedComment #23
anybody@grevil consolidating the commands is a good idea. Let's do the following:
Comment #24
anybodyComment #25
grevil commentedSGTM!
Comment #26
anybodyComment #27
grevil commentedAll done! Please review!
Comment #28
grevil commentedI'd keep the aliases. Anything else?
Comment #29
grevil commentedAh tests fail.
Comment #30
grevil commentedI went back and forth, whether to keep or remove the tests. They are ok, but only test the underlying BanManager. Only 3 tests test the commands but only the list command in three ways.
We already have middleware tests, which indirectly test the BanManager. We can open a separate issue for further tests, but I don't want to merge them here.
Comment #31
anybodyNice @grevil all good, thanks! Merged!
Comment #32
anybodyComment #35
mstrelan commentedSimilar comment here regarding BC. Adding to
BanIpManagerInterfacemeans all implementations need to add the new method. It is probably unlikely that people are implementing this without also extendingBanIpManager, so it's probably ok, but can't say for sure. In saying that, I'm not sure exactly how to achieve this in a BC way.Comment #36
grevil commentedI'll fix the introduced breaking changes in #3575604: Remove introduced breaking changes in 1.1.x.
Comment #37
anybody