Compare commits

..

2 Commits

Author SHA1 Message Date
Clemens Schwaighofer
4b3fbaa309 Updates based on latest phpstan run 2022-09-02 17:00:22 +09:00
Clemens Schwaighofer
1a6c65df0e Minor test updates, comment typo updates, DB_CONFIG_SET for default
$DB_CONFIG_SET is now default current selcted db config instead of
$DB_CONFIG so to not overwrite the array itself
2022-08-05 12:43:57 +09:00
8 changed files with 64 additions and 54 deletions

View File

@@ -1,72 +1,47 @@
parameters: parameters:
ignoreErrors: ignoreErrors:
- -
message: "#^Parameter \\#1 \\$connection of function pg_connection_busy expects PgSql\\\\Connection, object\\|resource given\\.$#" message: "#^Parameter \\#1 \\$connection of function pg_escape_bytea expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#"
count: 3
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
-
message: "#^Parameter \\#1 \\$connection of function pg_connection_status expects PgSql\\\\Connection, object\\|resource given\\.$#"
count: 1 count: 1
path: www/lib/CoreLibs/DB/SQL/PgSQL.php path: www/lib/CoreLibs/DB/SQL/PgSQL.php
- -
message: "#^Parameter \\#1 \\$connection of function pg_get_result expects PgSql\\\\Connection, object\\|resource given\\.$#" message: "#^Parameter \\#1 \\$connection of function pg_escape_identifier expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#"
count: 2
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
-
message: "#^Parameter \\#1 \\$connection of function pg_meta_data expects PgSql\\\\Connection, object\\|resource given\\.$#"
count: 1 count: 1
path: www/lib/CoreLibs/DB/SQL/PgSQL.php path: www/lib/CoreLibs/DB/SQL/PgSQL.php
- -
message: "#^Parameter \\#1 \\$connection of function pg_send_query expects PgSql\\\\Connection, object\\|resource given\\.$#" message: "#^Parameter \\#1 \\$connection of function pg_escape_literal expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#"
count: 2
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
-
message: "#^Parameter \\#1 \\$connection of function pg_socket expects PgSql\\\\Connection, object\\|resource given\\.$#"
count: 1 count: 1
path: www/lib/CoreLibs/DB/SQL/PgSQL.php path: www/lib/CoreLibs/DB/SQL/PgSQL.php
- -
message: "#^Parameter \\#1 \\$connection of function pg_version expects PgSql\\\\Connection\\|null, object\\|resource given\\.$#" message: "#^Parameter \\#1 \\$connection of function pg_escape_string expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#"
count: 2
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
-
message: "#^Parameter \\#1 \\$result of function pg_affected_rows expects PgSql\\\\Result, object\\|resource given\\.$#"
count: 1 count: 1
path: www/lib/CoreLibs/DB/SQL/PgSQL.php path: www/lib/CoreLibs/DB/SQL/PgSQL.php
- -
message: "#^Parameter \\#1 \\$result of function pg_fetch_all expects PgSql\\\\Result, object\\|resource given\\.$#" message: "#^Parameter \\#1 \\$connection of function pg_execute expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#"
count: 1 count: 1
path: www/lib/CoreLibs/DB/SQL/PgSQL.php path: www/lib/CoreLibs/DB/SQL/PgSQL.php
- -
message: "#^Parameter \\#1 \\$result of function pg_fetch_array expects PgSql\\\\Result, object\\|resource given\\.$#" message: "#^Parameter \\#1 \\$connection of function pg_parameter_status expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#"
count: 1 count: 1
path: www/lib/CoreLibs/DB/SQL/PgSQL.php path: www/lib/CoreLibs/DB/SQL/PgSQL.php
- -
message: "#^Parameter \\#1 \\$result of function pg_field_name expects PgSql\\\\Result, object\\|resource given\\.$#" message: "#^Parameter \\#1 \\$connection of function pg_prepare expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#"
count: 1 count: 1
path: www/lib/CoreLibs/DB/SQL/PgSQL.php path: www/lib/CoreLibs/DB/SQL/PgSQL.php
- -
message: "#^Parameter \\#1 \\$result of function pg_num_fields expects PgSql\\\\Result, object\\|resource given\\.$#" message: "#^Parameter \\#1 \\$connection of function pg_query expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#"
count: 1 count: 1
path: www/lib/CoreLibs/DB/SQL/PgSQL.php path: www/lib/CoreLibs/DB/SQL/PgSQL.php
- -
message: "#^Parameter \\#1 \\$result of function pg_num_rows expects PgSql\\\\Result, object\\|resource given\\.$#" message: "#^Parameter \\#1 \\$connection of function pg_query_params expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#"
count: 1
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
-
message: "#^Parameter \\#1 \\$result of function pg_result_error expects PgSql\\\\Result, object\\|resource given\\.$#"
count: 1 count: 1
path: www/lib/CoreLibs/DB/SQL/PgSQL.php path: www/lib/CoreLibs/DB/SQL/PgSQL.php

