-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What happen with --user option in Drush 9? #3396
Comments
Just remove |
@weitzman Hi, this is not fixed problem. For now I see only one solution - manual user login in drush command: |
Hi @hamrant , As I discovered later there is a new recommended approach now. If your Drush command requires some privileges you should use \Drupal\Core\Session\AccountSwitcher service. Docs here https://www.drupal.org/node/2377441 |
Hi @RoSk0, thanks for quick response. Ok, I will use AccountSwitcher instead |
@seth-shaw-unlv yes, you need to use it inside drush command. Example:
services:
my_demo.commands:
class: \Drupal\my_demo\Commands\DemoCommands
arguments: ['@account_switcher']
tags:
- { name: drush.command }
<?php
namespace Drupal\my_demo\Commands;
use Drupal\Core\Session\UserSession;
use Drush\Commands\DrushCommands;
use Drupal\Core\Session\AccountSwitcherInterface;
/**
* A Drush commandfile.
*
* In addition to this file, you need a drush.services.yml
* in root of your module, and a composer.json file that provides the name
* of the services file to use.
*
* See these files for an example of injecting Drupal services:
* - http://cgit.drupalcode.org/devel/tree/src/Commands/DevelCommands.php
* - http://cgit.drupalcode.org/devel/tree/drush.services.yml
*/
class DemoCommands extends DrushCommands {
/**
* The account switcher service.
*
* @var \Drupal\Core\Session\AccountSwitcherInterface
*/
protected $accountSwitcher;
/**
* SimplesitemapCommands constructor.
*
* @param \Drupal\Core\Session\AccountSwitcherInterface $account_switcher
* The account switching service.
*/
public function __construct(AccountSwitcherInterface $account_switcher) {
$this->accountSwitcher = $account_switcher;
}
/**
* Some demo drush command.
*
* @usage drush run-demo
* Run demo command.
*
* @command run:demo
* @aliases run-demo
*/
public function demo() {
// Switch to root user (--user option was removed from drush 9).
$this->accountSwitcher->switchTo(new UserSession(['uid' => 1]));
// Do here logic related to command.
// ...
// Switch account back.
$this->accountSwitcher->switchBack();
}
} |
Thanks @hamrant. |
A warning regarding using the described account switching as I've been bitten by it: The switched account is not presently inherited by subprocesses... so any contained |
If you really wanted to, you could use a |
@adam-vessey @greg-1-anderson |
It's possible to do the following within a batch subprocess:
|
Work for me. Thank you. |
Hi,
I was deploying new project today and faced with issue. Our deployment system has a step to put site in maintenance mode which look like this
drush -u 1 -l http://address -r /var/www/drupal/project/current -y sset system.maintenance_mode 1
for Drupal 8. When this step was executed instead of usual OK message I receivedI have spent some tome and come to point where I can see from docs that I need to Drush 9 with 8.4+ and Drush 8 for everything else. That is fine, but... Global
--user
option was removed by #2696 but how we should replace this behaviour with Drush 9? Any links to docs or blog posts about this is greatly appreciated.The text was updated successfully, but these errors were encountered: