mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-04-04 15:13:40 -04:00
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.
This commit is contained in:
@@ -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
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user