Skip to content

Commit

Permalink
fix the multisite update background-css dir clearance
Browse files Browse the repository at this point in the history
  • Loading branch information
wordpressfan committed Jan 28, 2025
1 parent dc54b37 commit a92c6d5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
6 changes: 4 additions & 2 deletions inc/Engine/Common/Cache/CacheInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ public function get_root_path(): string;
public function generate_path( string $url ): string;

/**
* Wipes the whole cache directory .
* Wipes the whole cache directory.
*
* @param array $preserve_dirs List of directories to be preserved.
*
* @return bool True on success and false on failure.
*/
public function full_clear(): bool;
public function full_clear( array $preserve_dirs = [] ): bool;
}
6 changes: 4 additions & 2 deletions inc/Engine/Common/Cache/FilesystemCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,16 @@ public function clear() {
/**
* Clear the whole background-css directory.
*
* @param array $preserve_dirs List of directories to be preserved.
*
* @return bool True on success and false on failure.
*/
public function full_clear(): bool {
public function full_clear( array $preserve_dirs = [] ): bool {
$base_path = $this->get_base_path();
if ( ! $this->filesystem->exists( $base_path ) ) {
return false;
}
rocket_rrmdir( $base_path, [], $this->filesystem );
rocket_rrmdir( $base_path, $preserve_dirs, $this->filesystem );
return true;
}

Expand Down
5 changes: 4 additions & 1 deletion inc/Engine/Media/Lazyload/CSS/Admin/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ public function clear_background_css_with_upgrade( $new_version, $old_version )
if ( empty( $old_version ) || version_compare( $old_version, '3.18', '>' ) ) {
return;
}

$preserve_dirs = is_multisite() ? get_sites( [ 'fields' => 'ids' ] ) : [ get_current_blog_id() ];

// Completely clear background-css directory.
$this->cache->full_clear();
$this->cache->full_clear( $preserve_dirs );
}
}

0 comments on commit a92c6d5

Please sign in to comment.