Last active
April 2, 2024 18:42
-
-
Save theritesite/b8047ce597304520ac8509f9aff72a1b to your computer and use it in GitHub Desktop.
EDD Git Download Updater class/process-file.php update for pantheon compatibility. This whole gist (disregarding the <?php ?> tags) should replace the EDD_GIT_Download_Updater_Process_File::unzip() function.
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
<?php | |
/** | |
* "Iteratively" copy files to replace rename function | |
* | |
* This is used for Pantheon and Pressable compatibility | |
* | |
* @param string $src | |
* @param string $dst | |
* @return boolean $new_file | |
*/ | |
public function iterative_copy($source,$dest) { | |
$ret = mkdir($dest); | |
foreach ( $iterator = new \RecursiveIteratorIterator( | |
new \RecursiveDirectoryIterator($source, | |
\RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) | |
as $item ) { | |
if ($item->isDir()) { | |
mkdir($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName()); | |
} else { | |
copy($item, $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName()); | |
} | |
} | |
unlink($source); | |
return $ret; | |
} | |
/* | |
* Unzip our file into a new temporary folder. | |
* | |
* @param string $zip_path | |
* @since 1.0 | |
* @return string $new_dir | |
*/ | |
public function unzip( $zip_path ) { | |
if ( is_dir( trailingslashit( $this->tmp_dir . $this->folder_name ) ) ) { | |
$this->remove_dir( trailingslashit( $this->tmp_dir . $this->folder_name ) ); | |
} | |
$zip = new ZipArchive(); | |
$zip->open( $zip_path ); | |
$zip->extractTo( $this->tmp_dir ); | |
$zip->close(); | |
$this->set_sub_dir( $this->tmp_dir ); | |
// old | |
$new_dir = rename( $this->tmp_dir . $this->sub_dir, $this->tmp_dir . $this->folder_name ); | |
// pantheon compatibility | |
// pressable compatibility | |
// If $new_dir is false due to a fail in rename() | |
if( ! $new_dir ) { | |
$new_dir = $this->iterative_copy( $this->tmp_dir . $this->sub_dir, $this->tmp_dir . $this->folder_name ); | |
} | |
if ( ! $new_dir ) { | |
return false; | |
} | |
$new_dir = $this->tmp_dir . $this->folder_name; | |
$this->set_sub_dir( $this->tmp_dir ); | |
unlink( $this->tmp_dir . $this->file_name ); | |
/** | |
* Allow developers to add an action once the .zip file has been extracted. | |
* | |
* @since 1.3 | |
* @param string $new_dir The new directory. | |
* @param string $repo_name The name of the Git repository. | |
*/ | |
do_action( 'edd_git_zip_extracted', $new_dir, $this->repo_name ); | |
return $new_dir; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment