Skip to content

Commit 62715e3

Browse files
ddesmetupddesmet
andauthored
Feature/update user (#369)
* added user update function * Updated README with new user update function Co-authored-by: Davie De Smet <[email protected]>
1 parent 67574e5 commit 62715e3

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ $iss = new IssueService(new ArrayConfiguration(
179179
- [Find Assignable Users](#find-assignable-users)
180180
- [Find Users by query](#find-users-by-query)
181181
- [Delete User](#delete-user)
182+
- [Update User](#update-user)
182183

183184
### Group
184185
- [Create Group](#create-group)
@@ -1903,6 +1904,42 @@ try {
19031904

19041905
```
19051906

1907+
#### update User
1908+
1909+
[See Jira API reference](https://docs.atlassian.com/software/jira/docs/api/REST/latest/#api/2/user-updateUser)
1910+
1911+
Updates user.
1912+
1913+
```php
1914+
<?php
1915+
require 'vendor/autoload.php';
1916+
1917+
use JiraRestApi\JiraException;
1918+
use JiraRestApi\User\UserService;
1919+
1920+
try {
1921+
$us = new UserService();
1922+
1923+
$paramArray = ['username' => '[email protected]'];
1924+
1925+
// create new user
1926+
$user = [
1927+
'name'=>'charli',
1928+
'password' => 'abracada',
1929+
'emailAddress' => '[email protected]',
1930+
'displayName' => 'Charli of Atlassian',
1931+
];
1932+
1933+
$updatedUser = $us->update($paramArray, $user)
1934+
1935+
var_dump($updatedUser);
1936+
1937+
} catch (JiraRestApi\JiraException $e) {
1938+
print("Error Occured! " . $e->getMessage());
1939+
}
1940+
1941+
```
1942+
19061943
#### Create Group
19071944

19081945
[See Jira API reference](https://docs.atlassian.com/software/jira/docs/api/REST/latest/#api/2/group-createGroup)

src/User/UserService.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,31 @@ public function getUsers($paramArray)
222222

223223
return $users;
224224
}
225+
226+
/**
227+
* Function to update an existing user.
228+
*
229+
* @param array $paramArray
230+
* @param User|array $user
231+
*
232+
* @throws \JiraRestApi\JiraException
233+
* @throws \JsonMapper_Exception
234+
*
235+
* @return User User class
236+
*/
237+
public function update($paramArray, $user)
238+
{
239+
$queryParam = '?'.http_build_query($paramArray);
240+
241+
$data = json_encode($user);
242+
243+
$this->log->info("Update User (".$queryParam.") =\n".$data);
244+
245+
$ret = $this->exec($this->uri.$queryParam, $data, 'PUT');
246+
247+
return $this->json_mapper->map(
248+
json_decode($ret),
249+
new User()
250+
);
251+
}
225252
}

0 commit comments

Comments
 (0)