-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #184 from stellarwp/1.6.0
1.6.0
- Loading branch information
Showing
6 changed files
with
164 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
// PHP8 str_starts_with() polyfill. | ||
if ( ! function_exists( 'str_starts_with' ) ) { | ||
function str_starts_with( string $haystack, string $needle ): bool { | ||
return 0 === strncmp( $haystack, $needle, strlen( $needle ) ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?php | ||
|
||
namespace StellarWP\Slic; | ||
|
||
/** | ||
* Updates a SQL dump file. Optionally, installs a specific WordPress version. | ||
* | ||
* @var bool $is_help Whether we're handling an `help` request on this command or not. | ||
* @var string $subcommand This command. | ||
* @var callable $args The argument map closure, as produced by the `args` function. | ||
* @var string $cli_name The current name of the `slic` CLI application. | ||
*/ | ||
if ( $is_help ) { | ||
$help = <<< HELP | ||
SUMMARY: | ||
Updates a SQL dump file. Optionally, installs a specific WordPress version. | ||
USAGE: | ||
<yellow>$cli_name $subcommand <file> [<wp_version>]</yellow> | ||
EXAMPLES: | ||
<light_cyan>$cli_name $subcommand tests/_data/dump.sql</light_cyan> | ||
Update the dump file using slic's currently installed version of WordPress. | ||
<light_cyan>$cli_name $subcommand tests/_data/dump.sql latest</light_cyan> | ||
Update the WordPress version to the latest and update the dump file. | ||
<light_cyan>$cli_name $subcommand tests/_data/dump.sql 6.4.3</light_cyan> | ||
Update the WordPress version to 6.4.3 and update the dump file. | ||
HELP; | ||
|
||
echo colorize( $help ); | ||
|
||
return; | ||
} | ||
|
||
// Confirm a target has been set or show an error. | ||
slic_target( false ); | ||
|
||
// Extract the arguments. | ||
$command = $args( '...' ); | ||
$file = trim( $command[0] ); | ||
$version = trim( $command[1] ?? '' ); | ||
|
||
// Build the path inside the slic container. | ||
$container_path = remove_double_separators( trailingslashit( get_project_container_path() ) . $file ); | ||
|
||
// Run core update if a version was provided, otherwise run core update-db. | ||
if ( $version ) { | ||
$update_command = cli_command( [ | ||
'core', | ||
'update', | ||
'--force', | ||
sprintf( '--version=%s', $version ), | ||
], true ); | ||
} else { | ||
$update_command = cli_command( [ | ||
'core', | ||
'update-db', | ||
], true ); | ||
} | ||
|
||
$commands = [ | ||
cli_command( [ | ||
'cli', | ||
'cache', | ||
'clear', | ||
] ), | ||
$update_command, | ||
cli_command( [ | ||
'db', | ||
'reset', | ||
'--yes', | ||
] ), | ||
cli_command( [ | ||
'core', | ||
'version', | ||
'--extra', | ||
], true ), | ||
cli_command( [ | ||
'db', | ||
'export', | ||
'--add-drop-table', | ||
$container_path, | ||
] ), | ||
]; | ||
|
||
// Execute the command chain. | ||
foreach ( $commands as $arguments ) { | ||
$result = slic_passive()( $arguments ); | ||
|
||
// 0 is success on command line. | ||
if ( $result === 0 ) { | ||
continue; | ||
} | ||
|
||
echo magenta( sprintf( 'Error: Command Failed: %s', implode( ' ', $arguments ) ) ); | ||
exit ( 1 ); | ||
} | ||
|
||
ensure_wordpress_installed(); | ||
|
||
echo green( sprintf( | ||
"Success: Exported to host path '%s'.", | ||
remove_double_separators( trailingslashit( get_project_local_path() ) . $file ) | ||
) ); | ||
|
||
exit( 0 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters