phan and phpstan fixes, also add a convert flag reset to original
dbResetConvertFlag resets to the settings given on init of class
This commit is contained in:
@@ -41,7 +41,8 @@ class EditBase
|
||||
/**
|
||||
* construct form generator
|
||||
*
|
||||
* @param array<mixed> $db_config db config array, mandatory
|
||||
* phpcs:ignore
|
||||
* @param array{db_name:string,db_user:string,db_pass:string,db_host:string,db_port:int,db_schema:string,db_encoding:string,db_type:string,db_ssl:string,db_convert_type?:string[]} $db_config db config array, mandatory
|
||||
* @param \CoreLibs\Logging\Logging $log Logging class, null auto set
|
||||
* @param \CoreLibs\Language\L10n $l10n l10n language class, null auto set
|
||||
* @param \CoreLibs\ACL\Login $login login class for ACL settings
|
||||
|
||||
@@ -54,7 +54,8 @@ class ArrayIO extends \CoreLibs\DB\IO
|
||||
* constructor for the array io class, set the
|
||||
* primary key name automatically (from array)
|
||||
*
|
||||
* @param array<mixed> $db_config db connection config
|
||||
* phpcs:ignore
|
||||
* @param array{db_name:string,db_user:string,db_pass:string,db_host:string,db_port:int,db_schema:string,db_encoding:string,db_type:string,db_ssl:string,db_convert_type?:string[]} $db_config db connection config
|
||||
* @param array<mixed> $table_array table array config
|
||||
* @param string $table_name table name string
|
||||
* @param \CoreLibs\Logging\Logging $log Logging class
|
||||
|
||||
@@ -339,7 +339,7 @@ class IO
|
||||
// 2: convert json/jsonb to array (CONVERT_JSON)
|
||||
// 4: convert numeric/floatN to float (CONVERT_NUMERIC)
|
||||
// 8: convert bytea to string data (CONVERT_BYTEA)
|
||||
/** @var int convert type settings as bit mask, 0 for off, anything >2 will aways set 1 too */
|
||||
/** @var int type settings as bit mask, 0 for off, anything >2 will aways set 1 too */
|
||||
private int $convert_type = Convert::off->value;
|
||||
// FOR BELOW: (This should be private and only readable through some method)
|
||||
// cursor array for cached readings
|
||||
@@ -410,7 +410,8 @@ class IO
|
||||
* main DB concstructor with auto connection to DB
|
||||
* and failure set on failed connection
|
||||
*
|
||||
* @param array<mixed> $db_config DB configuration array
|
||||
* phpcs:ignore
|
||||
* @param array{db_name:string,db_user:string,db_pass:string,db_host:string,db_port:int,db_schema:string,db_encoding:string,db_type:string,db_ssl:string,db_convert_type?:string[]} $db_config DB configuration array
|
||||
* @param \CoreLibs\Logging\Logging $log Logging class
|
||||
*/
|
||||
public function __construct(
|
||||
@@ -508,7 +509,8 @@ class IO
|
||||
/**
|
||||
* Setup DB config and options
|
||||
*
|
||||
* @param array<string,string|int|array<string>> $db_config
|
||||
* phpcs:ignore
|
||||
* @param array{db_name:string,db_user:string,db_pass:string,db_host:string,db_port:int,db_schema:string,db_encoding:string,db_type:string,db_ssl:string,db_convert_type?:string[]} $db_config
|
||||
* @return bool
|
||||
*/
|
||||
private function __setConfigOptions(array $db_config): bool
|
||||
@@ -548,6 +550,21 @@ class IO
|
||||
continue;
|
||||
}
|
||||
$this->db_convert_type[] = $db_convert_type;
|
||||
$this->__setConvertType($db_convert_type);
|
||||
}
|
||||
|
||||
// return status true: ok, false: options error
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the convert bit flags
|
||||
*
|
||||
* @param string $db_convert_type One of 'on', 'json', 'numeric', 'bytea'
|
||||
* @return void
|
||||
*/
|
||||
private function __setConvertType(string $db_convert_type): void
|
||||
{
|
||||
switch ($db_convert_type) {
|
||||
case 'on':
|
||||
$this->convert_type |= Convert::on->value;
|
||||
@@ -567,10 +584,6 @@ class IO
|
||||
}
|
||||
}
|
||||
|
||||
// return status true: ok, false: options error
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* based on $this->db_type
|
||||
* here we need to load the db pgsql include one
|
||||
@@ -1046,7 +1059,7 @@ class IO
|
||||
// always bool/int
|
||||
if (
|
||||
$this->dbGetFieldType($key) != 'interval' &&
|
||||
str_starts_with($this->dbGetFieldType($key), 'int')
|
||||
str_starts_with($this->dbGetFieldType($key) ?: '', 'int')
|
||||
) {
|
||||
$row[$key] = (int)$value;
|
||||
}
|
||||
@@ -1055,15 +1068,15 @@ class IO
|
||||
}
|
||||
if (
|
||||
$this->convert_type & Convert::json->value &&
|
||||
str_starts_with($this->dbGetFieldType($key), 'json')
|
||||
str_starts_with($this->dbGetFieldType($key) ?: '', 'json')
|
||||
) {
|
||||
$row[$key] = Json::jsonConvertToArray($value);
|
||||
}
|
||||
if (
|
||||
$this->convert_type & Convert::numeric->value &&
|
||||
(
|
||||
str_starts_with($this->dbGetFieldType($key), 'numeric') ||
|
||||
str_starts_with($this->dbGetFieldType($key), 'float')
|
||||
str_starts_with($this->dbGetFieldType($key) ?: '', 'numeric') ||
|
||||
str_starts_with($this->dbGetFieldType($key) ?: '', 'float')
|
||||
// $this->dbGetFieldType($key) == 'real'
|
||||
)
|
||||
) {
|
||||
@@ -3407,6 +3420,18 @@ class IO
|
||||
$this->convert_type &= ~$convert->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset to origincal config file set
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function dbResetConvertFlag(): void
|
||||
{
|
||||
foreach ($this->db_convert_type as $db_convert_type) {
|
||||
$this->__setConvertType($db_convert_type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
|
||||
@@ -953,11 +953,11 @@ class Logging
|
||||
*
|
||||
* @param string $group_id id for error message, groups messages together
|
||||
* @param string|Stringable $message the actual error message
|
||||
* @param mixed[] $context
|
||||
* @param string $prefix Attach some block before $string.
|
||||
* Will not be stripped even
|
||||
* when strip is true
|
||||
* if strip is false, recommended to add that to $string
|
||||
* @param mixed[] $context
|
||||
* @return bool True if logged, false if not logged
|
||||
*/
|
||||
public function debug(
|
||||
|
||||
@@ -308,7 +308,8 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
/**
|
||||
* construct form generator
|
||||
*
|
||||
* @param array<mixed> $db_config db config array, mandatory
|
||||
* phpcs:ignore
|
||||
* @param array{db_name:string,db_user:string,db_pass:string,db_host:string,db_port:int,db_schema:string,db_encoding:string,db_type:string,db_ssl:string,db_convert_type?:string[]} $db_config db config array, mandatory
|
||||
* @param \CoreLibs\Logging\Logging $log Logging class
|
||||
* @param \CoreLibs\Language\L10n $l10n l10n language class
|
||||
* @param array<string,mixed> $login_acl Login ACL array,
|
||||
|
||||
@@ -36,6 +36,7 @@ class Image
|
||||
): string|false {
|
||||
// get image type flags
|
||||
$image_types = [
|
||||
0 => 'UNKOWN-IMAGE',
|
||||
1 => 'gif',
|
||||
2 => 'jpg',
|
||||
3 => 'png'
|
||||
@@ -69,7 +70,7 @@ class Image
|
||||
}
|
||||
// does this picture exist and is it a picture
|
||||
if (file_exists($filename) && is_file($filename)) {
|
||||
[$width, $height, $type] = getimagesize($filename) ?: [0, 0, null];
|
||||
[$width, $height, $type] = getimagesize($filename) ?: [0, 0, 0];
|
||||
$convert_prefix = '';
|
||||
$create_file = false;
|
||||
$delete_filename = '';
|
||||
@@ -98,7 +99,7 @@ class Image
|
||||
if (!is_file($filename)) {
|
||||
$filename .= '-0';
|
||||
}
|
||||
[$width, $height, $type] = getimagesize($filename) ?: [0, 0, null];
|
||||
[$width, $height, $type] = getimagesize($filename) ?: [0, 0, 0];
|
||||
}
|
||||
// if no size given, set size to original
|
||||
if (!$size_x || $size_x < 1) {
|
||||
@@ -117,7 +118,7 @@ class Image
|
||||
$status = exec($convert_string, $output, $return);
|
||||
// get the size of the converted data, if converted
|
||||
if (is_file($thumbnail)) {
|
||||
[$width, $height, $type] = getimagesize($thumbnail) ?: [0, 0, null];
|
||||
[$width, $height, $type] = getimagesize($thumbnail) ?: [0, 0, 0];
|
||||
}
|
||||
}
|
||||
if ($height > $size_y) {
|
||||
|
||||
Reference in New Issue
Block a user