update
This commit is contained in:
parent
777fa8ffad
commit
b0e98033b4
@ -4,8 +4,10 @@ namespace Core\API\Parameter;
|
|||||||
|
|
||||||
class StringType extends Parameter {
|
class StringType extends Parameter {
|
||||||
|
|
||||||
|
const UNLIMITED = -1;
|
||||||
|
|
||||||
public int $maxLength;
|
public int $maxLength;
|
||||||
public function __construct(string $name, int $maxLength = -1, bool $optional = FALSE, ?string $defaultValue = NULL, ?array $choices = NULL) {
|
public function __construct(string $name, int $maxLength = self::UNLIMITED, bool $optional = FALSE, ?string $defaultValue = NULL, ?array $choices = NULL) {
|
||||||
$this->maxLength = $maxLength;
|
$this->maxLength = $maxLength;
|
||||||
parent::__construct($name, Parameter::TYPE_STRING, $optional, $defaultValue, $choices);
|
parent::__construct($name, Parameter::TYPE_STRING, $optional, $defaultValue, $choices);
|
||||||
}
|
}
|
||||||
|
@ -37,28 +37,11 @@ namespace Core\API\Settings {
|
|||||||
$key = $this->getParam("key");
|
$key = $this->getParam("key");
|
||||||
$sql = $this->context->getSQL();
|
$sql = $this->context->getSQL();
|
||||||
|
|
||||||
$query = $sql->select("name", "value") ->from("Settings");
|
$settings = Settings::getAll($sql, $key);
|
||||||
|
if ($settings !== null) {
|
||||||
if (!is_null($key)) {
|
|
||||||
$query->where(new CondRegex(new Column("name"), $key));
|
|
||||||
}
|
|
||||||
|
|
||||||
// filter sensitive values, if called from outside
|
|
||||||
if ($this->isExternalCall()) {
|
|
||||||
$query->where(new CondNot("private"));
|
|
||||||
}
|
|
||||||
|
|
||||||
$res = $query->execute();
|
|
||||||
|
|
||||||
$this->success = ($res !== FALSE);
|
|
||||||
$this->lastError = $sql->getLastError();
|
|
||||||
|
|
||||||
if ($this->success) {
|
|
||||||
$settings = array();
|
|
||||||
foreach($res as $row) {
|
|
||||||
$settings[$row["name"]] = $row["value"];
|
|
||||||
}
|
|
||||||
$this->result["settings"] = $settings;
|
$this->result["settings"] = $settings;
|
||||||
|
} else {
|
||||||
|
return $this->createError("Error fetching settings: " . $sql->getLastError());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->success;
|
return $this->success;
|
||||||
@ -151,7 +134,7 @@ namespace Core\API\Settings {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function deleteKeys(array $keys) {
|
private function deleteKeys(array $keys): bool {
|
||||||
$sql = $this->context->getSQL();
|
$sql = $this->context->getSQL();
|
||||||
$res = $sql->delete("Settings")
|
$res = $sql->delete("Settings")
|
||||||
->where(new CondIn(new Column("name"), $keys))
|
->where(new CondIn(new Column("name"), $keys))
|
||||||
|
@ -7,7 +7,11 @@
|
|||||||
namespace Core\Configuration;
|
namespace Core\Configuration;
|
||||||
|
|
||||||
use Core\Driver\Logger\Logger;
|
use Core\Driver\Logger\Logger;
|
||||||
|
use Core\Driver\SQL\Column\Column;
|
||||||
|
use Core\Driver\SQL\Condition\CondNot;
|
||||||
|
use Core\Driver\SQL\Condition\CondRegex;
|
||||||
use Core\Driver\SQL\Query\Insert;
|
use Core\Driver\SQL\Query\Insert;
|
||||||
|
use Core\Driver\SQL\SQL;
|
||||||
use Core\Objects\Context;
|
use Core\Objects\Context;
|
||||||
|
|
||||||
class Settings {
|
class Settings {
|
||||||
@ -45,6 +49,41 @@ class Settings {
|
|||||||
$this->logger = new Logger("Settings");
|
$this->logger = new Logger("Settings");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getAll(?SQL $sql, ?string $pattern = null, bool $external = false): ?array {
|
||||||
|
$query = $sql->select("name", "value") ->from("Settings");
|
||||||
|
|
||||||
|
if ($pattern) {
|
||||||
|
$query->where(new CondRegex(new Column("name"), $pattern));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($external) {
|
||||||
|
$query->where(new CondNot("private"));
|
||||||
|
}
|
||||||
|
|
||||||
|
$res = $query->execute();
|
||||||
|
if ($res !== false && $res !== null) {
|
||||||
|
$settings = array();
|
||||||
|
foreach($res as $row) {
|
||||||
|
$settings[$row["name"]] = $row["value"];
|
||||||
|
}
|
||||||
|
return $settings;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function get(?SQL $sql, string $key, mixed $defaultValue): mixed {
|
||||||
|
$res = $sql->select("value") ->from("Settings")
|
||||||
|
->whereEq("name", $key)
|
||||||
|
->execute();
|
||||||
|
|
||||||
|
if ($res === false || $res === null) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return (empty($res)) ? $defaultValue : $res[0]["value"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function getJwtPublicKey(bool $allowPrivate = true): ?\Firebase\JWT\Key {
|
public function getJwtPublicKey(bool $allowPrivate = true): ?\Firebase\JWT\Key {
|
||||||
if (empty($this->jwtPublicKey)) {
|
if (empty($this->jwtPublicKey)) {
|
||||||
if ($allowPrivate && $this->jwtSecretKey) {
|
if ($allowPrivate && $this->jwtSecretKey) {
|
||||||
|
@ -201,7 +201,10 @@ class MySQL extends SQL {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (\mysqli_sql_exception $exception) {
|
} catch (\mysqli_sql_exception $exception) {
|
||||||
$this->lastError = $this->logger->error("MySQL::execute failed: $stmt->error ($stmt->errno)");
|
$this->lastError = $this->logger->error("MySQL::execute failed: " .
|
||||||
|
($stmt !== null
|
||||||
|
? "$stmt->error ($stmt->errno)"
|
||||||
|
: $exception->getMessage()));
|
||||||
} finally {
|
} finally {
|
||||||
|
|
||||||
if ($res !== null && !is_bool($res) && $fetchType !== self::FETCH_ITERATIVE) {
|
if ($res !== null && !is_bool($res) && $fetchType !== self::FETCH_ITERATIVE) {
|
||||||
|
@ -1,13 +1,17 @@
|
|||||||
FROM composer:latest AS composer
|
FROM composer:latest AS composer
|
||||||
FROM php:8.0-fpm
|
FROM php:8.1-fpm
|
||||||
WORKDIR "/application"
|
WORKDIR "/application"
|
||||||
|
|
||||||
|
ARG ADDITIONAL_PACKAGES
|
||||||
|
ARG ADDITIONAL_SCRIPT
|
||||||
|
|
||||||
RUN mkdir -p /application/core/Configuration /var/www/.gnupg && \
|
RUN mkdir -p /application/core/Configuration /var/www/.gnupg && \
|
||||||
chown -R www-data:www-data /application /var/www/ && \
|
chown -R www-data:www-data /application /var/www/ && \
|
||||||
chmod 700 /var/www/.gnupg
|
chmod 700 /var/www/.gnupg
|
||||||
|
|
||||||
# YAML + dev dependencies
|
# YAML + dev dependencies + additional packages
|
||||||
RUN apt-get update -y && \
|
RUN apt-get update -y && \
|
||||||
apt-get install -y libyaml-dev libzip-dev libgmp-dev libpng-dev gnupg2 && \
|
apt-get install -y libyaml-dev libzip-dev libgmp-dev libpng-dev gnupg2 $ADDITIONAL_PACKAGES && \
|
||||||
pecl install yaml && docker-php-ext-enable yaml && \
|
pecl install yaml && docker-php-ext-enable yaml && \
|
||||||
docker-php-ext-install gd
|
docker-php-ext-install gd
|
||||||
|
|
||||||
@ -27,5 +31,8 @@ RUN docker-php-ext-install mysqli zip gmp
|
|||||||
# clean cache
|
# clean cache
|
||||||
RUN apt-get clean
|
RUN apt-get clean
|
||||||
|
|
||||||
|
# run additional scripts
|
||||||
|
RUN if [[ ! -z "$ADDITIONAL_SCRIPT" ]]; then $ADDITIONAL_SCRIPT; fi
|
||||||
|
|
||||||
COPY --from=composer /usr/bin/composer /usr/bin/composer
|
COPY --from=composer /usr/bin/composer /usr/bin/composer
|
||||||
USER www-data
|
USER www-data
|
Loading…
Reference in New Issue
Block a user