diff --git a/docs/README.md b/docs/README.md index 257473fa..d0f1fe39 100644 --- a/docs/README.md +++ b/docs/README.md @@ -104,5 +104,6 @@ Note: Altis local-server automatically collects domains names to issue the SSL c * `composer server exec -- ` - Runs any command on the PHP container. * `composer server db` - Logs into MySQL on the DB container. * `composer server db info` - Print MySQL connection details. - * `composer server db sequel` - Opens a connection to the database in [Sequel Pro](https://sequelpro.com). + * `composer server db (sequel|spf)` - Opens a connection to the database in [Sequel Pro](https://sequelpro.com) or [Sequel Ace](https://sequel-ace.com/). + * `composer server db (tableplus|tbp)` - Opens a connection to the database in [Table Plus](https://tableplus.com/). * `composer server import-uploads` - Syncs files from `content/uploads` to the S3 container. diff --git a/inc/composer/class-command.php b/inc/composer/class-command.php index cc5df932..275d82e6 100644 --- a/inc/composer/class-command.php +++ b/inc/composer/class-command.php @@ -72,7 +72,8 @@ protected function configure() { shell Database commands: db Log into MySQL on the Database server - db sequel Generates an SPF file for Sequel Pro + db (sequel|spf) Opens Sequel Pro/Sequel Ace with the database connection + db (tableplus|tbp) Opens TablePlus with the database connection db info Prints out Database connection details db exec -- "" Run and output the result of a SQL query. SSL commands: @@ -658,7 +659,9 @@ protected function db( InputInterface $input, OutputInterface $output ) { EOT; $output->write( $db_info ); break; + case 'sequel': + case 'spf': if ( php_uname( 's' ) !== 'Darwin' ) { $output->writeln( 'This command is only supported on MacOS, use composer server db info to see the database connection details.' ); return 1; @@ -676,10 +679,32 @@ protected function db( InputInterface $input, OutputInterface $output ) { exec( "open $output_file_path", $null, $return_val ); if ( $return_val !== 0 ) { - $output->writeln( 'You must have Sequel Pro (https://www.sequelpro.com) installed to use this command' ); + $output->writeln( 'You must have Sequel Pro (https://www.sequelpro.com) or Sequel Ace (https://sequel-ace.com/) installed to use this command' ); } break; + + case 'tableplus': + case 'tbp': + $connection_data = $this->get_db_connection_data(); + $url = sprintf( + 'mysql://%s:%s@%s:%s/%s', + $connection_data['MYSQL_USER'], + $connection_data['MYSQL_PASSWORD'], + $connection_data['HOST'], + $connection_data['PORT'], + $connection_data['MYSQL_DATABASE'] + ); + $url .= '?' . http_build_query( [ + 'name' => $this->get_project_subdomain(), + 'env' => 'local', + ] ); + exec( sprintf( 'open "%s"', $url ), $null, $return_val ); + if ( $return_val !== 0 ) { + $output->writeln( 'You must have TablePlus (https://tableplus.com/) installed to use this command' ); + } + break; + case 'exec': $query = $input->getArgument( 'options' )[1] ?? null; if ( empty( $query ) ) { @@ -692,10 +717,12 @@ protected function db( InputInterface $input, OutputInterface $output ) { // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled passthru( "$base_command mysql --database=wordpress --user=root -e \"$query\"", $return_val ); break; + case null: // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled passthru( "$base_command mysql --database=wordpress --user=root", $return_val ); break; + default: $output->writeln( "The subcommand $db is not recognized" ); $return_val = 1;