From 836143e8a695f8bb6c5a0c111098f3613708968f Mon Sep 17 00:00:00 2001 From: Shady Sharaf Date: Tue, 29 Nov 2022 18:00:40 +0200 Subject: [PATCH 1/4] 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 From 45ea032b5f4f35d4c26c53da03d4ef05a5edf473 Mon Sep 17 00:00:00 2001 From: Shady Sharaf Date: Tue, 29 Nov 2022 18:02:51 +0200 Subject: [PATCH 2/4] Update docs on mysql optional custom args in db exec --- inc/composer/class-command.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/inc/composer/class-command.php b/inc/composer/class-command.php index cbad9200..537df78d 100644 --- a/inc/composer/class-command.php +++ b/inc/composer/class-command.php @@ -71,10 +71,10 @@ protected function configure() { Open a shell: shell Database commands: - db Log into MySQL on the Database server - db sequel Generates an SPF file for Sequel Pro - db info Prints out Database connection details - db exec -- "" Run and output the result of a SQL query. + db Log into MySQL on the Database server + db sequel Generates an SPF file for Sequel Pro + db info Prints out Database connection details + db exec -- "" Run and output the result of a SQL query, with options mysql args. SSL commands: ssl Show status on generated SSL certificates ssl install Installs and trusts Root Certificate Authority From c712ab9a61923ffabfceff4a4706fca5d3fc26b6 Mon Sep 17 00:00:00 2001 From: Shady Sharaf Date: Tue, 29 Nov 2022 18:14:06 +0200 Subject: [PATCH 3/4] Fix comments to be on their own lines with ending commas. --- inc/composer/class-command.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/inc/composer/class-command.php b/inc/composer/class-command.php index 537df78d..e57b45aa 100644 --- a/inc/composer/class-command.php +++ b/inc/composer/class-command.php @@ -680,9 +680,12 @@ protected function db( InputInterface $input, OutputInterface $output ) { break; case 'exec': $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 + // Remove the subcommand, we don't need it. + array_shift( $options ); + // The query is always the last option. + $query = array_pop( $options ) ?: null; + // Implode all optional options. + $args = count( $options ) > 1 ? implode( ' ', $options ) : ''; if ( empty( $query ) ) { $output->writeln( 'No query specified: pass a query via `db exec -- "sql query..."`' ); From 93ba1f9ce6472ed1f1437468eed52ecf080c325d Mon Sep 17 00:00:00 2001 From: Shady Sharaf Date: Wed, 21 Dec 2022 10:50:21 +0200 Subject: [PATCH 4/4] Fix docblock and function arg count check. Co-authored-by: Robert O'Rourke --- inc/composer/class-command.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inc/composer/class-command.php b/inc/composer/class-command.php index e57b45aa..ba5e82eb 100644 --- a/inc/composer/class-command.php +++ b/inc/composer/class-command.php @@ -74,7 +74,7 @@ protected function configure() { db Log into MySQL on the Database server db sequel Generates an SPF file for Sequel Pro db info Prints out Database connection details - db exec -- "" Run and output the result of a SQL query, with options mysql args. + db exec -- "" Run and output the result of a SQL query, with optional mysql args. SSL commands: ssl Show status on generated SSL certificates ssl install Installs and trusts Root Certificate Authority @@ -685,7 +685,7 @@ protected function db( InputInterface $input, OutputInterface $output ) { // The query is always the last option. $query = array_pop( $options ) ?: null; // Implode all optional options. - $args = count( $options ) > 1 ? implode( ' ', $options ) : ''; + $args = count( $options ) > 0 ? implode( ' ', $options ) : ''; if ( empty( $query ) ) { $output->writeln( 'No query specified: pass a query via `db exec -- "sql query..."`' );