Skip to content
Permalink
Browse files

Allow unblocking a blocked user. (#4018)

* Allow unblocking a blocked user.

* Warning unblocked user message.
  • Loading branch information...
GuidoRobertone authored and enzolutions committed Apr 24, 2019
1 parent 7f914f7 commit 3f87907a85f5ccdbaf0b218353fa4735e4a684b7
Showing with 107 additions and 0 deletions.
  1. +5 −0 config/services/user.yml
  2. +102 −0 src/Command/User/UnblockCommand.php
@@ -34,3 +34,8 @@ services:
arguments: ['@database', '@entity_type.manager', '@date.formatter', '@console.drupal_api']
tags:
- { name: drupal.command }
console.user_unblock:
class: Drupal\Console\Command\User\UnblockCommand
arguments: ['@entity_type.manager']
tags:
- { name: drupal.command }
@@ -0,0 +1,102 @@
<?php
/**
* @file
* Contains \Drupal\Console\Command\User\UnblockCommand.
*/
namespace Drupal\Console\Command\User;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
class UnblockCommand extends UserBase
{
/**
* UnblockCommand constructor.
*
* @param EntityTypeManagerInterface $entityTypeManager
*/
public function __construct(
EntityTypeManagerInterface $entityTypeManager
) {
parent::__construct($entityTypeManager);
}
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('user:unblock')
->setDescription($this->trans('commands.user.unblock.description'))
->setHelp($this->trans('commands.user.unblock.help'))
->addArgument(
'user',
InputArgument::REQUIRED,
$this->trans('commands.user.unblock.options.user')
)
->setAliases(['uu']);
}
/**
* {@inheritdoc}
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
$this->getUserArgument();
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$user = $input->getArgument('user');
$userEntity = $this->getUserEntity($user);
if (!$userEntity) {
$this->getIo()->error(
sprintf(
$this->trans('commands.user.unblock.errors.invalid-user'),
$user
)
);
return 1;
}
if (!$userEntity->isBlocked()) {
$this->getIo()->warning(
sprintf(
$this->trans('commands.user.unblock.warnings.unblocked-user'),
$user
)
);
return 1;
}
try {
$userEntity->activate();
$userEntity->save();
$this->getIo()->success(
sprintf(
$this->trans('commands.user.unblock.messages.unblock-successful'),
$user
)
);
return 0;
} catch (\Exception $e) {
$this->getIo()->error($e->getMessage());
return 1;
}
}
}

0 comments on commit 3f87907

Please sign in to comment.
You can’t perform that action at this time.