From a25c2c8249592c2e4964d98d32a0747329d3d112 Mon Sep 17 00:00:00 2001 From: Pieter Hoste Date: Thu, 25 Feb 2021 12:31:12 +0100 Subject: [PATCH] Restore UNIQUE_CHECKS mysql variable to its original value when done with changing the database structure. This prevents potentially inserting duplicated values while manipulating data in the setup:upgrade command. --- .../Framework/Setup/Declaration/Schema/OperationsExecutor.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Setup/Declaration/Schema/OperationsExecutor.php b/lib/internal/Magento/Framework/Setup/Declaration/Schema/OperationsExecutor.php index ed1baff1d3323..9c3c5b8a5b15d 100644 --- a/lib/internal/Magento/Framework/Setup/Declaration/Schema/OperationsExecutor.php +++ b/lib/internal/Magento/Framework/Setup/Declaration/Schema/OperationsExecutor.php @@ -135,7 +135,7 @@ private function startSetupForAllConnections() $this->resourceConnection->getConnection($resource) ->startSetup(); $this->resourceConnection->getConnection($resource) - ->query('SET UNIQUE_CHECKS=0'); + ->query('SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0'); } } @@ -150,6 +150,8 @@ private function endSetupForAllConnections() foreach ($this->sharding->getResources() as $resource) { $this->resourceConnection->getConnection($resource) ->endSetup(); + $this->resourceConnection->getConnection($resource) + ->query('SET UNIQUE_CHECKS=IF(@OLD_UNIQUE_CHECKS=0, 0, 1)'); } }