From cee54a1946d85efbd6122735fbbafd37c78caf78 Mon Sep 17 00:00:00 2001 From: Roman Date: Mon, 9 Jan 2023 15:59:53 +0100 Subject: [PATCH] bugfix --- Core/API/RoutesAPI.class.php | 2 +- Core/Driver/SQL/MySQL.class.php | 8 +++++--- Core/Driver/SQL/Query/CreateProcedure.class.php | 3 ++- Core/Driver/SQL/Type/CurrentTable.class.php | 11 +++++++++-- .../Controller/DatabaseEntityHandler.php | 2 +- Core/Objects/Router/Router.class.php | 8 ++++++++ docker/php/Dockerfile | 15 +++++++++++---- 7 files changed, 37 insertions(+), 12 deletions(-) diff --git a/Core/API/RoutesAPI.class.php b/Core/API/RoutesAPI.class.php index 43407aa..60ee17d 100644 --- a/Core/API/RoutesAPI.class.php +++ b/Core/API/RoutesAPI.class.php @@ -14,7 +14,7 @@ namespace Core\API { public function __construct(Context $context, bool $externalCall, array $params) { parent::__construct($context, $externalCall, $params); - $this->routerCachePath = getClassPath(self::ROUTER_CACHE_CLASS); + $this->routerCachePath = WEBROOT . DIRECTORY_SEPARATOR . getClassPath(self::ROUTER_CACHE_CLASS); } protected function toggleRoute(int $id, bool $active): bool { diff --git a/Core/Driver/SQL/MySQL.class.php b/Core/Driver/SQL/MySQL.class.php index fbe8ff1..8503cf9 100644 --- a/Core/Driver/SQL/MySQL.class.php +++ b/Core/Driver/SQL/MySQL.class.php @@ -419,9 +419,11 @@ class MySQL extends SQL { $returns = $procedure->getReturns(); $paramDefs = []; - foreach ($procedure->getParameters() as $param) { - if ($param instanceof Column) { - $paramDefs[] = $this->getParameterDefinition($param); + foreach ($procedure->getParameters() as $parameter) { + if ($parameter instanceof Column) { + $paramDefs[] = $this->getParameterDefinition($parameter); + } else if ($parameter instanceof CurrentTable) { + $paramDefs[] = $this->getParameterDefinition($parameter->toColumn()); } else { $this->lastError = $this->logger->error("PROCEDURE parameter type " . gettype($returns) . " is not implemented yet"); return null; diff --git a/Core/Driver/SQL/Query/CreateProcedure.class.php b/Core/Driver/SQL/Query/CreateProcedure.class.php index 6b19a24..c099c63 100644 --- a/Core/Driver/SQL/Query/CreateProcedure.class.php +++ b/Core/Driver/SQL/Query/CreateProcedure.class.php @@ -4,6 +4,7 @@ namespace Core\Driver\SQL\Query; use Core\Driver\SQL\Column\Column; +use Core\Driver\SQL\Expression\Expression; use Core\Driver\SQL\SQL; class CreateProcedure extends Query { @@ -21,7 +22,7 @@ class CreateProcedure extends Query { $this->returns = NULL; } - public function param(Column $parameter): CreateProcedure { + public function param(Expression $parameter): CreateProcedure { $this->parameters[] = $parameter; return $this; } diff --git a/Core/Driver/SQL/Type/CurrentTable.class.php b/Core/Driver/SQL/Type/CurrentTable.class.php index 5b38860..65e70ea 100644 --- a/Core/Driver/SQL/Type/CurrentTable.class.php +++ b/Core/Driver/SQL/Type/CurrentTable.class.php @@ -2,10 +2,13 @@ namespace Core\Driver\SQL\Type; +use Core\Driver\SQL\Column\Column; +use Core\Driver\SQL\Column\StringColumn; use Core\Driver\SQL\Expression\Expression; use Core\Driver\SQL\MySQL; use Core\Driver\SQL\PostgreSQL; use Core\Driver\SQL\SQL; +use Exception; class CurrentTable extends Expression { @@ -14,11 +17,15 @@ class CurrentTable extends Expression { function getExpression(SQL $sql, array &$params): string { if ($sql instanceof MySQL) { - // CURRENT_TABLE + return $sql->columnName("CURRENT_TABLE"); } else if ($sql instanceof PostgreSQL) { return "TG_TABLE_NAME"; } else { - + throw new Exception("CurrentTable Not implemented for driver type: " . get_class($sql)); } } + + public function toColumn(): Column { + return new StringColumn("CURRENT_TABLE"); + } } \ No newline at end of file diff --git a/Core/Objects/DatabaseEntity/Controller/DatabaseEntityHandler.php b/Core/Objects/DatabaseEntity/Controller/DatabaseEntityHandler.php index f2e7ed0..f6a517f 100644 --- a/Core/Objects/DatabaseEntity/Controller/DatabaseEntityHandler.php +++ b/Core/Objects/DatabaseEntity/Controller/DatabaseEntityHandler.php @@ -461,7 +461,7 @@ class DatabaseEntityHandler implements Persistable { $doInsert = false; foreach ($nmRelation->getProperties($this) as $property) { - if ($properties !== null || !in_array($property->getName(), $properties)) { + if ($properties !== null && !in_array($property->getName(), $properties)) { continue; } diff --git a/Core/Objects/Router/Router.class.php b/Core/Objects/Router/Router.class.php index 9bbe2fc..24bde34 100644 --- a/Core/Objects/Router/Router.class.php +++ b/Core/Objects/Router/Router.class.php @@ -124,6 +124,14 @@ class RouterCache extends Router { } "; + $directory = dirname($file); + if (!is_dir($directory)) { + if (!mkdir($directory, 775, true)) { + $this->logger->severe("Could not create directory: $directory"); + return false; + } + } + if (@file_put_contents($file, $code) === false) { $this->logger->severe("Could not write Router cache file: $file"); return false; diff --git a/docker/php/Dockerfile b/docker/php/Dockerfile index 80ab317..2bc369d 100644 --- a/docker/php/Dockerfile +++ b/docker/php/Dockerfile @@ -7,11 +7,15 @@ RUN mkdir -p /application/core/Configuration /var/www/.gnupg && \ # YAML + dev dependencies RUN apt-get update -y && \ - apt-get install -y libyaml-dev libzip-dev libgmp-dev libpng-dev gnupg2d nodejs npm && \ - apt-get clean && \ + apt-get install -y libyaml-dev libzip-dev libgmp-dev libpng-dev gnupg2 && \ pecl install yaml && docker-php-ext-enable yaml && \ - docker-php-ext-install gd && \ - npm install --global yarn && ln -s /usr/local/bin/yarn /usr/bin/yarn + docker-php-ext-install gd + +# NodeJS +RUN curl -sL https://deb.nodesource.com/setup_14.x | bash - && \ + apt-get update && \ + apt-get -y install nodejs && \ + npm install --global yarn # Runkit for unit testing (no stable release available) RUN pecl install runkit7-4.0.0a6 && docker-php-ext-enable runkit7 && \ @@ -20,5 +24,8 @@ RUN pecl install runkit7-4.0.0a6 && docker-php-ext-enable runkit7 && \ # mysqli, zip, gmp RUN docker-php-ext-install mysqli zip gmp +# clean cache +RUN apt-get clean + COPY --from=composer /usr/bin/composer /usr/bin/composer USER www-data \ No newline at end of file