Skip to content

Commit 619c2b3

Browse files
whytea91Yaroslav Tarasov
authored andcommitted
BUGFIX EXTPLESK-8950 Fix case when getAll returns 1 database instead of 0
1 parent a43949f commit 619c2b3

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

src/Api/Operator/Database.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ public function getAll(?string $field, $value): array
7979
$items = [];
8080
foreach ((array) $response->xpath('//result') as $xmlResult) {
8181
if ($xmlResult) {
82-
$items[] = new Struct\Info($xmlResult);
82+
$info = new Struct\Info($xmlResult);
83+
$vars = is_object($info) ? get_object_vars($info) : [];
84+
if (!empty($vars['id']) && !empty($vars['name']) && !empty($vars['type'])) {
85+
$items[] = $info;
86+
}
8387
}
8488
}
8589

tests/DatabaseTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,4 +225,15 @@ private function createUser(array $params): \PleskX\Api\Struct\Database\UserInfo
225225

226226
return $user;
227227
}
228+
229+
public function testGetAllForWebspaceWithNoDatabases()
230+
{
231+
$webspace = static::createWebspace();
232+
$databases = static::$client->database()->getAll('webspace-id', $webspace->id);
233+
234+
$this->assertIsArray($databases);
235+
$this->assertEmpty($databases);
236+
237+
static::$client->webspace()->delete('id', $webspace->id);
238+
}
228239
}

0 commit comments

Comments
 (0)