Skip to content

Commit

Permalink
Merge pull request #78 from dinhtungdu/fix/install-wordpress-nightly
Browse files Browse the repository at this point in the history
fix: install nightly version
  • Loading branch information
tlovett1 authored May 17, 2021
2 parents 8d4971d + 40d7c1d commit 9ef233d
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 4 deletions.
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
46 changes: 42 additions & 4 deletions src/classes/Command/Pull.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,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 @@ -463,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 @@ -475,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 @@ -855,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 @@ -879,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();
}
}
}

3 changes: 3 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 Down Expand Up @@ -177,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

0 comments on commit 9ef233d

Please sign in to comment.