From 619c2b3ea811824f2fb6e6a48362e3c91c299fbd Mon Sep 17 00:00:00 2001 From: Yaroslav Tarasov Date: Tue, 3 Feb 2026 17:27:20 +0200 Subject: [PATCH] BUGFIX EXTPLESK-8950 Fix case when getAll returns 1 database instead of 0 --- src/Api/Operator/Database.php | 6 +++++- tests/DatabaseTest.php | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Api/Operator/Database.php b/src/Api/Operator/Database.php index 817adec5..ddc0e6ed 100644 --- a/src/Api/Operator/Database.php +++ b/src/Api/Operator/Database.php @@ -79,7 +79,11 @@ public function getAll(?string $field, $value): array $items = []; foreach ((array) $response->xpath('//result') as $xmlResult) { if ($xmlResult) { - $items[] = new Struct\Info($xmlResult); + $info = new Struct\Info($xmlResult); + $vars = is_object($info) ? get_object_vars($info) : []; + if (!empty($vars['id']) && !empty($vars['name']) && !empty($vars['type'])) { + $items[] = $info; + } } } diff --git a/tests/DatabaseTest.php b/tests/DatabaseTest.php index 1b2b1c5f..e7c65c68 100644 --- a/tests/DatabaseTest.php +++ b/tests/DatabaseTest.php @@ -225,4 +225,15 @@ private function createUser(array $params): \PleskX\Api\Struct\Database\UserInfo return $user; } + + public function testGetAllForWebspaceWithNoDatabases() + { + $webspace = static::createWebspace(); + $databases = static::$client->database()->getAll('webspace-id', $webspace->id); + + $this->assertIsArray($databases); + $this->assertEmpty($databases); + + static::$client->webspace()->delete('id', $webspace->id); + } }