Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method to update lists from JSON files and clear cache #7054

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions inc/Engine/Optimization/DynamicLists/AbstractDataManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,13 @@ private function put_lists_to_file( string $content ): bool {
private function set_lists_cache( $content ) {
set_transient( $this->get_cache_transient_name(), $content, $this->cache_duration );
}

/**
* Removes the lists cache
*
* @return void
*/
public function remove_lists_cache() {
delete_transient( $this->get_cache_transient_name() );
}
}
26 changes: 26 additions & 0 deletions inc/Engine/Optimization/DynamicLists/DynamicLists.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,4 +313,30 @@ public function get_lrc_exclusions(): array {

return $lists->lazy_rendering_exclusions ?? [];
}

/**
* Updates the lists from JSON files
*
* @return array
*/
public function update_lists_from_files() {
if ( $this->user->is_license_expired() ) {
return [
'success' => false,
'data' => '',
'message' => __( 'You need an active license to get the latest version of the lists from our server.', 'rocket' ),
];
}
Miraeld marked this conversation as resolved.
Show resolved Hide resolved

foreach ( $this->providers as $provider ) {
$provider->data_manager->remove_lists_cache();
$provider->data_manager->get_lists();
}

return [
'success' => true,
'data' => '',
'message' => __( 'Lists are successfully updated from JSON files.', 'rocket' ),
];
Miraeld marked this conversation as resolved.
Show resolved Hide resolved
}
}
10 changes: 10 additions & 0 deletions inc/Engine/Optimization/DynamicLists/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public static function get_subscribed_events() {
'rocket_plugins_to_deactivate' => 'add_incompatible_plugins_to_deactivate',
'rocket_staging_list' => 'add_staging_exclusions',
'rocket_lrc_exclusions' => 'add_lrc_exclusions',
'wp_rocket_upgrade' => 'update_lists_from_files',
];
}

Expand Down Expand Up @@ -202,4 +203,13 @@ public function add_staging_exclusions( $stagings = [] ): array {
public function add_lrc_exclusions( $exclusions ): array {
return array_merge( (array) $exclusions, $this->dynamic_lists->get_lrc_exclusions() );
}

/**
* Update dynamic lists from JSON files.
*
* @return void
*/
public function update_lists_from_files() {
$this->dynamic_lists->update_lists_from_files();
}
}
Loading