32
32
use Magento \Framework \Stdlib \StringUtils ;
33
33
use Zend_Db_Adapter_Exception ;
34
34
use Zend_Db_Statement_Exception ;
35
-
35
+ use Magento \ Framework \ DB \ Adapter \ SqlVersionProvider ;
36
36
// @codingStandardsIgnoreStart
37
37
38
38
/**
@@ -251,6 +251,16 @@ class Mysql extends \Zend_Db_Adapter_Pdo_Mysql implements AdapterInterface, Rese
251
251
*/
252
252
private $ parentConnections = [];
253
253
254
+ /**
255
+ * @var SqlVersionProvider
256
+ */
257
+ private $ sqlVersionProvider ;
258
+
259
+ /***
260
+ * const MYSQL_8_4_VERSION
261
+ */
262
+ public const MYSQL_8_4_VERSION = '8.4 ' ;
263
+
254
264
/**
255
265
* Constructor
256
266
*
@@ -260,21 +270,24 @@ class Mysql extends \Zend_Db_Adapter_Pdo_Mysql implements AdapterInterface, Rese
260
270
* @param SelectFactory $selectFactory
261
271
* @param array $config
262
272
* @param SerializerInterface|null $serializer
273
+ * @param SqlVersionProvider|null $sqlVersionProvider
263
274
*/
264
275
public function __construct (
265
276
StringUtils $ string ,
266
277
DateTime $ dateTime ,
267
278
LoggerInterface $ logger ,
268
279
SelectFactory $ selectFactory ,
269
280
array $ config = [],
270
- SerializerInterface $ serializer = null
281
+ SerializerInterface $ serializer = null ,
282
+ SqlVersionProvider $ sqlVersionProvider = null
271
283
) {
272
284
$ this ->pid = getmypid ();
273
285
$ this ->string = $ string ;
274
286
$ this ->dateTime = $ dateTime ;
275
287
$ this ->logger = $ logger ;
276
288
$ this ->selectFactory = $ selectFactory ;
277
289
$ this ->serializer = $ serializer ?: ObjectManager::getInstance ()->get (SerializerInterface::class);
290
+ $ this ->sqlVersionProvider = $ sqlVersionProvider ?? ObjectManager::getInstance ()->get (SqlVersionProvider::class);
278
291
$ this ->exceptionMap = [
279
292
// SQLSTATE[HY000]: General error: 2006 MySQL server has gone away
280
293
2006 => ConnectionException::class,
@@ -3069,7 +3082,9 @@ public function startSetup()
3069
3082
$ this ->rawQuery ("SET SQL_MODE='' " );
3070
3083
$ this ->rawQuery ("SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 " );
3071
3084
$ this ->rawQuery ("SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' " );
3072
- $ this ->rawQuery ("SET @@GLOBAL.RESTRICT_FK_ON_NON_STANDARD_KEY=0 " );
3085
+ if (str_contains ($ this ->sqlVersionProvider ->getSqlVersion (), self ::MYSQL_8_4_VERSION )) {
3086
+ $ this ->rawQuery ("SET @@GLOBAL.RESTRICT_FK_ON_NON_STANDARD_KEY=0 " );
3087
+ }
3073
3088
return $ this ;
3074
3089
}
3075
3090
0 commit comments