@@ -16,17 +16,17 @@ class Mysql extends \Magento\TestFramework\Db\AbstractDb
16
16
/**
17
17
* Mysql default Port.
18
18
*/
19
- protected const DEFAULT_PORT = 3306 ;
19
+ public const DEFAULT_PORT = 3306 ;
20
20
21
21
/**
22
22
* MariaDB minimum version.
23
23
*/
24
- protected const MARIADB_MIN_VERSION = '11.4. ' ;
24
+ public const MARIADB_MIN_VERSION = '11.4. ' ;
25
25
26
26
/**
27
27
* Name of configuration file.
28
28
*/
29
- protected const DEFAULTS_EXTRA_FILE_NAME = 'defaults_extra.cnf ' ;
29
+ public const DEFAULTS_EXTRA_FILE_NAME = 'defaults_extra.cnf ' ;
30
30
31
31
/**
32
32
* MySQL DB dump file
@@ -92,10 +92,8 @@ public function __construct($host, $user, $password, $schema, $varPath, \Magento
92
92
*/
93
93
public function cleanup ()
94
94
{
95
- $ dbCommand = 'mysql ' ;
96
- if ($ this ->isMariaDB ()) {
97
- $ dbCommand = 'mariadb ' ;
98
- }
95
+ $ dbCommand = $ this ->getDbCommand ();
96
+
99
97
$ this ->ensureDefaultsExtraFile ();
100
98
$ this ->_shell ->execute (
101
99
'%s --defaults-file=%s --host=%s --port=%s %s -e %s ' ,
@@ -135,14 +133,10 @@ public function isDbDumpExists()
135
133
*/
136
134
public function storeDbDump ()
137
135
{
138
- $ dumpCommand = ' mysqldump ' ;
136
+ $ dumpCommand = $ this -> getDbDumpCommand () ;
139
137
$ this ->ensureDefaultsExtraFile ();
140
138
$ additionalArguments = [];
141
139
142
- if ($ this ->isMariaDB ()) {
143
- $ dumpCommand = 'mariadb-dump ' ;
144
- }
145
-
146
140
if ($ this ->isMysqlDumpVersion8 ()) {
147
141
$ additionalArguments [] = '--column-statistics=0 ' ;
148
142
}
@@ -184,10 +178,7 @@ public function restoreFromDbDump()
184
178
throw new \LogicException ("DB dump file does not exist: " . $ this ->getSetupDbDumpFilename ());
185
179
}
186
180
187
- $ dbCommand = 'mysql ' ;
188
- if ($ this ->isMariaDB ()) {
189
- $ dbCommand = 'mariadb ' ;
190
- }
181
+ $ dbCommand = $ this ->getDbCommand ();
191
182
192
183
$ this ->_shell ->execute (
193
184
'%s --defaults-file=%s --host=%s --port=%s %s < %s ' ,
@@ -279,25 +270,45 @@ private function isUsingAuroraDb(): bool
279
270
private function isMariaDB (): bool
280
271
{
281
272
try {
282
- if (!$ this ->isMariaDB ) {
273
+ if (!isset ( $ this ->isMariaDB ) ) {
283
274
$ version = $ this ->_shell ->execute (
284
275
'mariadb-dump --version '
285
276
);
286
-
287
- $ this -> isMariaDB = ( bool ) preg_match ( ' /-MariaDB/i ' , $ version );
288
-
289
- if ( $ this -> isMariaDB ) {
290
- $ pattern = " /\s*((?:[0-9]+\.?)+)/i " ;
291
- preg_match ( $ pattern , $ version , $ matches );
292
- $ currentVersion = $ matches [ 1 ];
293
- if (! version_compare ( $ currentVersion , self :: MARIADB_MIN_VERSION , ' >= ' )) {
294
- $ this -> isMariaDB = false ;
295
- }
277
+ $ pattern = " /((?:[0-9]+\.?)+)(.*?)(mariadb)/i " ;
278
+ preg_match ( $ pattern , $ version === null ? $ version : ' ' , $ matches );
279
+ $ currentVersion = $ matches [ 1 ] ?? '' ;
280
+ $ isMariadb = isset ( $ matches [ 3 ]);
281
+ if ( $ isMariadb
282
+ && $ currentVersion
283
+ && version_compare ( $ currentVersion, self :: MARIADB_MIN_VERSION , ' >= ' )) {
284
+ $ this -> isMariaDB = true ;
285
+ } else {
286
+ $ this -> isMariaDB = false ;
296
287
}
297
288
}
298
289
} catch (LocalizedException $ e ) {
299
290
$ this ->isMariaDB = false ;
300
291
}
301
292
return $ this ->isMariaDB ;
302
293
}
294
+
295
+ /**
296
+ * Get db command mysql or mariadb
297
+ *
298
+ * @return string
299
+ */
300
+ protected function getDbCommand ()
301
+ {
302
+ return $ this ->isMariaDB () ? 'mariadb ' : 'mysql ' ;
303
+ }
304
+
305
+ /**
306
+ * Get dump command mysqldum or mariadb-dump
307
+ *
308
+ * @return string
309
+ */
310
+ protected function getDbDumpCommand ()
311
+ {
312
+ return $ this ->isMariaDB () ? 'mysqldump ' : 'mariadb-dump ' ;
313
+ }
303
314
}
0 commit comments