Skip to content

Commit 577d848

Browse files
authored
Merge pull request #231 from stellarwp/2.1.5
Fix SLIC_WP_AUTO_UPDATE_CORE handling
2 parents 79c4619 + 1444eae commit 577d848

File tree

8 files changed

+212
-75
lines changed

8 files changed

+212
-75
lines changed

.env.slic

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# DO NOT MODIFY THIS FILE!
33
# If you need to override the contents of this file create a .env.slic.local file and customize it.
44

5-
65
# slic cli configuration parameters.
76
# ==================================
87
# The containers will each be assigned an IP address in the `slic` network.
@@ -86,10 +85,13 @@ SLIC_WP_HTTP_BLOCK_EXTERNAL=true
8685
# Set to `true` to disable the WordPress cron system, set to `false` to enable it.
8786
SLIC_DISABLE_WP_CRON=true
8887

89-
# This value will be assigned to the WP_AUTO_UPDATE_CORE constant defined in the wp-config.php file.
90-
# Set to `true` to allow automatic core updates to take place.
88+
# Controls the WP_AUTO_UPDATE_CORE constant in wp-config.php.
89+
# If not set or empty, the constant will NOT be defined, allowing WordPress to use its default behavior.
90+
# If set to a value (e.g., `true`, `false`, `minor`), the constant will be defined with that value.
91+
# To allow core auto updating, set `SLIC_WP_AUTO_UPDATE_CORE=` (empty value) to override this default.
9192
SLIC_WP_AUTO_UPDATE_CORE=false
9293

93-
# This value will be assigned to the AUTOMATIC_UPDATER_DISABLED constant defined in the wp-config.php file.
94-
# Set to `false` to allow all types of automatic updates.
94+
# Controls the AUTOMATIC_UPDATER_DISABLED constant in wp-config.php.
95+
# If not set or empty, the constant will NOT be defined, allowing WordPress to use its default behavior.
96+
# If set to a value (e.g., `true`, `false`), the constant will be defined with that value.
9597
SLIC_AUTOMATIC_UPDATER_DISABLED=true

changelog.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
# [2.1.5] - 2025-11-28
8+
9+
- Fixed - Handling of the project in the `use` command to guarantee that project specific override files will apply to all operations performed during the handling of the `use` command, including possible spin up of the stack.
10+
- Fixed - Correctly handle the `SLIC_WP_AUTO_UPDATE_CORE`, allow "undefining" this env var with `SLIC_WP_AUTO_UPDATE_CORE=`
11+
- Fixed - Correctly handle the `SLIC_AUTOMATIC_UPDATER_DISABLED`, allow "undefining" this env var with `SLIC_AUTOMATIC_UPDATER_DISABLED=`
12+
- Fixed - Correctly handle the `SLIC_WP_HTTP_BLOCK_EXTERNAL`, allow "undefining" this env var with `SLIC_WP_HTTP_BLOCK_EXTERNAL=`
13+
- Changed - `update-dump` command now validates dump file existence before processing, provides clearer progress messages, and properly restores the original WordPress version after testing with a specific version.
14+
- Fixed - `read_env_file()` no longer reads commented out env vars, e.g. `# SOME_VAR=test` would previously be set.
15+
716
# [2.1.4] - 2025-11-26
817

918
- Fixed - Use `mysqlshow` to check `db` service health when using MySQL 5.5.

slic-stack.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ services:
9090
define( 'WP_DEBUG_DISPLAY', true );
9191
define( 'WP_DEBUG_LOG', true );
9292
define( 'DISABLE_WP_CRON', ${SLIC_DISABLE_WP_CRON:-true} );
93-
define( 'WP_HTTP_BLOCK_EXTERNAL', ${SLIC_WP_HTTP_BLOCK_EXTERNAL:-true} );
94-
define( 'WP_AUTO_UPDATE_CORE', ${SLIC_WP_AUTO_UPDATE_CORE:-false} );
95-
define( 'AUTOMATIC_UPDATER_DISABLED', ${SLIC_AUTOMATIC_UPDATER_DISABLED:-true} );
93+
${SLIC_WP_HTTP_BLOCK_EXTERNAL:+define( 'WP_HTTP_BLOCK_EXTERNAL', ${SLIC_WP_HTTP_BLOCK_EXTERNAL} );}
94+
${SLIC_WP_AUTO_UPDATE_CORE:+define( 'WP_AUTO_UPDATE_CORE', ${SLIC_WP_AUTO_UPDATE_CORE} );}
95+
${SLIC_AUTOMATIC_UPDATER_DISABLED:+define( 'AUTOMATIC_UPDATER_DISABLED', ${SLIC_AUTOMATIC_UPDATER_DISABLED} );}
9696
# Configure this to debug the tests with XDebug.
9797
# Map the `_wordpress` directory to `/var/www/html' directory in your IDE of choice.
9898
# Map the `_plugins` directory to `/plugins` directory in your IDE of choice.

