From 3890f50e77b0cefce253df5201d5c314c0d73c5d Mon Sep 17 00:00:00 2001 From: objecttothis Date: Thu, 30 Nov 2023 17:08:07 +0400 Subject: [PATCH] Corrected Problems - Added types to config. - Added formatting to DB_log messages - Corrected bug referencing non-existent OSPOS config property timezone - set the date_default_timezone to the php-specified default when timezone is not set in the app rather than 'America/New York' - Added TODO indicating problem. --- app/Config/App.php | 12 ++++++------ app/Events/Db_log.php | 21 ++++++++++++--------- app/Events/Load_config.php | 4 +++- app/Models/Attribute.php | 5 ++++- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/app/Config/App.php b/app/Config/App.php index 61286d482..7cb844713 100644 --- a/app/Config/App.php +++ b/app/Config/App.php @@ -12,35 +12,35 @@ class App extends BaseConfig * * @var string */ - public $application_version = '3.4.0-dev'; + public string $application_version = '3.4.0-dev'; /** * This is the commit hash for the version you are currently using. * * @var string */ - public $commit_sha1 = 'dev'; + public string $commit_sha1 = 'dev'; /** * Logs are stored in writable/logs * * @var bool */ - public $db_log_enabled = false; + public bool $db_log_enabled = false; /** - * DB Query Log only long running queries + * DB Query Log only long-running queries * * @var bool */ - public $db_log_only_long = false; + public bool $db_log_only_long = false; /** * Defines whether to require/reroute to HTTPS * * @var bool */ - public $https_on; //Set in the constructor + public bool $https_on; //Set in the constructor /** * -------------------------------------------------------------------------- diff --git a/app/Events/Db_log.php b/app/Events/Db_log.php index 3a5a20598..70b131572 100644 --- a/app/Events/Db_log.php +++ b/app/Events/Db_log.php @@ -6,15 +6,17 @@ use Config\Database; class Db_log { + private object $config; + public function db_log_queries(): void { - $config = config('App'); - // check if database logging is enabled (see config/config.php) - if($config->db_log_enabled) + $this->config = config('App'); + + if($this->config->db_log_enabled) { $filepath = WRITEPATH . 'logs/Query-log-' . date('Y-m-d') . '.log'; $handle = fopen($filepath, "a+"); - $message = $this->generate_message($config); + $message = $this->generate_message(); if(strlen($message) > 0) { @@ -26,16 +28,17 @@ class Db_log } } - private function generate_message($config): string + private function generate_message(): string { $db = Database::connect(); $last_query = $db->getLastQuery(); $affected_rows = $db->affectedRows(); $execution_time = $this->convert_time($last_query->getDuration()); - $message = $last_query->getQuery() - . " \n Affected rows: $affected_rows" - . " \n Execution Time: " . $execution_time['time'] . ' ' . $execution_time['unit']; + $message = '*** Query: ' . date('Y-m-d H:i:s T') . ' *******************' + . "\n" . $last_query->getQuery() + . "\n Affected rows: $affected_rows" + . "\n Execution Time: " . $execution_time['time'] . ' ' . $execution_time['unit']; $long_query = ($execution_time['unit'] === 's') && ($execution_time['time'] > 0.5); if($long_query) @@ -43,7 +46,7 @@ class Db_log $message .= ' [LONG RUNNING QUERY]'; } - return $config->db_log_only_long && !$long_query ? '' : $message; + return $this->config->db_log_only_long && !$long_query ? '' : $message; } private function convert_time(float $time): array diff --git a/app/Events/Load_config.php b/app/Events/Load_config.php index 8c36a74ff..8b5b77f49 100644 --- a/app/Events/Load_config.php +++ b/app/Events/Load_config.php @@ -51,8 +51,10 @@ class Load_config $language = Services::language(); $language->setLocale($config->settings['language_code']); + log_message('error', '$config->timezone set to: ' . $config->settings['timezone']); + log_message('error', 'PHP date.timezone set to: ' . ini_get('date.timezone')); //Time Zone - date_default_timezone_set($config->timezone ?? 'America/New_York'); + date_default_timezone_set($config->settings['timezone'] ?? ini_get('date.timezone')); bcscale(max(2, totals_decimals() + tax_decimals())); } diff --git a/app/Models/Attribute.php b/app/Models/Attribute.php index 63e698153..55bbff499 100644 --- a/app/Models/Attribute.php +++ b/app/Models/Attribute.php @@ -81,7 +81,7 @@ class Attribute extends Model $builder->where('definition_id', $definition_id); } - return ($builder->get()->getNumRows() > 0); + return ($builder->get()->getNumRows() > 0); //TODO: This is returning a result of 1 on dropdown } /* @@ -552,6 +552,7 @@ class Attribute extends Model */ public function save_link(int $item_id, int $definition_id, int $attribute_id): bool { + log_message('error', "saving link: definition - $definition_id, item - $item_id, attribute_id - $attribute_id" ); $this->db->transStart(); $builder = $this->db->table('attribute_links'); @@ -574,6 +575,7 @@ class Attribute extends Model $builder->insert($data); } + log_message('error', 'save_link result: ' . $this->db->transStatus()); $this->db->transComplete(); return $this->db->transStatus(); @@ -819,6 +821,7 @@ class Attribute extends Model $builder->where('attribute_id', $attribute_id); $builder->update(); } + log_message('error', "saving value: $attribute_value"); log_message('error', 'save_value result: ' . $this->db->transStatus()); $this->db->transComplete();