From aa6d00b4b5a6e95f2bca7525d6deb285af1f3ff5 Mon Sep 17 00:00:00 2001 From: Tobias Graml Date: Mon, 13 Nov 2023 11:28:59 +0100 Subject: [PATCH] Allow null for language and sales channel IDs --- .../Migration1699534500ConfigTable.php | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Migration/Migration1699534500ConfigTable.php b/src/Migration/Migration1699534500ConfigTable.php index a63067a8..e5955c16 100644 --- a/src/Migration/Migration1699534500ConfigTable.php +++ b/src/Migration/Migration1699534500ConfigTable.php @@ -24,8 +24,8 @@ public function update(Connection $connection): void `id` binary(16) NOT NULL, `configuration_key` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, `configuration_value` json NOT NULL, - `sales_channel_id` binary(16) NOT NULL, - `language_id` binary(16) NOT NULL, + `sales_channel_id` binary(16), + `language_id` binary(16), `created_at` datetime(3) NOT NULL, `updated_at` datetime(3) DEFAULT NULL, PRIMARY KEY (`id`), @@ -62,21 +62,21 @@ private function insertPreviousConfigurationIfExists(Connection $connection): vo foreach ($configs as $config) { $salesChannelId = $config['sales_channel_id']; - if (!$salesChannelId) { - $salesChannelId = $this->getDefaultSalesChannelId($connection); - } - - $sql = 'SELECT LOWER(HEX(`language_id`)) AS `language_id` FROM `sales_channel` WHERE `id` = UNHEX(?)'; - $languageId = $connection->fetchOne($sql, [$salesChannelId]); + $languageId = null; - if (!$languageId) { - continue; + if ($salesChannelId) { + $sql = 'SELECT LOWER(HEX(`language_id`)) AS `language_id` FROM `sales_channel` WHERE `id` = UNHEX(?)'; + $languageId = $connection->fetchOne($sql, [$salesChannelId]); } $data = $config; $data['id'] = Uuid::fromHexToBytes($config['id']); - $data['language_id'] = Uuid::fromHexToBytes($languageId); - $data['sales_channel_id'] = Uuid::fromHexToBytes($salesChannelId); + $data['language_id'] = $languageId + ? Uuid::fromHexToBytes($languageId) + : null; + $data['sales_channel_id'] = $salesChannelId + ? Uuid::fromHexToBytes($salesChannelId) + : null; try { $connection->insert('nosto_integration_config', $data); } catch (Exception $exception) {