diff --git a/src/Drupal/Driver/DrushDriver.php b/src/Drupal/Driver/DrushDriver.php index 12e5b516..09930741 100644 --- a/src/Drupal/Driver/DrushDriver.php +++ b/src/Drupal/Driver/DrushDriver.php @@ -163,7 +163,10 @@ 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); @@ -171,6 +174,19 @@ public function userCreate(\stdClass $user) { } } + /** + * 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} */ @@ -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); }