Skip to content

Commit 07d4c80

Browse files
committed
feat: add --skip-ssl option for database:import command
1 parent 1a51519 commit 07d4c80

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

src/Command/Database/ImportDatabaseCommand.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ protected function configure()
6565
->addOption('server', null, InputOption::VALUE_REQUIRED, 'The ID or name of the database server to import a database to')
6666
->addOption('user', null, InputOption::VALUE_REQUIRED, 'The user used to connect to the database server')
6767
->addOption('password', null, InputOption::VALUE_REQUIRED, 'The password of the user connecting to the database server')
68-
->addOption('force', 'f', InputOption::VALUE_NONE, 'Force the import even if there are SQL errors');
68+
->addOption('force', 'f', InputOption::VALUE_NONE, 'Force the import even if there are SQL errors')
69+
->addOption('skip-ssl', null, InputOption::VALUE_NONE, 'Disable SSL for the connection to the database server');
6970
}
7071

7172
/**
@@ -100,7 +101,7 @@ protected function perform(Input $input, Output $output)
100101

101102
$output->infoWithDelayWarning(sprintf('Importing "<comment>%s</comment>" to the "<comment>%s</comment>" database', $file, $name));
102103

103-
Mysql::import($file, $host, $port, $user, $password, $name, $input->getBooleanOption('force'));
104+
Mysql::import($file, $host, $port, $user, $password, $name, $input->getBooleanOption('force'), $input->getBooleanOption('skip-ssl'));
104105

105106
if ($tunnel instanceof Process) {
106107
$tunnel->stop();

src/Tool/Mysql.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,23 @@ public static function export(string $filename, string $host, string $port, stri
3333
/**
3434
* Import a MySQL database.
3535
*/
36-
public static function import(string $filename, string $host, string $port, string $user, string $password, string $name, bool $force = false)
36+
public static function import(string $filename, string $host, string $port, string $user, string $password, string $name, bool $force = false, bool $skipSsl = false)
3737
{
3838
if (!self::isMySqlInstalledGlobally()) {
3939
throw new CommandLineToolNotDetectedException('MySQL');
4040
}
4141

42-
self::runCommand(sprintf('%s %s | mysql %s --protocol=TCP --host=%s --port=%s --user=%s --password=%s %s', str_ends_with($filename, '.sql.gz') ? 'gunzip <' : 'cat', $filename, $force ? '--force' : '', $host, $port, $user, $password, $name));
42+
$options = [];
43+
44+
if ($force) {
45+
$options[] = '--force';
46+
}
47+
48+
if ($skipSsl) {
49+
$options[] = '--skip-ssl';
50+
}
51+
52+
self::runCommand(sprintf('%s %s | mysql %s --protocol=TCP --host=%s --port=%s --user=%s --password=%s %s', str_ends_with($filename, '.sql.gz') ? 'gunzip <' : 'cat', $filename, implode(' ', $options), $host, $port, $user, $password, $name));
4353
}
4454

4555
/**

0 commit comments

Comments
 (0)