6
6
7
7
namespace Magento \Framework \Setup \Declaration \Schema \Db ;
8
8
9
- use Magento \Framework \DB \Adapter \ConnectionException ;
10
- use Magento \Framework \DB \Adapter \SqlVersionProvider ;
9
+ use Magento \Framework \App \ResourceConnection ;
11
10
use Magento \Framework \Setup \Declaration \Schema \Dto \ElementInterface ;
12
11
13
12
/**
@@ -21,20 +20,25 @@ class DefinitionAggregator implements DbDefinitionProcessorInterface
21
20
private $ definitionProcessors ;
22
21
23
22
/**
24
- * @var SqlVersionProvider
23
+ * @var ResourceConnection
25
24
*/
26
- private $ sqlVersionProvider ;
25
+ private $ resourceConnection ;
27
26
28
27
/**
29
- * @param SqlVersionProvider $sqlVersionProvider
28
+ * @var string
29
+ */
30
+ private $ dbVersion ;
31
+
32
+ /**
33
+ * @param ResourceConnection $resourceConnection
30
34
* @param DbDefinitionProcessorInterface[] $definitionProcessors
31
35
*/
32
36
public function __construct (
33
- SqlVersionProvider $ sqlVersionProvider ,
37
+ ResourceConnection $ resourceConnection ,
34
38
array $ definitionProcessors
35
39
) {
36
40
$ this ->definitionProcessors = $ definitionProcessors ;
37
- $ this ->sqlVersionProvider = $ sqlVersionProvider ;
41
+ $ this ->resourceConnection = $ resourceConnection ;
38
42
}
39
43
40
44
/**
@@ -73,6 +77,21 @@ public function fromDefinition(array $data)
73
77
return $ definitionProcessor ->fromDefinition ($ data );
74
78
}
75
79
80
+ /**
81
+ * Get DB version
82
+ *
83
+ * @return string
84
+ */
85
+ private function getDatabaseVersion (): string
86
+ {
87
+ if (!$ this ->dbVersion ) {
88
+ $ this ->dbVersion = $ this ->resourceConnection ->getConnection ('default ' )
89
+ ->fetchPairs ("SHOW variables LIKE 'version' " )['version ' ];
90
+ }
91
+
92
+ return $ this ->dbVersion ;
93
+ }
94
+
76
95
/**
77
96
* Processes `$value` to be compatible with MySQL.
78
97
*
@@ -88,7 +107,7 @@ protected function processDefaultValue(array $data)
88
107
if ($ defaultValue === "'NULL' " ) {
89
108
return "NULL " ;
90
109
}
91
- if ($ defaultValue === "NULL " && $ this ->isMariaDbSqlConnection () ) {
110
+ if ($ defaultValue === "NULL " && strpos ( $ this ->getDatabaseVersion (), ' MariaDB ' ) !== false ) {
92
111
return null ;
93
112
}
94
113
/*
@@ -108,18 +127,4 @@ protected function processDefaultValue(array $data)
108
127
109
128
return $ defaultValue ;
110
129
}
111
-
112
- /**
113
- * Checks if MariaDB used as SQL engine
114
- *
115
- * @return bool
116
- * @throws ConnectionException
117
- */
118
- private function isMariaDbSqlConnection (): bool
119
- {
120
- return strpos (
121
- $ this ->sqlVersionProvider ->getSqlVersion (),
122
- SqlVersionProvider::MARIA_DB_10_VERSION
123
- ) === 0 ;
124
- }
125
130
}
0 commit comments