Skip to content

Commit

Permalink
feat: add --skip-ssl option for database:import command
Browse files Browse the repository at this point in the history
  • Loading branch information
carlalexander committed Jun 28, 2024
1 parent 1a51519 commit 07d4c80
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/Command/Database/ImportDatabaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ protected function configure()
->addOption('server', null, InputOption::VALUE_REQUIRED, 'The ID or name of the database server to import a database to')
->addOption('user', null, InputOption::VALUE_REQUIRED, 'The user used to connect to the database server')
->addOption('password', null, InputOption::VALUE_REQUIRED, 'The password of the user connecting to the database server')
->addOption('force', 'f', InputOption::VALUE_NONE, 'Force the import even if there are SQL errors');
->addOption('force', 'f', InputOption::VALUE_NONE, 'Force the import even if there are SQL errors')
->addOption('skip-ssl', null, InputOption::VALUE_NONE, 'Disable SSL for the connection to the database server');
}

/**
Expand Down Expand Up @@ -100,7 +101,7 @@ protected function perform(Input $input, Output $output)

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

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

if ($tunnel instanceof Process) {
$tunnel->stop();
Expand Down
14 changes: 12 additions & 2 deletions src/Tool/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,23 @@ public static function export(string $filename, string $host, string $port, stri
/**
* Import a MySQL database.
*/
public static function import(string $filename, string $host, string $port, string $user, string $password, string $name, bool $force = false)
public static function import(string $filename, string $host, string $port, string $user, string $password, string $name, bool $force = false, bool $skipSsl = false)
{
if (!self::isMySqlInstalledGlobally()) {
throw new CommandLineToolNotDetectedException('MySQL');
}

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));
$options = [];

if ($force) {
$options[] = '--force';
}

if ($skipSsl) {
$options[] = '--skip-ssl';
}

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));
}

/**
Expand Down

0 comments on commit 07d4c80

Please sign in to comment.