slic.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
] );
3535

3636
$cli_name = 'slic';
37-
const CLI_VERSION = '2.1.4';
37+
const CLI_VERSION = '2.1.5';
3838

3939
// If the run-time option `-q`, for "quiet", is specified, then do not print the header.
4040
if ( in_array( '-q', $argv, true ) || ( in_array( 'exec', $argv, true ) && ! in_array( 'help', $argv, true ) ) ) {
@@ -114,7 +114,7 @@
114114
<light_cyan>up</light_cyan> Starts containers in the stack; alias of `start`.
115115
<light_cyan>update</light_cyan> Updates the tool and the images used in its services.
116116
<light_cyan>upgrade</light_cyan> Upgrades the {$cli_name} repo.
117-
<light_cyan>update-dump</light_cyan> Updates a SQL dump file. Optionally, installs a specific WordPress version..
117+
<light_cyan>update-dump</light_cyan> Updates a SQL dump.sql for acceptance testing by importing, upgrading, and re-exporting it.
118118
HELP;
119119

120120
$help_message = colorize( $help_message_template );

src/commands/update-dump.php

Lines changed: 146 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
namespace StellarWP\Slic;
44

55
/**
6-
* Updates a SQL dump file. Optionally, installs a specific WordPress version.
6+
* Updates a SQL dump file by importing it, running database updates, and exporting it back.
7+
* Optionally tests the dump with a specific WordPress version before restoring the original version.
78
*
89
* @var bool $is_help Whether we're handling an `help` request on this command or not.
910
* @var string $subcommand This command.
@@ -14,7 +15,11 @@
1415
$help = <<< HELP
1516
SUMMARY:
1617
17-
Updates a SQL dump file. Optionally, installs a specific WordPress version.
18+
Updates a SQL dump file by importing it, running database updates, and exporting it back.
19+
Optionally upgrades the dump to a specific WordPress version (then restores original version).
20+
21+
The process: imports the dump.sql → optionally installs a WP version → runs core update-db →
22+
exports an updated dump.sql → restores original WP version (if version was specified).
1823
1924
USAGE:
2025
@@ -23,13 +28,13 @@
2328
EXAMPLES:
2429
2530
<light_cyan>$cli_name $subcommand tests/_data/dump.sql</light_cyan>
26-
Update the dump file using slic's currently installed version of WordPress.
31+
Update the dump file's database structure using the current WordPress version.
2732
2833
<light_cyan>$cli_name $subcommand tests/_data/dump.sql latest</light_cyan>
29-
Update the WordPress version to the latest and update the dump file.
34+
Update the dump file to be compatible with the latest WordPress version.
3035
3136
<light_cyan>$cli_name $subcommand tests/_data/dump.sql 6.4.3</light_cyan>
32-
Update the WordPress version to 6.4.3 and update the dump file.
37+
Update the dump file to be compatible with WordPress 6.4.3.
3338
HELP;
3439

3540
echo colorize( $help );
@@ -45,67 +50,157 @@
4550
$file = trim( $command[0] );
4651
$version = trim( $command[1] ?? '' );
4752

48-
// Build the path inside the slic container.
53+
// Build the paths.
4954
$container_path = remove_double_separators( trailingslashit( get_project_container_path() ) . $file );
55+
$host_path = remove_double_separators( trailingslashit( get_project_local_path() ) . $file );
56+
57+
// Proper line endings.
58+
$lb = PHP_EOL;
59+
60+
// Check if the existing dump file exists.
61+
if ( ! file_exists( $host_path ) ) {
62+
echo magenta( sprintf(
63+
"Error: Dump file '%s' does not exist.\nPlease create it first with: %s wp db export --add-drop-table %s",
64+
$host_path,
65+
$cli_name,
66+
$file
67+
) );
68+
69+
exit( 1 );
70+
}
5071

51-
// Run core update if a version was provided, otherwise run core update-db.
72+
ensure_wordpress_installed();
73+
74+
$original_version = null;
75+
76+
// If $version is passed, capture the existing WP version to restore later.
5277
if ( $version ) {
53-
$update_command = cli_command( [
54-
'core',
55-
'update',
56-
'--force',
57-
sprintf( '--version=%s', $version ),
58-
], true );
59-
} else {
60-
$update_command = cli_command( [
78+
$version_command = cli_command( [
6179
'core',
62-
'update-db',
80+
'version',
6381
], true );
82+
83+
ob_start();
84+
$result = slic_realtime()( $version_command );
85+
$output = trim( ob_get_clean() );
86+
87+
if ( $result === 0 && ! empty( $output ) ) {
88+
$original_version = $output;
89+
echo colorize( sprintf( "<light_cyan>Captured current WordPress version: %s</light_cyan>{$lb}", $original_version ) );
90+
} else {
91+
echo magenta( 'Warning: Could not capture current WordPress version.' );
92+
}
6493
}
6594

66-
$commands = [
67-
cli_command( [
68-
'cli',
69-
'cache',
70-
'clear',
71-
] ),
72-
$update_command,
73-
cli_command( [
74-
'db',
75-
'reset',
76-
'--yes',
77-
] ),
78-
cli_command( [
95+
// Clear the cache.
96+
echo colorize( "<light_cyan>Clearing cache...</light_cyan>{$lb}" );
97+
$result = slic_realtime()( cli_command( [
98+
'cli',
99+
'cache',
100+
'clear',
101+
] ) );
102+
103+
if ( $result !== 0 ) {
104+
echo magenta( 'Error: Failed to clear cache.' );
105+
exit( 1 );
106+
}
107+
108+
// Reset database.
109+
echo colorize( "<light_cyan>Resetting database...</light_cyan>{$lb}" );
110+
$result = slic_realtime()( cli_command( [
111+
'db',
112+
'reset',
113+
'--yes',
114+
] ) );
115+
116+
if ( $result !== 0 ) {
117+
echo magenta( 'Error: Failed to reset database.' );
118+
exit( 1 );
119+
}
120+
121+
// Import existing dump file.
122+
echo colorize( "<light_cyan>Importing dump file...</light_cyan>{$lb}" );
123+
$result = slic_realtime()( cli_command( [
124+
'db',
125+
'import',
126+
$container_path,
127+
] ) );
128+
129+
if ( $result !== 0 ) {
130+
echo magenta( sprintf( 'Error: Failed to import dump file: %s', $container_path ) );
131+
exit( 1 );
132+
}
133+
134+
// If $version is passed, install that WP version.
135+
if ( $version ) {
136+
echo colorize( sprintf( "<light_cyan>Installing WordPress version %s...</light_cyan>{$lb}", $version ) );
137+
$result = slic_realtime()( cli_command( [
79138
'core',
80-
'version',
81-
'--extra',
82-
], true ),
83-
cli_command( [
84-
'db',
85-
'export',
86-
'--add-drop-table',
87-
$container_path,
88-
] ),
89-
];
90-
91-
// Execute the command chain.
92-
foreach ( $commands as $arguments ) {
93-
$result = slic_passive()( $arguments );
94-
95-
// 0 is success on command line.
96-
if ( $result === 0 ) {
97-
continue;
139+
'update',
140+
'--force',
141+
sprintf( '--version=%s', $version ),
142+
], true ) );
143+
144+
if ( $result !== 0 ) {
145+
echo magenta( sprintf( 'Error: Failed to install WordPress version: %s', $version ) );
146+
exit( 1 );
98147
}
148+
}
99149

100-
echo magenta( sprintf( 'Error: Command Failed: %s', implode( ' ', $arguments ) ) );
101-
exit ( 1 );
150+
// Run core update-db.
151+
echo colorize( "<light_cyan>Updating database...</light_cyan>{$lb}" );
152+
$result = slic_realtime()( cli_command( [
153+
'core',
154+
'update-db',
155+
] ) );
156+
157+
if ( $result !== 0 ) {
158+
echo magenta( 'Error: Failed to update database.' );
159+
exit( 1 );
102160
}
103161

104-
ensure_wordpress_installed();
162+
// Export the dump.sql to the same file.
163+
echo colorize( "<light_cyan>Exporting updated dump...</light_cyan>{$lb}" );
164+
$result = slic_realtime()( cli_command( [
165+
'db',
166+
'export',
167+
'--add-drop-table',
168+
$container_path,
169+
] ) );
170+
171+
if ( $result !== 0 ) {
172+
echo magenta( 'Error: Failed to export database.' );
173+
exit( 1 );
174+
}
175+
176+
// If $version was passed, restore the original WP version and run core update-db again.
177+
if ( $version && $original_version ) {
178+
echo colorize( sprintf( "<light_cyan>Restoring original WordPress version %s...</light_cyan>{$lb}", $original_version ) );
179+
$result = slic_realtime()( cli_command( [
180+
'core',
181+
'update',
182+
'--force',
183+
sprintf( '--version=%s', $original_version ),
184+
], true ) );
185+
186+
if ( $result !== 0 ) {
187+
echo magenta( sprintf( 'Warning: Failed to restore WordPress version: %s', $original_version ) );
188+
} else {
189+
echo colorize( "<light_cyan>Updating database for restored version...</light_cyan>{$lb}" );
190+
$result = slic_realtime()( cli_command( [
191+
'core',
192+
'update-db',
193+
] ) );
194+
195+
if ( $result !== 0 ) {
196+
echo magenta( 'Warning: Failed to update database after restoring version.' );
197+
}
198+
}
199+
}
105200

106201
echo green( sprintf(
107202
"Success: Exported to host path '%s'.",
108-
remove_double_separators( trailingslashit( get_project_local_path() ) . $file )
203+
$host_path
109204
) );
110205

111206
exit( 0 );

src/slic.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,20 @@ function setup_slic_env( $root_dir, $reset = false ) {
272272
load_env_file( $root_dir . '/.env.slic.run' );
273273
}
274274

275+
/*
276+
* Special handling of the `use` command.
277+
*
278+
* This has to be detected early to allow for override files in the `use` target to apply.
279+
* If the user called `slic use some-plugin`, then this will set the `SLIC_CURRENT_PROJECT` env
280+
* var to `some-plugin`. This will, in turn, affect all the functions that use the information of the
281+
* project path like the `get_project_local_path()` one in the context of the handling of the `use` command.
282+
*/
283+
global $argc, $argv;
284+
if ( $argc >= 3 && $argv[1] === 'use' && ! empty( $argv[2] ) ) {
285+
$target = (string) ensure_valid_target( $argv[2] );
286+
putenv( "SLIC_CURRENT_PROJECT={$target}" );
287+
}
288+
275289
$target_path = get_project_local_path();
276290
if( ! empty( $target_path ) ) {
277291
// Load the local overrides from the target.
@@ -379,7 +393,6 @@ function slic_set_php_version( $version, $require_confirm = false, $skip_rebuild
379393

380394
rebuild_stack();
381395
update_stack_images();
382-
load_env_file( root() . '/.env.slic.run' );
383396
restart_php_services( true );
384397
}
385398

src/utils.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,23 @@ function read_env_file( $env_file ) {
8989
exit( 1 );
9090
}
9191

92-
$lines = array_filter( explode( "\n", file_get_contents( $env_file ) ) );
92+
$lines = explode( "\n", file_get_contents( $env_file ) );
9393
$env_lines = [];
9494
foreach ( $lines as $env_line ) {
95+
// Trim whitespace.
96+
$env_line = trim( $env_line );
97+
98+
// Skip empty lines and comments.
99+
if ( empty( $env_line ) || strpos( $env_line, '#' ) === 0 ) {
100+
continue;
101+
}
102+
95103
if ( ! preg_match( '/^(?<key>[^=]+)=(?<value>.*)$/', $env_line, $m ) ) {
96104
continue;
97105
}
98-
$env_lines[ $m['key'] ] = $m['value'];
106+
107+
// Don't trim value to preserve intentional spaces.
108+
$env_lines[ trim( $m['key'] ) ] = $m['value'];
99109
}
100110

101111
return $env_lines;

0 commit comments

Comments
 (0)