Skip to content

Commit

Permalink
Allow custom mysql flags for db exec command
Browse files Browse the repository at this point in the history
See #548
  • Loading branch information
shadyvb committed Nov 29, 2022
1 parent 6e87c9e commit 836143e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions inc/composer/class-command.php
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,11 @@ protected function db( InputInterface $input, OutputInterface $output ) {

break;
case 'exec':
$query = $input->getArgument( 'options' )[1] ?? null;
$options = $input->getArgument( 'options' ) ?? [];
array_shift( $options ); // remove the subcommand, we don't need it
$query = array_pop( $options ) ?: null; // the query is always the last option
$args = count( $options ) > 1 ? implode( ' ', $options ) : ''; // implode all optional options

if ( empty( $query ) ) {
$output->writeln( '<error>No query specified: pass a query via `db exec -- "sql query..."`</error>' );
break;
Expand All @@ -688,7 +692,7 @@ protected function db( InputInterface $input, OutputInterface $output ) {
$query = "$query;";
}
// phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled
passthru( "$base_command mysql --database=wordpress --user=root -e \"$query\"", $return_val );
passthru( "$base_command mysql --database=wordpress --user=root $args -e \"$query\"", $return_val );
break;
case null:
// phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled
Expand Down

0 comments on commit 836143e

Please sign in to comment.