Skip to content

Commit c298f6f

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

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

src/Api/Operator/Database.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,15 @@ public function getAll(?string $field, $value): array
7878
$response = $this->getBy('get-db', $field, $value);
7979
$items = [];
8080
foreach ((array) $response->xpath('//result') as $xmlResult) {
81-
if ($xmlResult) {
82-
$items[] = new Struct\Info($xmlResult);
81+
if (!$xmlResult) {
82+
continue;
83+
}
84+
85+
if (!isset($xmlResult->id) || (int) $xmlResult->id <= 0) {
86+
continue;
8387
}
88+
89+
$items[] = new Struct\Info($xmlResult);
8490
}
8591

8692
return $items;

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)