Files
interview-demo-code/backend/src/database/migrations/20260101000000_migrate_from_legacy_settings.php
Nikita Kiselev 01458e3b4c
Some checks failed
Telegram Mini App Shop Builder / Compute version metadata (push) Has been cancelled
Telegram Mini App Shop Builder / Run Frontend tests (push) Has been cancelled
Telegram Mini App Shop Builder / Run Backend tests (push) Has been cancelled
Telegram Mini App Shop Builder / Run PHP_CodeSniffer (push) Has been cancelled
Telegram Mini App Shop Builder / Build module. (push) Has been cancelled
Telegram Mini App Shop Builder / release (push) Has been cancelled
Squashed commit message
2026-03-11 22:33:34 +03:00

75 lines
3.5 KiB
PHP
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
use Acme\ECommerceFramework\Migrations\Migration;
use Acme\ECommerceFramework\ECommerce\Decorators\OcRegistryDecorator;
use Acme\ECommerceFramework\Support\Arr;
return new class extends Migration {
public function up(): void
{
$ecommerce = $this->app->get(OcRegistryDecorator::class);
$ecommerce->load->model('setting/setting');
$legacySettings = $ecommerce->model_setting_setting->getSetting('module_tgshop');
if (! $legacySettings) {
return;
}
$newSettings = $ecommerce->model_setting_setting->getSetting('module_acmeshop');
static $mapLegacyToNewSettings = [
'module_tgshop_app_icon' => 'app.app_icon',
'module_tgshop_theme_light' => 'app.theme_light',
'module_tgshop_bot_token' => 'telegram.bot_token',
'module_tgshop_status' => 'app.app_enabled',
'module_tgshop_app_name' => 'app.app_name',
'module_tgshop_theme_dark' => 'app.theme_dark',
'module_tgshop_debug' => 'app.app_debug',
'module_tgshop_chat_id' => 'telegram.chat_id',
'module_tgshop_text_order_created_success' => 'texts.text_order_created_success',
'module_tgshop_enable_store' => 'store.enable_store',
'module_tgshop_feature_vouchers' => 'store.feature_vouchers',
'module_tgshop_order_default_status_id' => 'orders.order_default_status_id',
'module_tgshop_feature_coupons' => 'store.feature_coupons',
'module_tgshop_text_no_more_products' => 'texts.text_no_more_products',
'module_tgshop_text_empty_cart' => 'texts.text_empty_cart',
];
if (! $newSettings) {
$data = [];
foreach ($mapLegacyToNewSettings as $key => $value) {
if (array_key_exists($key, $legacySettings)) {
if ($key === 'module_tgshop_status') {
$newValue = filter_var($legacySettings[$key], FILTER_VALIDATE_BOOLEAN);
} elseif ($key === 'module_tgshop_debug') {
$newValue = filter_var($legacySettings[$key], FILTER_VALIDATE_BOOLEAN);
} elseif ($key === 'module_tgshop_chat_id') {
$newValue = (int) $legacySettings[$key];
} elseif ($key === 'module_tgshop_enable_store') {
$newValue = filter_var($legacySettings[$key], FILTER_VALIDATE_BOOLEAN);
} elseif ($key === 'module_tgshop_order_default_status_id') {
$newValue = (int) $legacySettings[$key];
} elseif ($key === 'module_tgshop_feature_vouchers') {
$newValue = filter_var($legacySettings[$key], FILTER_VALIDATE_BOOLEAN);
} elseif ($key === 'module_tgshop_feature_coupons') {
$newValue = filter_var($legacySettings[$key], FILTER_VALIDATE_BOOLEAN);
} else {
$newValue = $legacySettings[$key];
}
Arr::set($data, $value, $newValue);
}
}
$ecommerce->model_setting_setting->editSetting('module_acmeshop', [
'module_acmeshop_settings' => $data,
]);
$this->logger->info('Выполнено обновление настроек с 1й версии модуля.');
}
$ecommerce->model_setting_setting->deleteSetting('module_tgshop');
}
};