Skip to content

Commit 9fd2eda

Browse files
author
Vladislav Baranovskiy
committed
Add set-db-user method to database object
1 parent 17409be commit 9fd2eda

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

src/PleskX/Api/Operator/Database.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Database extends \PleskX\Api\Operator
1212
*/
1313
public function create($properties)
1414
{
15-
return new Struct\Info($this->_create('add-db', $properties));
15+
return new Struct\Info($this->_process('add-db', $properties));
1616
}
1717

1818
/**
@@ -21,26 +21,40 @@ public function create($properties)
2121
*/
2222
public function createUser($properties)
2323
{
24-
return new Struct\UserInfo($this->_create('add-db-user', $properties));
24+
return new Struct\UserInfo($this->_process('add-db-user', $properties));
2525
}
2626

2727
/**
2828
* @param $command
2929
* @param array $properties
3030
* @return \PleskX\Api\XmlResponse
3131
*/
32-
private function _create($command, array $properties)
32+
private function _process($command, array $properties)
3333
{
3434
$packet = $this->_client->getPacket();
3535
$info = $packet->addChild($this->_wrapperTag)->addChild($command);
3636

3737
foreach ($properties as $name => $value) {
38+
if (false !== strpos($value, '&')) {
39+
$info->$name = $value;
40+
continue;
41+
}
3842
$info->addChild($name, $value);
3943
}
4044

4145
return $this->_client->request($packet);
4246
}
4347

48+
/**
49+
* @param array $properties
50+
* @return bool
51+
*/
52+
public function updateUser(array $properties)
53+
{
54+
$response = $this->_process('set-db-user', $properties);
55+
return 'ok' === (string)$response->status;
56+
}
57+
4458
/**
4559
* @param string $field
4660
* @param integer|string $value

tests/DatabaseTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,29 @@ public function testCreateUser()
4646
]);
4747
static::$_client->database()->deleteUser('id', $user->id);
4848
static::$_client->database()->delete('id', $database->id);
49+
}
4950

51+
public function testUpdateUser()
52+
{
53+
$database = $this->_createDatabase([
54+
'webspace-id' => static::$_webspace->id,
55+
'name' => 'test1',
56+
'type' => 'mysql',
57+
'db-server-id' => 1
58+
]);
59+
$user = $this->_createUser([
60+
'db-id' => $database->id,
61+
'login' => 'test_user1',
62+
'password' => 'setup1Q',
63+
]);
64+
$updatedUser = static::$_client->database()->updateUser([
65+
'id' => $user->id,
66+
'login' => 'test_user2',
67+
'password' => 'setup2Q'
68+
]);
69+
$this->assertEquals(true, $updatedUser);
70+
static::$_client->database()->deleteUser('id', $user->id);
71+
static::$_client->database()->delete('id', $database->id);
5072
}
5173

5274
public function testGetById()

0 commit comments

Comments
 (0)