Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
tlovett1 committed May 17, 2021
2 parents 4e5a844 + f0395e8 commit cfb29a2
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 21 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ All notable changes to this project will be documented in this file, per [the Ke

## [Unreleased] - TBD

## [2.1.0] - TBD
## [2.2.0] - 2021-05-17
* Support overriding version for create and push as well as setting version to `nightly`. Props [dinhtungdu](https://github.com/dinhtungdu).
* Better error handling for `get_download_url`. Props [paulschreiber](https://github.com/paulschreiber).
* Message warning users about using production databases
* Update `rmccue/requests` version

## [2.1.0] - 2021-01-22
### Added
- `--overwirte_local_copy` flag to the `pull` command (props [@eugene-manuilov](https://github.com/eugene-manuilov) via [#71](https://github.com/10up/wpsnapshots/pull/71)).
- `--suppress_instructions` flag to the `pull` command (props [@eugene-manuilov](https://github.com/eugene-manuilov) via [#76](https://github.com/10up/wpsnapshots/pull/76)).
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"require": {
"symfony/console": "^3.3 || ^4.1",
"rmccue/requests": "^1.7",
"rmccue/requests": "^1.8",
"php": ">=5.6",
"aws/aws-sdk-php": "^3.67"
},
Expand Down
35 changes: 22 additions & 13 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

use \Symfony\Component\Console\Application;

define( 'WPSNAPSHOTS_VERSION', '2.1.0' );
define( 'WPSNAPSHOTS_VERSION', '2.2.0' );

require_once __DIR__ . '/utils.php';

Expand Down
3 changes: 3 additions & 0 deletions src/classes/Command/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ protected function configure() {
$this->addOption( 'db_name', null, InputOption::VALUE_REQUIRED, 'Database name.' );
$this->addOption( 'db_user', null, InputOption::VALUE_REQUIRED, 'Database user.' );
$this->addOption( 'db_password', null, InputOption::VALUE_REQUIRED, 'Database password.' );

$this->addOption( 'wp_version', null, InputOption::VALUE_OPTIONAL, 'Override the WordPress version.' );
}

/**
Expand Down Expand Up @@ -149,6 +151,7 @@ protected function execute( InputInterface $input, OutputInterface $output ) {
'repository' => $repository->getName(),
'contains_db' => $include_db,
'contains_files' => $include_files,
'wp_version' => $input->getOption( 'wp_version' ),
],
$output,
$input->getOption( 'verbose' )
Expand Down
48 changes: 44 additions & 4 deletions src/classes/Command/Pull.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ protected function execute( InputInterface $input, OutputInterface $output ) {
return 1;
}

$output->writeln( '<comment>Security Warning: WP Snapshots creates copies of your codebase and database. This could result in data retention policy issues, please exercise extreme caution when using production data.</comment>' );

$id = $input->getArgument( 'snapshot_id' );

$helper = $this->getHelper( 'question' );
Expand Down Expand Up @@ -225,7 +227,13 @@ protected function execute( InputInterface $input, OutputInterface $output ) {

Log::instance()->write( 'Extracting WordPress...', 1 );

exec( 'rm -rf ' . Utils\escape_shell_path( $path ) . 'wordpress && tar -C ' . Utils\escape_shell_path( $path ) . ' -xf ' . Utils\escape_shell_path( $snapshot_path ) . 'wp.tar.gz ' . $verbose_pipe );
exec( 'rm -rf ' . Utils\escape_shell_path( $path ) . 'wordpress' );

$this->extractArchive(
Utils\escape_shell_path( $snapshot_path ) . 'wp.tar.gz',
Utils\escape_shell_path( $path ),
$verbose_pipe
);

Log::instance()->write( 'Moving WordPress files...', 1 );

Expand Down Expand Up @@ -461,10 +469,12 @@ protected function execute( InputInterface $input, OutputInterface $output ) {

$download_url = Utils\get_download_url( $snapshot->meta['wp_version'] );

$downloaded_file_path = Utils\escape_shell_path( $snapshot_path ) . ( strpos( $download_url, '.zip' ) ? 'wp.zip' : 'wp.tar.gz' );

$headers = [ 'Accept' => 'application/json' ];
$options = [
'timeout' => 600,
'filename' => $snapshot_path . 'wp.tar.gz',
'filename' => $downloaded_file_path,
];

Log::instance()->write( 'Downloading WordPress ' . $snapshot->meta['wp_version'] . '...', 1 );
Expand All @@ -473,7 +483,11 @@ protected function execute( InputInterface $input, OutputInterface $output ) {

Log::instance()->write( 'Extracting WordPress...', 1 );

exec( 'tar -C ' . Utils\escape_shell_path( $path ) . ' -xf ' . Utils\escape_shell_path( $snapshot_path ) . 'wp.tar.gz ' . $verbose_pipe );
$this->extractArchive(
$downloaded_file_path,
Utils\escape_shell_path( $path ),
$verbose_pipe
);

Log::instance()->write( 'Moving WordPress files...', 1 );

Expand Down Expand Up @@ -853,7 +867,11 @@ function( $answer ) {

exec( 'mkdir -p ' . Utils\escape_shell_path( WP_CONTENT_DIR ) );

exec( 'tar -C ' . Utils\escape_shell_path( WP_CONTENT_DIR ) . ' -xf ' . Utils\escape_shell_path( $snapshot_path ) . 'files.tar.gz ' . $verbose_pipe );
$this->extractArchive(
Utils\escape_shell_path( $snapshot_path ) . 'files.tar.gz',
Utils\escape_shell_path( WP_CONTENT_DIR ),
$verbose_pipe
);
}

/**
Expand All @@ -877,4 +895,26 @@ function( $answer ) {
}
}

/**
* Extract archive file helper. Support tar and zip file
*
* @param string $file_path Archive file path.
* @param string $destination_path Destination path.
*/
private function extractArchive( $file_path, $destination_path, $verbose_pipe = '' ) {
if ( strpos( $file_path, '.tar' ) ) {
return exec( 'tar -C ' . $destination_path . ' -xf ' . $file_path . ' ' . $verbose_pipe );
}

if ( ! class_exists( 'ZipArchive' ) ) {
return exec( 'unzip -d ' . $destination_path . ' ' . $file_path . ' ' . $verbose_pipe );
}

$zip = new \ZipArchive;
if ( $zip->open( $file_path ) === true ) {
$zip->extractTo( $destination_path );
$zip->close();
}
}
}

5 changes: 5 additions & 0 deletions src/classes/Command/Push.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ protected function configure() {
$this->addOption( 'db_password', null, InputOption::VALUE_REQUIRED, 'Database password.' );
$this->addOption( 'exclude', false, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Exclude a file or directory from the snapshot.' );
$this->addOption( 'exclude_uploads', false, InputOption::VALUE_NONE, 'Exclude uploads from pushed snapshot.' );

$this->addOption( 'wp_version', null, InputOption::VALUE_OPTIONAL, 'Override the WordPress version.' );
}
/**
* Executes the command
Expand All @@ -69,6 +71,8 @@ protected function execute( InputInterface $input, OutputInterface $output ) {
return 1;
}

$output->writeln( '<comment>Security Warning: WP Snapshots creates copies of your codebase and database. This could result in data retention policy issues, please exercise extreme caution when using production data.</comment>' );

$snapshot_id = $input->getArgument( 'snapshot_id' );

if ( ! empty( $snapshot_id ) ) {
Expand Down Expand Up @@ -175,6 +179,7 @@ protected function execute( InputInterface $input, OutputInterface $output ) {
'repository' => $repository->getName(),
'contains_db' => $include_db,
'contains_files' => $include_files,
'wp_version' => $input->getOption( 'wp_version' ),
], $output, $verbose
);
}
Expand Down
3 changes: 3 additions & 0 deletions src/classes/Snapshot.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ public static function create( $args ) {
);

$meta['wp_version'] = ( ! empty( $wp_version ) ) ? $wp_version : '';
if ( ! empty( $args['wp_version'] ) ) {
$meta['wp_version'] = $args['wp_version'];
}

$author_info = RepositoryManager::instance()->getAuthorInfo();
$author = [];
Expand Down
6 changes: 5 additions & 1 deletion src/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ function create_config_file( $path, $path_to_template, $constants = [] ) {
* @return string|bool
*/
function get_download_url( $version = 'latest', $locale = 'en_US' ) {
if ( ! $version ) {
return false;
}

if ( 'nightly' === $version ) {
return 'https://wordpress.org/nightly-builds/wordpress-latest.zip';
}
Expand All @@ -287,7 +291,7 @@ function get_download_url( $version = 'latest', $locale = 'en_US' ) {
return str_replace( '.zip', '.tar.gz', $request_body['offers'][0]['download'] );
}

if ( 'en_US' === $locale ) {
if ( 'en_US' === $locale || ! $locale ) {
$url = 'https://wordpress.org/wordpress-' . $version . '.tar.gz';

return $url;
Expand Down

0 comments on commit cfb29a2

Please sign in to comment.