Skip to content

Commit

Permalink
archive command: add debug, fix minor issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mircobabini committed Aug 25, 2021
1 parent c57136f commit c0c10c8
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions command.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class Swim_WP_CLI extends WP_CLI_Command {
// todo move the version to the "package meta" docblock
const VERSION = '1.3.0';
const VERSION = '1.3.1';

/**
* A test which always gives success and the current version.
Expand Down Expand Up @@ -38,7 +38,7 @@ public function archive( array $args = [], array $assoc_args = [] ) {

$datetime = date( 'YmdHis' );

$target_filepath = "$source_domain-$datetime.zip";
$target_filepath = $archive_root . "$source_domain-$datetime.zip";

// subcommand options
$options = array(
Expand All @@ -50,12 +50,17 @@ public function archive( array $args = [], array $assoc_args = [] ) {

// db dump
$database_filename = "database-$datetime.sql";
WP_CLI::runcommand( "wp db export $database_filename", $options );
WP_CLI::debug( "db export $database_filename" );
WP_CLI::runcommand( "db export $database_filename", $options );

// create the zip archive
exec( "zip -r $target_filepath $archive_root -x 'wp-content/cache*'" );
// NB: zip -r using a dirpath will cause the structure to be kept into the zip.
// to avoid this issue, use pushd/popd: https://superuser.com/questions/119649/avoid-unwanted-path-in-zip-file/119661#119661
WP_CLI::debug( "pushd '$archive_root'; zip -r '$target_filepath' . -x 'wp-content/cache*'; popd;" );
exec( "pushd '$archive_root'; zip -r '$target_filepath' . -x 'wp-content/cache*'; popd;" );

// delete db dump
WP_CLI::debug( "unlink: $archive_root/$database_filename" );
@unlink( "$archive_root/$database_filename" );

WP_CLI::success( "Success. Archive $target_filepath." );
Expand Down

0 comments on commit c0c10c8

Please sign in to comment.