Return numbers as numbers on all API endpoints

This commit is contained in:
Bernd Bestel
2022-12-25 20:49:11 +01:00
parent 639ef0da5b
commit 46c4cdb81a
3 changed files with 12 additions and 3 deletions

View File

@@ -62,6 +62,7 @@
- ⚠️ **Breaking changes**: - ⚠️ **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 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) - 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) - 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) - `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`) - The endpoint `/batteries` now also returns the corresponding battery object (as field/property `battery`)

View File

@@ -9,12 +9,14 @@ const REQUIRED_PHP_EXTENSIONS = ['fileinfo', 'pdo_sqlite', 'gd', 'ctype', 'json'
'filter', 'iconv', 'tokenizer' 'filter', 'iconv', 'tokenizer'
]; ];
const REQUIRED_PHP_VERSION = '8.1.0';
const REQUIRED_SQLITE_VERSION = '3.22.0'; const REQUIRED_SQLITE_VERSION = '3.22.0';
class PrerequisiteChecker class PrerequisiteChecker
{ {
public function checkRequirements() public function checkRequirements()
{ {
self::checkForPhpVersion();
self::checkForConfigFile(); self::checkForConfigFile();
self::checkForConfigDistFile(); self::checkForConfigDistFile();
self::checkForComposer(); self::checkForComposer();
@@ -49,7 +51,6 @@ class PrerequisiteChecker
private function checkForPhpExtensions() private function checkForPhpExtensions()
{ {
$loadedExtensions = get_loaded_extensions(); $loadedExtensions = get_loaded_extensions();
foreach (REQUIRED_PHP_EXTENSIONS as $extension) foreach (REQUIRED_PHP_EXTENSIONS as $extension)
{ {
if (!in_array($extension, $loadedExtensions)) if (!in_array($extension, $loadedExtensions))
@@ -62,13 +63,21 @@ class PrerequisiteChecker
private function checkForSqliteVersion() private function checkForSqliteVersion()
{ {
$sqliteVersion = self::getSqlVersionAsString(); $sqliteVersion = self::getSqlVersionAsString();
if (version_compare($sqliteVersion, REQUIRED_SQLITE_VERSION, '<')) if (version_compare($sqliteVersion, REQUIRED_SQLITE_VERSION, '<'))
{ {
throw new ERequirementNotMet('SQLite ' . REQUIRED_SQLITE_VERSION . ' is required, however you are running ' . $sqliteVersion); 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() private function getSqlVersionAsString()
{ {
$dbh = new PDO('sqlite::memory:'); $dbh = new PDO('sqlite::memory:');

View File

@@ -69,7 +69,6 @@ class DatabaseService
{ {
$pdo = new \PDO('sqlite:' . $this->GetDbFilePath()); $pdo = new \PDO('sqlite:' . $this->GetDbFilePath());
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$pdo->setAttribute(\PDO::ATTR_STRINGIFY_FETCHES, true);
$pdo->sqliteCreateFunction('regexp', function ($pattern, $value) { $pdo->sqliteCreateFunction('regexp', function ($pattern, $value) {
mb_regex_encoding('UTF-8'); mb_regex_encoding('UTF-8');