Skip to content

Commit

Permalink
Issue #1 - allow for zip file having been downloaded already
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbingwide committed May 10, 2019
1 parent 8d12d50 commit 7f25249
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions classes/class-OIK-component-update.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,19 +346,35 @@ function download_plugin_version() {
return $error;
}

/**
* Downloads the URL to the target file if not already downloaded
*
* This caters for Genesis theme framework being manually downloaded
*
* @param $url
* @param $target
*
* @return array|null
*/

function download_url_to_target( $url, $target ) {
$this->echo( "Downloading:", $url );
$zip_file = file_get_contents( $url );
if ( $zip_file === false ) {
$error = error_get_last();
$this->echo( "Error:", $error['message']);
$this->set_target_file_name( $target );
if ( file_exists( $target ) ) {
$this->echo( "Download exists:", $target);
$error = null;
} else {
$this->echo( "Downloading:", $url );
$zip_file = file_get_contents( $url );
if ( $zip_file === false ) {
$error = error_get_last();
$this->echo( "Error:", $error['message'] );
} else {

$written = file_put_contents( $target, $zip_file );
$this->set_target_file_name( $target );
$this->echo( "Written:", $target );
$this->echo( "Bytes:", $written );
$error = null;
$written = file_put_contents( $target, $zip_file );
$this->echo( "Written:", $target );
$this->echo( "Bytes:", $written );
$error = null;
}
}
return $error;
}
Expand Down

0 comments on commit 7f25249

Please sign in to comment.