Skip to content

Commit

Permalink
add recursive delete to php ; still issue ; udpate process needs test…
Browse files Browse the repository at this point in the history
… (php -> js -> py)
  • Loading branch information
froger-me committed Jan 10, 2024
1 parent 80a578a commit 2cbebcc
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions integration/dummy-generic/wppus-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class WPPUS_API {
private static $url;
private static $package_name;
private static $package_script;
private static $zip_name;
private static $version;
private static $license_key;
private static $license_signature;
Expand Down Expand Up @@ -219,7 +218,9 @@ public static function update() {
if ( is_dir( '/tmp/' . self::$package_name ) ) {
$t_ext = PATHINFO_EXTENSION;
# get the permissions of the current script
$octal_mode = substr( sprintf( '%o', fileperms( self::$package_script ) ), -4 );
$octal_mode = intval( substr( sprintf( '%o', fileperms( self::$package_script ) ), -4 ) );

echo "$octal_mode\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped

# set the permissions of the new main scripts to the permissions of the
# current script
Expand All @@ -236,7 +237,12 @@ public static function update() {

# check if the file does not start with `wppus`, or is .json
if ( 'wppus' !== substr( basename( $file ), 0, 5 ) && 'json' !== pathinfo( $file, $t_ext ) ) {
unlink( $file ); // phpcs:ignore WordPress.WP.AlternativeFunctions.unlink_unlink

if ( is_dir( $file ) ) {
deleteFolder( $file );
} else {
unlink( $file ); // phpcs:ignore WordPress.WP.AlternativeFunctions.unlink_unlink
}
}
}

Expand All @@ -256,7 +262,7 @@ public static function update() {
unlink( $file ); // phpcs:ignore WordPress.WP.AlternativeFunctions.unlink_unlink
}

rmdir( '/tmp/' . self::$package_name ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_rmdir
deleteFolder( '/tmp/' . self::$package_name );
}

# add the license key to wppus.json
Expand All @@ -277,3 +283,25 @@ public static function get_update_info() {
return self::check_for_updates();
}
}

function deleteFolder( $dir_path ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid, Universal.Files.SeparateFunctionsFromOO.Mixed

if ( ! is_dir( $dir_path ) ) {
throw new InvalidArgumentException( "$dir_path must be a directory" ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
}
if ( substr( $dir_path, strlen( $dir_path ) - 1, 1 ) !== '/' ) {
$dir_path .= '/';
}

$files = glob( $dir_path . '*', GLOB_MARK );

foreach ( $files as $file ) {
if ( is_dir( $file ) ) {
deleteFolder( $file );
} else {
unlink( $file ); // phpcs:ignore WordPress.WP.AlternativeFunctions.unlink_unlink
}
}

rmdir( $dir_path ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_rmdir
}

0 comments on commit 2cbebcc

Please sign in to comment.