Skip to content

Commit

Permalink
Merge pull request #194 from stellarwp/bugfix/restart-with-correct-ph…
Browse files Browse the repository at this point in the history
…p-version

Bugfix: Properly restarts the PHP services after using the `slic php-version set` command
  • Loading branch information
defunctl authored Jun 6, 2024
2 parents 4ae378b + 548e688 commit 4105e2b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
10 changes: 6 additions & 4 deletions src/commands/php-version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
36 changes: 33 additions & 3 deletions src/slic.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, string>|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(
"✅ <light_cyan>%s service%s restarted.</light_cyan>",
implode( ', ', $services ),
count( $services ) > 1 ? 's' : ''
) . PHP_EOL );
}

/**
Expand Down

0 comments on commit 4105e2b

Please sign in to comment.