Skip to content
Snippets Groups Projects
Commit 30feb23d authored by Stephen Mustgrave's avatar Stephen Mustgrave
Browse files

Merge branch '3391850-drush-command-to' into '5.0.x'

Issue #3391850 by paul_leclerc, anybody: Drush command to disable restrict_ip

See merge request !28
parents 16e00c4b 2d64a013
No related branches found
No related tags found
No related merge requests found
Pipeline #378035 passed with warnings
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
* About * About
* Installation * Installation
* Configuration * Configuration
* Drush commands
* Modules that expand on restrict IP
* Questions and Answers * Questions and Answers
* Support * Support
...@@ -34,6 +36,12 @@ $config['restrict_ip.settings']['ip_whitelist'] = [ ...@@ -34,6 +36,12 @@ $config['restrict_ip.settings']['ip_whitelist'] = [
'111.111.111.2', '111.111.111.2',
]; ];
### Drush commands
If you don't have access/permissions on settings files, you can also use a restrict_ip drush command :
`drush ripd 1/0`
### Modules that expand on restrict IP ### Modules that expand on restrict IP
1. [IP-based Determination of a Visitor's Country](https://www.drupal.org/project/ip2country) 1. [IP-based Determination of a Visitor's Country](https://www.drupal.org/project/ip2country)
......
...@@ -4,6 +4,11 @@ parameters: ...@@ -4,6 +4,11 @@ parameters:
restrict_ip.event_subscriber.class: Drupal\restrict_ip\EventSubscriber\RestrictIpEventSubscriber restrict_ip.event_subscriber.class: Drupal\restrict_ip\EventSubscriber\RestrictIpEventSubscriber
services: services:
restrict_ip.commands:
class: \Drupal\restrict_ip\Drush\Commands\RestrictIpCommands
tags:
- { name: drush.command }
restrict_ip.mapper: restrict_ip.mapper:
class: Drupal\restrict_ip\Mapper\RestrictIpMapper class: Drupal\restrict_ip\Mapper\RestrictIpMapper
arguments: arguments:
......
<?php
namespace Drupal\restrict_ip\Drush\Commands;
use Drush\Commands\DrushCommands;
final class RestrictIpCommands extends DrushCommands {
/**
* Disable/Enable restrict_ip.
*
* @param string $disable
* 1/0
*
* @command restrict_ip:disable
* @aliases ripd
* @usage restrict_ip:disable off
*/
public function ipRestrictDisable(string $disable): void {
$configF = \Drupal::configFactory();
$edit = $configF->getEditable('restrict_ip.settings');
$edit->set('enable', (boolean) $disable);
$edit->save();
$disableString = $disable ? 'enable' : 'disable';
$this->logger()->success(t('restrict_ip ' . $disableString));
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment