mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-07-26 06:37:02 -04:00
* refactor(login): rename methods and keys to camelCase, add initialization keys - Rename snake_case methods to camelCase in MY_Migration and callers: is_latest() → isLatest(), migrate_to_ci4() → migrateToCI4(), get_latest_migration() → getLatestMigration(), get_current_version() → getCurrentVersion() - Rename snake_case array keys to camelCase in Login controller: has_errors → hasErrors, is_new_install → isNewInstall, is_latest → isLatest, latest_version → latestVersion, gcaptcha_enabled → gcaptchaEnabled - Add initialization_required, initialization_message, initialize keys to all language files to support new install flow messaging Signed-off-by: Travis Garrison <travis@chiraqbookstore.com> * refactor(login): move auth validation before migration, reorder language keys alphabetically - Validate credentials with login_check rule before attempting migration - Return 401 with invalid credentials message on validation failure - Alphabetically reorder and align language file keys across all locales - Add new migration status keys: migrating_database, migration_complete, migration_complete_login, migration_complete_migrate - Remove deprecated keys: migration_needed, migration_initializing, migration_running, migration_required Signed-off-by: Travis Garrison <travis@chiraqbookstore.com> --------- Signed-off-by: Travis Garrison <travis@chiraqbookstore.com> Co-authored-by: Travis Garrison <travis@chiraqbookstore.com>
68 lines
1.7 KiB
PHP
68 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Events;
|
|
|
|
use App\Libraries\MY_Migration;
|
|
use App\Models\Appconfig;
|
|
use CodeIgniter\Session\Handlers\DatabaseHandler;
|
|
use CodeIgniter\Session\Handlers\FileHandler;
|
|
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;
|
|
|
|
public function load_config(): void
|
|
{
|
|
$migration_config = config('Migrations');
|
|
$migration = new MY_Migration($migration_config);
|
|
|
|
$this->session = session();
|
|
|
|
$config = config(OSPOS::class);
|
|
|
|
if (!$migration->isLatest()) {
|
|
$this->session->destroy();
|
|
}
|
|
|
|
$this->setDefaultLanguage($config);
|
|
|
|
$language = Services::language();
|
|
$language->setLocale(current_language_code());
|
|
|
|
date_default_timezone_set($config->settings['timezone'] ?? ini_get('date.timezone'));
|
|
|
|
bcscale(max(2, totals_decimals() + tax_decimals()));
|
|
}
|
|
|
|
private function setDefaultLanguage(OSPOS $config): void
|
|
{
|
|
$languageCode = $config->settings['language_code'] ?? null;
|
|
|
|
if (empty($config->settings) || $languageCode === null) {
|
|
$config->settings['language'] = 'english';
|
|
$config->settings['language_code'] = 'en';
|
|
return;
|
|
}
|
|
|
|
if (!$this->languageExists($languageCode)) {
|
|
$config->settings['language'] = 'english';
|
|
$config->settings['language_code'] = 'en';
|
|
}
|
|
}
|
|
|
|
private function languageExists(string $languageCode): bool
|
|
{
|
|
return file_exists(APPPATH . 'Language/' . $languageCode);
|
|
}
|
|
}
|