From 46c4cdb81a42568dd9a00db236fd477df90da27f Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Sun, 25 Dec 2022 20:49:11 +0100 Subject: [PATCH] Return numbers as numbers on all API endpoints --- changelog/70_UNRELEASED_xxxx.xx.xx.md | 1 + helpers/PrerequisiteChecker.php | 13 +++++++++++-- services/DatabaseService.php | 1 - 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/changelog/70_UNRELEASED_xxxx.xx.xx.md b/changelog/70_UNRELEASED_xxxx.xx.xx.md index 2ff0b1ad..508d0073 100644 --- a/changelog/70_UNRELEASED_xxxx.xx.xx.md +++ b/changelog/70_UNRELEASED_xxxx.xx.xx.md @@ -62,6 +62,7 @@ - ⚠️ **Breaking changes**: - The product property `qu_factor_purchase_to_stock` was removed (existing factors were migrated to normal product specific QU conversions, see above) - The endpoint `/stock/products/{productId}` returns a new field/property `qu_conversion_factor_purchase_to_stock` for convenience (contains the conversion factor of the corresponding QU conversion from the product's qu_id_purchase to qu_id_stock) + - Numbers are now returned as numbers (so technically without quotes around them, were strings for nearly all endpoints before) - The following entities are now also available via the endpoint `/objects/{entity}` (only listing, no edit) - `quantity_unit_conversions_resolved` (returns all final/resolved conversion factors per product and any directly or indirectly related quantity units) - The endpoint `/batteries` now also returns the corresponding battery object (as field/property `battery`) diff --git a/helpers/PrerequisiteChecker.php b/helpers/PrerequisiteChecker.php index f055f965..f7c68f5f 100644 --- a/helpers/PrerequisiteChecker.php +++ b/helpers/PrerequisiteChecker.php @@ -9,12 +9,14 @@ const REQUIRED_PHP_EXTENSIONS = ['fileinfo', 'pdo_sqlite', 'gd', 'ctype', 'json' 'filter', 'iconv', 'tokenizer' ]; +const REQUIRED_PHP_VERSION = '8.1.0'; const REQUIRED_SQLITE_VERSION = '3.22.0'; class PrerequisiteChecker { public function checkRequirements() { + self::checkForPhpVersion(); self::checkForConfigFile(); self::checkForConfigDistFile(); self::checkForComposer(); @@ -49,7 +51,6 @@ class PrerequisiteChecker private function checkForPhpExtensions() { $loadedExtensions = get_loaded_extensions(); - foreach (REQUIRED_PHP_EXTENSIONS as $extension) { if (!in_array($extension, $loadedExtensions)) @@ -62,13 +63,21 @@ class PrerequisiteChecker private function checkForSqliteVersion() { $sqliteVersion = self::getSqlVersionAsString(); - if (version_compare($sqliteVersion, REQUIRED_SQLITE_VERSION, '<')) { throw new ERequirementNotMet('SQLite ' . REQUIRED_SQLITE_VERSION . ' is required, however you are running ' . $sqliteVersion); } } + private function checkForPhpVersion() + { + $phpVersion = phpversion(); + if (version_compare($phpVersion, REQUIRED_PHP_VERSION, '<')) + { + throw new ERequirementNotMet('PHP ' . REQUIRED_PHP_VERSION . ' is required, however you are running ' . $phpVersion); + } + } + private function getSqlVersionAsString() { $dbh = new PDO('sqlite::memory:'); diff --git a/services/DatabaseService.php b/services/DatabaseService.php index 7d111f75..c093f361 100644 --- a/services/DatabaseService.php +++ b/services/DatabaseService.php @@ -69,7 +69,6 @@ class DatabaseService { $pdo = new \PDO('sqlite:' . $this->GetDbFilePath()); $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); - $pdo->setAttribute(\PDO::ATTR_STRINGIFY_FETCHES, true); $pdo->sqliteCreateFunction('regexp', function ($pattern, $value) { mb_regex_encoding('UTF-8');