Skip to content

Commit

Permalink
Merge pull request jhedstrom#184 from xaqrox/drush-uid
Browse files Browse the repository at this point in the history
Extract and store uid in DrushDriver::userCreate()
  • Loading branch information
jhedstrom authored Apr 18, 2018
2 parents acf9c1b + 7117894 commit 2febeef
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/Drupal/Driver/DrushDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,30 @@ public function userCreate(\stdClass $user) {
'password' => $user->pass,
'mail' => $user->mail,
);
$this->drush('user-create', $arguments, $options);
$result = $this->drush('user-create', $arguments, $options);
if ($uid = $this->parseUserId($result)) {
$user->uid = $uid;
}
if (isset($user->roles) && is_array($user->roles)) {
foreach ($user->roles as $role) {
$this->userAddRole($user, $role);
}
}
}

/**
* Parse user id from drush user-information output.
*/
protected function parseUserId($info) {
// Find the row containing "User ID : xxx".
preg_match('/User ID\s+:\s+\d+/', $info, $matches);
if (!empty($matches)) {
// Extract the ID from the row.
list(, $uid) = explode(':', $matches[0]);
return (int) $uid;
}
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -246,6 +262,13 @@ protected function decodeJsonObject($output) {
* {@inheritdoc}
*/
public function createNode($node) {
// Look up author by name.
if (isset($node->author)) {
$user_info = $this->drush('user-information', array(sprintf('"%s"', $node->author)));
if ($uid = $this->parseUserId($user_info)) {
$node->uid = $uid;
}
}
$result = $this->drush('behat', array('create-node', escapeshellarg(json_encode($node))), array());
return $this->decodeJsonObject($result);
}
Expand Down

0 comments on commit 2febeef

Please sign in to comment.