#!/usr/bin/env php '); exit(1); } $username = $argv[1]; $email = $argv[2]; $realname = $argv[3]; $admin = $argv[4]; $admin = id(new PhabricatorUser())->loadOneWhere( 'username = %s', $argv[4]); if (!$admin) { throw new Exception( pht( 'Admin user must be the username of a valid Phabricator account, used '. 'to send the new user a welcome email.')); } $existing_user = id(new PhabricatorUser())->loadOneWhere( 'username = %s', $username); if ($existing_user) { throw new Exception( pht( "There is already a user with the username '%s'!", $username)); } $existing_email = id(new PhabricatorUserEmail())->loadOneWhere( 'address = %s', $email); if ($existing_email) { throw new Exception( pht( "There is already a user with the email '%s'!", $email)); } $user = new PhabricatorUser(); $user->setUsername($username); $user->setRealname($realname); $user->setIsApproved(1); $email_object = id(new PhabricatorUserEmail()) ->setAddress($email) ->setIsVerified(1); id(new PhabricatorUserEditor()) ->setActor($admin) ->createNewUser($user, $email_object); $welcome_engine = id(new PhabricatorPeopleWelcomeMailEngine()) ->setSender($admin) ->setRecipient($user); if ($welcome_engine->canSendMail()) { $welcome_engine->sendMail(); } echo pht( "Created user '%s' (realname='%s', email='%s').\n", $username, $realname, $email);