View File

@@ -49,11 +49,11 @@ parameters:
- www/vendor - www/vendor
# ignore errores with # ignore errores with
ignoreErrors: ignoreErrors:
- # this error is ignore because of the PHP 8.0 to 8.1 change for pg_*, only for 8.0 or lower #- # this error is ignore because of the PHP 8.0 to 8.1 change for pg_*, only for 8.0 or lower
message: "#^Parameter \\#1 \\$(result|connection) of function pg_\\w+ expects resource(\\|null)?, object\\|resource(\\|bool)? given\\.$#" # message: "#^Parameter \\#1 \\$(result|connection) of function pg_\\w+ expects resource(\\|null)?, object\\|resource(\\|bool)? given\\.$#"
path: %currentWorkingDirectory%/www/lib/CoreLibs/DB/SQL/PgSQL.php # path: %currentWorkingDirectory%/www/lib/CoreLibs/DB/SQL/PgSQL.php
- # this is for 8.1 or newer - # this is for 8.1 or newer
message: "#^Parameter \\#1 \\$(result|connection) of function pg_\\w+ expects PgSql\\\\(Result|Connection(\\|null)?), object\\|resource given\\.$#" message: "#^Parameter \\#1 \\$(result|connection) of function pg_\\w+ expects PgSql\\\\(Result|Connection(\\|string)?(\\|null)?), object\\|resource given\\.$#"
path: %currentWorkingDirectory%/www/lib/CoreLibs/DB/SQL/PgSQL.php path: %currentWorkingDirectory%/www/lib/CoreLibs/DB/SQL/PgSQL.php
# this is ignored for now # this is ignored for now
# - '#Expression in empty\(\) is always falsy.#' # - '#Expression in empty\(\) is always falsy.#'

View File

@@ -209,13 +209,12 @@ print "INSERT WITH NO PRIMARY KEY WITH RETURNING STATUS: " . Support::printToStr
print "</pre>"; print "</pre>";
// READ PREPARE // READ PREPARE
if ( $q_prep = "SELECT test_foo_id, test, some_bool, string_a, number_a, "
$db->dbPrepare( . "number_a_numeric, some_time "
'sel_test_foo', . "FROM test_foo "
"SELECT test_foo_id, test, some_bool, string_a, number_a, number_a_numeric, some_time " . "WHERE test = $1 "
. "FROM test_foo ORDER BY test_foo_id DESC LIMIT 5" . "ORDER BY test_foo_id DESC LIMIT 5";
) === false if ($db->dbPrepare('sel_test_foo', $q_prep) === false) {
) {
print "Error in sel_test_foo prepare<br>"; print "Error in sel_test_foo prepare<br>";
} else { } else {
$max_rows = 6; $max_rows = 6;
@@ -229,6 +228,29 @@ if (
$i++; $i++;
} }
} }
// prepre a second time on normal connection
if ($db->dbPrepare('sel_test_foo', $q_prep) === false) {
print "Error prepareing<br>";
print "ERROR (dbPrepare on same query): "
. $db->dbGetLastError() . "/" . $db->dbGetLastWarning() . "/"
. "<pre>" . print_r($db->dbGetCombinedErrorHistory(), true) . "</pre><br>";
}
// NOTE: try to replacate connection still exists if script is run a second time
// open pg bouncer connection
$db_pgb = new CoreLibs\DB\IO($DB_CONFIG['test_pgbouncer'], $log);
print "[PGB] DBINFO: " . $db_pgb->dbInfo() . "<br>";
if ($db->dbPrepare('pgb_sel_test_foo', $q_prep) === false) {
print "[PGB] [1] Error in pgb_sel_test_foo prepare<br>";
} else {
print "[PGB] [1] pgb_sel_test_foo prepare OK<br>";
}
// second prepare
if ($db->dbPrepare('pgb_sel_test_foo', $q_prep) === false) {
print "[PGB] [2] Error in pgb_sel_test_foo prepare<br>";
} else {
print "[PGB] [2] pgb_sel_test_foo prepare OK<br>";
}
$db_pgb->dbClose();
# db write class test # db write class test
$table = 'test_foo'; $table = 'test_foo';

View File

