From 836143e8a695f8bb6c5a0c111098f3613708968f Mon Sep 17 00:00:00 2001 From: Shady Sharaf Date: Tue, 29 Nov 2022 18:00:40 +0200 Subject: [PATCH] Allow custom mysql flags for db exec command See https://github.com/humanmade/altis-local-server/issues/548 --- inc/composer/class-command.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/inc/composer/class-command.php b/inc/composer/class-command.php index eaf0ab99..cbad9200 100644 --- a/inc/composer/class-command.php +++ b/inc/composer/class-command.php @@ -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( 'No query specified: pass a query via `db exec -- "sql query..."`' ); break; @@ -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