From f03f97935d766cd0eda195a981c5b9747726b17b Mon Sep 17 00:00:00 2001 From: Leonard Fischer Date: Tue, 17 Dec 2024 14:46:28 +0100 Subject: [PATCH 1/7] Fix 'request success' check for newer 'save' endpoints --- src/Request.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Request.php b/src/Request.php index 99b7af8..194dbe7 100644 --- a/src/Request.php +++ b/src/Request.php @@ -61,10 +61,11 @@ public function __construct(API $api) { * @throws RuntimeException on error */ protected function requireSuccessFor(array $result): int { - if (!array_key_exists('id', $result) || - !is_numeric($result['id']) || + if ((!array_key_exists('id', $result) && !array_key_exists('entry', $result)) || + (!is_numeric($result['id'] ?? 0) && !is_numeric($result['entry'] ?? 0)) || !array_key_exists('success', $result) || $result['success'] !== true) { + if (array_key_exists('message', $result)) { throw new RuntimeException(sprintf('Bad result: %s', $result['message'])); } else { @@ -72,7 +73,7 @@ protected function requireSuccessFor(array $result): int { } } - return (int) $result['id']; + return (int) ($result['id'] ?? $result['entry']); } /** From 2ecfde1e048401c6edef3ff1de7640977de11dcd Mon Sep 17 00:00:00 2001 From: Leonard Fischer Date: Tue, 17 Dec 2024 14:47:14 +0100 Subject: [PATCH 2/7] Update README with current data, prepare changelog for 1.0.1 --- CHANGELOG.md | 15 ++++++++++++++- README.md | 8 ++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53c5cda..bbf3203 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased][] +## [1.0.1][] – 2024-12-17 + +**Note:** For the next minor version (1.1.0) we plan to drop support for PHP `8.0`. + +### Fixed + +- `Request::requireSuccessFor()`: Fix misleading error response for (successfully) saving category data + +### Changed + +- Slightly updating the README to represent the current state of the client (PHP and i-doit compatibility) + ## [1.0.0][] – 2024-12-16 **Note:** Support for all PHP `7` versions has been dropped. PHP `8+` only, from now on :) @@ -233,7 +245,8 @@ Happy summer time ⛱️ Initial release -[Unreleased]: https://github.com/i-doit/api-client-php/compare/1.0.0...HEAD +[Unreleased]: https://github.com/i-doit/api-client-php/compare/1.0.1...HEAD +[1.0.1]: https://github.com/i-doit/api-client-php/compare/1.0.0...1.0.1 [1.0.0]: https://github.com/i-doit/api-client-php/compare/0.10...1.0.0 [0.10]: https://github.com/i-doit/api-client-php/compare/0.9...0.10 [0.9]: https://github.com/i-doit/api-client-php/compare/0.8...0.9 diff --git a/README.md b/README.md index ddec6db..ccd6692 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Easy-to-use, but feature-rich client library for i-doit's JSON-RPC API [![Latest stable version](https://img.shields.io/packagist/v/idoit/apiclient.svg)](https://packagist.org/packages/idoit/apiclient) -[![Minimum PHP version](https://img.shields.io/badge/php-%3E%3D%207.4-8892BF.svg)](https://php.net/) +[![Minimum PHP version](https://img.shields.io/badge/php-%3E%3D%208.0-8892BF.svg)](https://php.net/) [![Build status](https://github.com/i-doit/api-client-php/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/i-doit/api-client-php/actions) **Please note: This project is not an official product by synetics GmbH. synetics GmbH doesn't provide any commercial support.** @@ -39,9 +39,9 @@ What's new? Take a look at the [changelog](CHANGELOG.md). Meet these simple requirements before using the client: -- A running instance of i-doit pro/open, version `1.18.1` or higher (older versions may work but are not supported) -- i-doit API add-on, version `1.12.3` or higher (older versions may work but are not supported) -- PHP, version `8.0` or higher (`8.1` is recommended, `7.4` should work but is deprecated) +- A running instance of i-doit pro/open, version `30` or higher (older versions may work but are not supported) +- i-doit API add-on, version `2.0` or higher (older versions may work but are not supported) +- PHP, version `8.0` or higher (`8.2` is recommended) - PHP modules `curl`, `date`, `json`, `openssl` and `zlib` As a rule of thumb, always use the latest stable releases to benefit from new features, improvements and bug fixes. From 02476b7b32845f19520886509c56e4a97ca92472 Mon Sep 17 00:00:00 2001 From: Leonard Fischer Date: Tue, 17 Dec 2024 14:48:57 +0100 Subject: [PATCH 3/7] Exclude nightly/experimental PHP builds for now --- .github/workflows/main.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9ff0bbb..9fd908b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,9 +20,9 @@ jobs: - '8.2' - '8.3' experimental: [false] - include: - - php-versions: nightly - experimental: true + #include: + # - php-versions: nightly + # experimental: true steps: - name: Checkout repository uses: actions/checkout@v2 From 60092e636a705de03d3b2266e356567607fe85c0 Mon Sep 17 00:00:00 2001 From: Leonard Fischer Date: Tue, 17 Dec 2024 15:04:14 +0100 Subject: [PATCH 4/7] Slightly changing the changelog message --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bbf3203..bf1470e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed -- `Request::requireSuccessFor()`: Fix misleading error response for (successfully) saving category data +- `Request::requireSuccessFor()`: Fix misleading error response for (successfully) saving category data when using `CMDBCategory` ### Changed From 6fe9a39fba5e942dd94b67d71607606ca19c18c1 Mon Sep 17 00:00:00 2001 From: Leonard Fischer Date: Tue, 17 Dec 2024 15:58:37 +0100 Subject: [PATCH 5/7] Simplify 'success' check --- src/Request.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Request.php b/src/Request.php index 194dbe7..b96275f 100644 --- a/src/Request.php +++ b/src/Request.php @@ -61,11 +61,11 @@ public function __construct(API $api) { * @throws RuntimeException on error */ protected function requireSuccessFor(array $result): int { - if ((!array_key_exists('id', $result) && !array_key_exists('entry', $result)) || - (!is_numeric($result['id'] ?? 0) && !is_numeric($result['entry'] ?? 0)) || - !array_key_exists('success', $result) || - $result['success'] !== true) { + $idExists = array_key_exists('id', $result) || array_key_exists('entry', $result); + $idIsNumeric = is_numeric($result['id'] ?? 0) || is_numeric($result['entry'] ?? 0); + $isSuccess = array_key_exists('success', $result) && $result['success'] === true; + if (!$idExists || !$idIsNumeric || !$isSuccess) { if (array_key_exists('message', $result)) { throw new RuntimeException(sprintf('Bad result: %s', $result['message'])); } else { From 889ff4b25c26885057ddcdb5c9489780dd8b2a39 Mon Sep 17 00:00:00 2001 From: Leonard Fischer Date: Tue, 17 Dec 2024 15:58:57 +0100 Subject: [PATCH 6/7] Check both 'id' and 'entry' --- src/CMDBCategory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMDBCategory.php b/src/CMDBCategory.php index 73d2518..ca82700 100644 --- a/src/CMDBCategory.php +++ b/src/CMDBCategory.php @@ -401,7 +401,7 @@ public function batchCreate(array $objectIDs, string $categoryConst, array $attr } } - $entryIDs[] = (int) $entry['id']; + $entryIDs[] = (int) ($entry['id'] ?? $entry['entry']); } return $entryIDs; From e4ce1cb18c5dec8567e65eaa6356d6b5cff94ce5 Mon Sep 17 00:00:00 2001 From: Leonard Fischer Date: Tue, 17 Dec 2024 16:01:22 +0100 Subject: [PATCH 7/7] Fix ID check if none is given --- src/Request.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Request.php b/src/Request.php index b96275f..5f66966 100644 --- a/src/Request.php +++ b/src/Request.php @@ -62,7 +62,7 @@ public function __construct(API $api) { */ protected function requireSuccessFor(array $result): int { $idExists = array_key_exists('id', $result) || array_key_exists('entry', $result); - $idIsNumeric = is_numeric($result['id'] ?? 0) || is_numeric($result['entry'] ?? 0); + $idIsNumeric = is_numeric($result['id'] ?? $result['entry'] ?? null); $isSuccess = array_key_exists('success', $result) && $result['success'] === true; if (!$idExists || !$idIsNumeric || !$isSuccess) {