@@ -17,7 +17,20 @@ $DB_CONFIG = [
'db_user' => $_ENV['DB_USER.TEST'] ?? '', 'db_user' => $_ENV['DB_USER.TEST'] ?? '',
'db_pass' => $_ENV['DB_PASS.TEST'] ?? '', 'db_pass' => $_ENV['DB_PASS.TEST'] ?? '',
'db_host' => $_ENV['DB_HOST.TEST'] ?? '', 'db_host' => $_ENV['DB_HOST.TEST'] ?? '',
'db_port' => 5432, 'db_port' => $_ENV['DB_PORT.PG'] ?? 5432,
'db_schema' => 'public',
'db_type' => 'pgsql',
'db_encoding' => '',
'db_ssl' => 'allow', // allow, disable, require, prefer
'db_debug' => true, // turn on logging or not
],
// same as above, but uses pg bouncer
'test_pgbouncer' => [
'db_name' => $_ENV['DB_NAME.TEST'] ?? '',
'db_user' => $_ENV['DB_USER.TEST'] ?? '',
'db_pass' => $_ENV['DB_PASS.TEST'] ?? '',
'db_host' => $_ENV['DB_HOST.TEST'] ?? '',
'db_port' => $_ENV['DB_PORT.PG_BOUNCER'] ?? 5432,
'db_schema' => 'public', 'db_schema' => 'public',
'db_type' => 'pgsql', 'db_type' => 'pgsql',
'db_encoding' => '', 'db_encoding' => '',

View File

@@ -252,7 +252,7 @@ if ($is_secure) {
define('DB_CONFIG_NAME', $SITE_CONFIG[HOST_NAME]['db_host']); define('DB_CONFIG_NAME', $SITE_CONFIG[HOST_NAME]['db_host']);
define('DB_CONFIG', $DB_CONFIG[DB_CONFIG_NAME] ?? []); define('DB_CONFIG', $DB_CONFIG[DB_CONFIG_NAME] ?? []);
// because we can't change constant, but we want to for db debug flag // because we can't change constant, but we want to for db debug flag
$GLOBALS['DB_CONFIG'] = DB_CONFIG; $GLOBALS['DB_CONFIG_SET'] = DB_CONFIG;
// define('DB_CONFIG_TARGET', SITE_CONFIG[$HOST_NAME]['db_host_target']); // define('DB_CONFIG_TARGET', SITE_CONFIG[$HOST_NAME]['db_host_target']);
// define('DB_CONFIG_OTHER', SITE_CONFIG[$HOST_NAME]['db_host_other']); // define('DB_CONFIG_OTHER', SITE_CONFIG[$HOST_NAME]['db_host_other']);
// override for login and global schemas // override for login and global schemas

View File

@@ -2580,9 +2580,9 @@ class IO
// loop through the write array and each field to build the query // loop through the write array and each field to build the query
foreach ($write_array as $field) { foreach ($write_array as $field) {
if ( if (
(empty($primary_key['value']) || (
(!empty($primary_key['value']) && empty($primary_key['value']) ||
!in_array($field, $not_write_update_array)) !in_array($field, $not_write_update_array)
) && ) &&
!in_array($field, $not_write_array) !in_array($field, $not_write_array)
) { ) {
@@ -2963,7 +2963,7 @@ class IO
* Either as single array level for single insert * Either as single array level for single insert
* Or nested array for multiple insert values * Or nested array for multiple insert values
* *
* If key was set only returns tghose values directly or as array * If key was set only returns those values directly or as array
* *
* On multiple insert return the position for which to return can be set too * On multiple insert return the position for which to return can be set too
* *
@@ -2978,7 +2978,7 @@ class IO
// return as is if key is null // return as is if key is null
if ($key === null) { if ($key === null) {
if (count($this->insert_id_arr) == 1) { if (count($this->insert_id_arr) == 1) {
// return as nul if not found // return as null if not found
return $this->insert_id_arr[0] ?? null; return $this->insert_id_arr[0] ?? null;
} else { } else {
return $this->insert_id_arr; return $this->insert_id_arr;

View File

@@ -173,7 +173,7 @@ class Logging
// can be overridden with basicSetLogFileId later // can be overridden with basicSetLogFileId later
if (!empty($this->options['file_id'])) { if (!empty($this->options['file_id'])) {
$this->setLogId($this->options['file_id'] ?? ''); $this->setLogId($this->options['file_id']);
} elseif (!empty($GLOBALS['LOG_FILE_ID'])) { } elseif (!empty($GLOBALS['LOG_FILE_ID'])) {
// legacy flow, should be removed and only set via options // legacy flow, should be removed and only set via options
$this->setLogId($GLOBALS['LOG_FILE_ID']); $this->setLogId($GLOBALS['LOG_FILE_ID']);

View File

@@ -423,7 +423,7 @@ class SmartyExtend extends \Smarty
$this->DATA['ADMIN'] = $cms->acl['admin'] ?? 0; $this->DATA['ADMIN'] = $cms->acl['admin'] ?? 0;
// top menu // top menu
$this->DATA['nav_menu'] = $cms->adbTopMenu(); $this->DATA['nav_menu'] = $cms->adbTopMenu();
$this->DATA['nav_menu_count'] = is_array($this->DATA['nav_menu']) ? count($this->DATA['nav_menu']) : 0; $this->DATA['nav_menu_count'] = count($this->DATA['nav_menu']);
// messages = ['msg' =>, 'class' => 'error/warning/...'] // messages = ['msg' =>, 'class' => 'error/warning/...']
$this->DATA['messages'] = $cms->messages; $this->DATA['messages'] = $cms->messages;
} else { /** @phpstan-ignore-line Because I assume object for phpstan */ } else { /** @phpstan-ignore-line Because I assume object for phpstan */