Files
opensourcepos/app/Events/Load_config.php
objecttothis 3890f50e77 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.
2024-06-15 17:19:15 +02:00

62 lines
1.5 KiB
PHP

<?php
namespace App\Events;
use App\Libraries\MY_Migration;
use App\Models\Appconfig;
use CodeIgniter\Session\Session;
use Config\OSPOS;
use Config\Services;
/**
* @property my_migration migration;
* @property session session;
* @property appconfig appconfig;
* @property mixed $migration_config
* @property mixed $config
*/
class Load_config
{
public Session $session;
/**
* Loads configuration from database into App CI config and then applies those settings
*/
public function load_config(): void
{
//Migrations
$migration_config = config('Migrations');
$migration = new MY_Migration($migration_config);
$this->session = session();
//Database Configuration
$config = config(OSPOS::class);
if (!$migration->is_latest())
{
$this->session->destroy();
}
//Language
helper('locale');
$language_exists = file_exists('../app/Language/' . current_language_code());
if(current_language_code() == null || current_language() == null || !$language_exists) //TODO: current_language() is undefined
{
$config->language = 'english';
$config->language_code = 'en-US';
}
$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->settings['timezone'] ?? ini_get('date.timezone'));
bcscale(max(2, totals_decimals() + tax_decimals()));
}
}