diff --git a/changelog.md b/changelog.md index bc9ad9e..97fafca 100644 --- a/changelog.md +++ b/changelog.md @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +# [Unreleased] - 2024-05-27 +* Fixed - Properly read changes and restart stack after using the `slic php-version set` command. + # [1.6.3] - 2024-05-10 * Added - The `playwright` command to Playwright commands in the stack. * Added - The `less` binary to the `slic` container (to correctly format wp-cli output). diff --git a/src/commands/php-version.php b/src/commands/php-version.php index bca02f9..17039ad 100644 --- a/src/commands/php-version.php +++ b/src/commands/php-version.php @@ -57,10 +57,12 @@ if ( ! $skip_rebuild ) { $confirm = ask("Do you want to restart the stack now? ", 'yes'); - if ( $confirm ) { - rebuild_stack(); - update_stack_images(); - } + if ( $confirm ) { + rebuild_stack(); + update_stack_images(); + load_env_file( root() . '/.env.slic.run' ); + restart_php_services( true ); + } } exit( 0 ); diff --git a/src/slic.php b/src/slic.php index 1363f36..d064363 100644 --- a/src/slic.php +++ b/src/slic.php @@ -385,10 +385,40 @@ function php_services() { * @param bool $hard Whether to restart the PHP services using the `docker compose restart` command or by using a * tear-down and up again cycle. */ -function restart_php_services( $hard = false ) { - foreach ( php_services() as $service => $pretty_name ) { - restart_service( $service, $pretty_name, $hard ); +function restart_php_services( bool $hard = false ): void { + restart_services( php_services(), $hard ); +} + +/** + * Concurrently restart multiple services at once. + * + * @param array|string[] $services The list of services to restart, e.g. [ 'wordpress', 'slic' ], + * or keyed by service => pretty_name, e.g. [ 'wordpress' => 'WordPress' ] + * @param bool $hard Whether to restart the service using the `docker compose restart` + * command or to use full tear-down and up again cycle. + */ +function restart_services( array $services, bool $hard = false ): void { + echo colorize( sprintf( PHP_EOL . 'Restarting services %s...' . PHP_EOL, implode( ', ', $services ) ) ); + + if ( isset( $services[0] ) ) { + $service_ids = $services; + } else { + $service_ids = array_keys( $services ); } + + if ( $hard ) { + slic_realtime()( array_merge( [ 'rm', '--stop', '--force' ], $service_ids ) ); + slic_realtime()( array_merge( [ 'up', '-d' ], $service_ids ) ); + } else { + slic_realtime()( array_merge( [ 'restart' ], $service_ids ) ); + } + + echo colorize( PHP_EOL . + sprintf( + "✅ %s service%s restarted.", + implode( ', ', $services ), + count( $services ) > 1 ? 's' : '' + ) . PHP_EOL ); } /**