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

Clear root folder when WPML uses a directory for the default language #5611

Closed
2 of 6 tasks
DahmaniAdame opened this issue Dec 6, 2022 · 3 comments · Fixed by #5761
Closed
2 of 6 tasks

Clear root folder when WPML uses a directory for the default language #5611

DahmaniAdame opened this issue Dec 6, 2022 · 3 comments · Fixed by #5761
Assignees
Labels
3rd party compatibility Issues related to 3rd party compatibility like theme, plugin or hosting effort: [S] 1-2 days of estimated development time module: cache needs: documentation Issues which need to create or update a documentation priority: medium Issues which are important, but no one will go out of business. severity: moderate Feature isn't working as expected but has work around to get same value type: bug Indicates an unexpected problem or unintended behavior
Milestone

Comments

@DahmaniAdame
Copy link
Contributor

DahmaniAdame commented Dec 6, 2022

Before submitting an issue please check that you’ve completed the following steps:

  • Made sure you’re on the latest version 3.12.3.2
  • Used the search feature to ensure that the bug hasn’t been reported before

Describe the bug
When WPML uses the option use directory for default language, the root folder is inaccessible by any of our cache-purging function.

image

The default language will have a separate folder from the root in this scenario.

We are doing that kind of check when WPML is enabled:

$urls = ( ! $lang || is_object( $lang ) || is_array( $lang ) || is_int( $lang ) )
? (array) get_rocket_i18n_uri()
: (array) get_rocket_i18n_home_url( $lang );

We need compatibility with WPML to detect that the sub-option is enabled and include the root folder in actions.

Temporarily fixed by clearing files from root using:

function rocket_remove_root_cached_files( $post, $purge_urls, $lang ) {
	$cache_folder_path = _rocket_get_wp_rocket_cache_path() . $_SERVER['SERVER_NAME'] . "/";
	$cache_folder_directory = dir($cache_folder_path);
	while ($file = $cache_folder_directory->read()) {
		if (!strpos($file,'.html')) continue;
		unlink($cache_folder_path . $file);
	}
}
add_action( 'after_rocket_clean_home', 'rocket_remove_root_cached_files', 10, 3 );
add_action( 'after_rocket_clean_domain', 'rocket_remove_root_cached_files', 10, 3 );

To Reproduce
Steps to reproduce the behavior:

  1. Use WPML and enable use directory for default language
  2. Make sure the root homepage is cached
  3. Try to purge cache
  4. See error

Expected behavior
All caches should be accessible to purge regardless of what options are enabled on WPML.

Screenshots
Added to decription.

Additional context
Ticket - https://secure.helpscout.net/conversation/2071911982/382573/

Backlog Grooming (for WP Media dev team use only)

  • Reproduce the problem
  • Identify the root cause
  • Scope a solution
  • Estimate the effort
@piotrbak piotrbak added type: bug Indicates an unexpected problem or unintended behavior 3rd party compatibility Issues related to 3rd party compatibility like theme, plugin or hosting module: cache priority: medium Issues which are important, but no one will go out of business. severity: moderate Feature isn't working as expected but has work around to get same value labels Dec 6, 2022
@webtrainingwheels
Copy link

I think it's the same as this one?
#1890

@DahmaniAdame
Copy link
Contributor Author

@webtrainingwheels, it's the same issue, indeed.
@piotrbak we can close #1890 since this one is more recent and has more details.

@CrochetFeve0251 CrochetFeve0251 added GROOMING IN PROGRESS Use this label when the issue is currently being groomed. and removed needs: grooming labels Feb 13, 2023
@CrochetFeve0251
Copy link
Contributor

Reproduce the problem

I reproduced the issue locally.

Identify the root cause

The root problem is mentionned by @DahmaniAdame.

Scope a solution

For the solution in the WPML subscriber we will add the following callback:

public function remove_root_cached_files() {
		$site_url = home_url();
		$host_name = parse_url( $site_url, PHP_URL_HOST );
		$cache_folder_path = _rocket_get_wp_rocket_cache_path() . $host_name . "/";
		$cache_folder_directory = $this->filesystem->dirlist($cache_folder_path);
		foreach (array_keys($cache_folder_directory) as $entry) {
			if ($this->filesystem->is_dir($entry)) {
				continue;
			}
			$this->filesystem->delete($cache_folder_path . $entry);
		}
	}

That we will subscribe to the events:

  • after_rocket_clean_home
  • after_rocket_clean_domain

Estimate the effort

Effort S

PS: Thank you for the base template @DahmaniAdame

@CrochetFeve0251 CrochetFeve0251 added effort: [S] 1-2 days of estimated development time and removed GROOMING IN PROGRESS Use this label when the issue is currently being groomed. labels Feb 13, 2023
@piotrbak piotrbak added this to the 3.13.1 milestone Mar 1, 2023
@CrochetFeve0251 CrochetFeve0251 self-assigned this Mar 15, 2023
@piotrbak piotrbak added the needs: documentation Issues which need to create or update a documentation label Mar 29, 2023
@piotrbak piotrbak modified the milestones: 3.13.1, 3.13.2 Apr 7, 2023
@piotrbak piotrbak removed this from the 3.13.2 milestone Apr 23, 2023
@piotrbak piotrbak added this to the 3.14.1 milestone Jun 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3rd party compatibility Issues related to 3rd party compatibility like theme, plugin or hosting effort: [S] 1-2 days of estimated development time module: cache needs: documentation Issues which need to create or update a documentation priority: medium Issues which are important, but no one will go out of business. severity: moderate Feature isn't working as expected but has work around to get same value type: bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants