20-02-2026

This commit is contained in:
Kevin Adametz 2026-02-20 17:55:06 +01:00
parent a8b395e20d
commit a00c42e770
252 changed files with 28785 additions and 8907 deletions

View file

@ -5,11 +5,8 @@ namespace App\Http\Controllers;
use App\Models\Setting;
use Request;
class SettingController extends Controller
{
public function __construct()
{
$this->middleware('admin');
@ -21,10 +18,10 @@ class SettingController extends Controller
$data = [
'values' => [],
];
return view('admin.settings.index', $data);
}
public function store()
{
$data = Request::all();
@ -50,7 +47,9 @@ class SettingController extends Controller
/**
* Get DHL configuration merged from database settings and .env values
* Database settings override .env values
* Priority is controlled by DHL_CONFIG_SOURCE environment variable:
* - 'database' (default): Database settings override .env values
* - 'env': Environment/Config values override database settings
*/
public function getDhlConfig()
{
@ -58,44 +57,49 @@ class SettingController extends Controller
$isTestMode = config('dhl.legacy.test_mode', false) || config('dhl.legacy.sandbox', false);
$baseUrl = $isTestMode ? config('dhl.sandbox_url') : config('dhl.base_url');
// Determine configuration priority
$useEnvPriority = config('dhl.config_source') === 'env';
return [
// API Settings
'base_url' => $isTestMode ? $baseUrl : (Setting::getContentBySlug('dhl_base_url') ?: $baseUrl),
'api_key' => Setting::getContentBySlug('dhl_api_key') ?: config('dhl.api_key'),
'username' => Setting::getContentBySlug('dhl_username') ?: config('dhl.username'),
'password' => Setting::getContentBySlug('dhl_password') ?: config('dhl.password'),
'billing_number' => Setting::getContentBySlug('dhl_billing_number') ?: config('dhl.billing_number'),
'base_url' => $isTestMode ? $baseUrl : $this->getConfigValue('dhl_base_url', $baseUrl, $useEnvPriority),
'api_key' => $this->getConfigValue('dhl_api_key', config('dhl.api_key'), $useEnvPriority),
'api_secret' => config('dhl.legacy.api_secret'), // Used by Tracking API
'username' => $this->getConfigValue('dhl_username', config('dhl.username'), $useEnvPriority),
'password' => $this->getConfigValue('dhl_password', config('dhl.password'), $useEnvPriority),
'billing_number' => $this->getConfigValue('dhl_billing_number', config('dhl.billing_number'), $useEnvPriority),
'sandbox' => config('dhl.legacy.sandbox', true), // Used by Tracking Service
'test_mode' => config('dhl.legacy.test_mode', true),
// Product Settings
'default_product' => Setting::getContentBySlug('dhl_product') ?: config('dhl.default_product'),
'label_format' => Setting::getContentBySlug('dhl_label_format') ?: config('dhl.label_format'),
'print_format' => Setting::getContentBySlug('dhl_print_format') ?: config('dhl.print_format'),
'retoure_print_format' => Setting::getContentBySlug('dhl_retoure_print_format') ?: config('dhl.retoure_print_format'),
'use_queue' => Setting::getContentBySlug('dhl_use_queue') ?: config('dhl.use_queue'),
'default_product' => $this->getConfigValue('dhl_product', config('dhl.default_product'), $useEnvPriority),
'label_format' => $this->getConfigValue('dhl_label_format', config('dhl.label_format'), $useEnvPriority),
'print_format' => $this->getConfigValue('dhl_print_format', config('dhl.print_format'), $useEnvPriority),
'retoure_print_format' => $this->getConfigValue('dhl_retoure_print_format', config('dhl.retoure_print_format'), $useEnvPriority),
'use_queue' => $this->getConfigValue('dhl_use_queue', config('dhl.use_queue'), $useEnvPriority),
// Sender Address
'sender' => [
'company' => Setting::getContentBySlug('dhl_sender_company') ?: config('dhl.sender.company'),
'name' => Setting::getContentBySlug('dhl_sender_name') ?: config('dhl.sender.name'),
'street' => Setting::getContentBySlug('dhl_sender_street') ?: config('dhl.sender.street'),
'houseNumber' => Setting::getContentBySlug('dhl_sender_house_number') ?: config('dhl.sender.houseNumber'),
'postalCode' => Setting::getContentBySlug('dhl_sender_postal_code') ?: config('dhl.sender.postalCode'),
'city' => Setting::getContentBySlug('dhl_sender_city') ?: config('dhl.sender.city'),
'country' => Setting::getContentBySlug('dhl_sender_country') ?: config('dhl.sender.country'),
'email' => Setting::getContentBySlug('dhl_sender_email') ?: config('dhl.sender.email'),
'phone' => Setting::getContentBySlug('dhl_sender_phone') ?: config('dhl.sender.phone'),
'company' => $this->getConfigValue('dhl_sender_company', config('dhl.sender.company'), $useEnvPriority),
'name' => $this->getConfigValue('dhl_sender_name', config('dhl.sender.name'), $useEnvPriority),
'street' => $this->getConfigValue('dhl_sender_street', config('dhl.sender.street'), $useEnvPriority),
'houseNumber' => $this->getConfigValue('dhl_sender_house_number', config('dhl.sender.houseNumber'), $useEnvPriority),
'postalCode' => $this->getConfigValue('dhl_sender_postal_code', config('dhl.sender.postalCode'), $useEnvPriority),
'city' => $this->getConfigValue('dhl_sender_city', config('dhl.sender.city'), $useEnvPriority),
'country' => $this->getConfigValue('dhl_sender_country', config('dhl.sender.country'), $useEnvPriority),
'email' => $this->getConfigValue('dhl_sender_email', config('dhl.sender.email'), $useEnvPriority),
'phone' => $this->getConfigValue('dhl_sender_phone', config('dhl.sender.phone'), $useEnvPriority),
],
// Account Numbers
'account_numbers' => [
'V01PAK' => Setting::getContentBySlug('dhl_account_v01pak') ?: config('dhl.account_numbers.V01PAK'),
'V62WP' => Setting::getContentBySlug('dhl_account_v62wp') ?: config('dhl.account_numbers.V62WP'),
'V53PAK' => Setting::getContentBySlug('dhl_account_v53pak') ?: config('dhl.account_numbers.V53PAK'),
'V07PAK' => Setting::getContentBySlug('dhl_account_v07pak') ?: config('dhl.account_numbers.V07PAK'),
'V01PAK' => $this->getConfigValue('dhl_account_v01pak', config('dhl.account_numbers.V01PAK'), $useEnvPriority),
'V62WP' => $this->getConfigValue('dhl_account_v62wp', config('dhl.account_numbers.V62WP'), $useEnvPriority),
'V53PAK' => $this->getConfigValue('dhl_account_v53pak', config('dhl.account_numbers.V53PAK'), $useEnvPriority),
'V07PAK' => $this->getConfigValue('dhl_account_v07pak', config('dhl.account_numbers.V07PAK'), $useEnvPriority),
'default' => config('dhl.account_numbers.default'),
],
// Dimensions
'dimensions' => [
'V01PAK' => config('dhl.dimensions.V01PAK'),
@ -111,6 +115,27 @@ class SettingController extends Controller
];
}
/**
* Get configuration value based on priority setting
*
* @param string $settingSlug The database setting slug
* @param mixed $configValue The config/env fallback value
* @param bool $useEnvPriority Whether to prioritize env over database
* @return mixed
*/
private function getConfigValue(string $settingSlug, $configValue, bool $useEnvPriority)
{
$dbValue = Setting::getContentBySlug($settingSlug);
if ($useEnvPriority) {
// ENV priority: Use config value if available, otherwise fall back to database
return $configValue ?: $dbValue;
} else {
// Database priority (default): Use database value if available, otherwise fall back to config
return $dbValue ?: $configValue;
}
}
/**
* Update DHL configuration cache after saving settings
*/
@ -125,7 +150,7 @@ class SettingController extends Controller
// You could add a connection test here if needed
\Log::info('DHL configuration updated successfully');
} catch (\Exception $e) {
\Log::error('DHL configuration update failed: ' . $e->getMessage());
\Log::error('DHL configuration update failed: '.$e->getMessage());
}
}
}