Comments

CKIDOW created an issue. See original summary.

ckidow’s picture

Here is my patch file to create a system user.

This patch is only for drush >= 9.

drush system_user:create

or

drush system_user:create my@email.com

msankhala’s picture

  1. +++ b/composer.json
    @@ -0,0 +1,15 @@
    \ No newline at end of file
    

    Missing newline at end of file.

  2. +++ b/src/Commands/SystemUserCommands.php
    @@ -0,0 +1,112 @@
    +    $this->setSystemUserService($system_user);
    ...
    +    $this->service = $system_user;
    

    You can avoid this setter method by doing $this->service = $system_user; inside constructor directly.

    Any advantage of doing setter injection here?

msankhala’s picture

Status: Active » Needs review
ckidow’s picture

No advantage from my point of view. Let's keep it simple and straight forward in the __construct as you suggested.

ckidow’s picture

There is a typo in the code doc for the "create" method:

"Creates a system users." -> Should be "Creates a system user."

ckidow’s picture

Patch update

msankhala’s picture

Status: Needs review » Needs work

The patch applies cleanly but I am getting an error after applying this patch. Can you please provide interdiff as well? See https://www.drupal.org/documentation/git/interdiff

Runnding drush command gives this error. My drush version 9.3.0

TypeError: Argument 1 passed to Drupal\system_user\Commands\SystemUserCommands::__construct() must be an instance of Drupal\system_user\Service\SystemUser, instance of Drupal\system_user\Service\SystemUserManager given, called in core/lib/Drupal/Component/DependencyInjection/Container.php on line 262 in Drupal\system_user\Commands\SystemUserCommands->__construct() (line 27 of modules/contrib/system_user/src/Commands/SystemUserCommands.php).
lomasr’s picture

Applied the patch. It worked cleanly for me but after enabling the module. I tried the newly created drush cmd but got this error
The drush command 'system_user:create' could not be found. Run `drush cache-clear drush` to clear the commandfile cache if you have [error]
installed new extensions.

ckidow’s picture

@lomasr As I mentioned above: This patch is only for drush >= 9 and module version 8.x.

ckidow’s picture

@msankhala this error is because I created the patch against the 8.x-1.0 version ... not against the 8.x-dev version

I did this because I don't want to have the .install file including creating one new system_user on module install... that's what I don't want.

ckidow’s picture

Here is the latest patch against current dev where the service class name was renamed.

ckidow’s picture

This should now work.

ckidow’s picture

Status: Needs work » Needs review
ckidow’s picture

Version: 8.x-1.0 » 8.x-1.x-dev
ckidow’s picture

opdavies’s picture

andrewtur’s picture

Rerolled against dev. Added to drush commands drush system_user:makeAdmin and drush system_user:unmakeAdmin

andrewtur’s picture

Removed php requirement from compose.json