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

Display a notice after a site was cloned to disable/re-enable WP Rocket #5667

Closed
WordPresseur opened this issue Jan 9, 2023 · 2 comments · Fixed by #5688 or #6122
Closed

Display a notice after a site was cloned to disable/re-enable WP Rocket #5667

WordPresseur opened this issue Jan 9, 2023 · 2 comments · Fixed by #5688 or #6122
Assignees
Labels
effort: [S] 1-2 days of estimated development time module: filesystem needs: copywriting 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. type: enhancement Improvements that slightly enhance existing functionality and are fast to implement
Milestone

Comments

@WordPresseur
Copy link
Contributor

Is your feature request related to a problem? Please describe.
Not all users are aware they have to deactivate WP Rocket before a migration/clone and if a user migrate/clone their site with WP Rocket active, it can leads to issues like a non cached/optimized site due to wrong config files.

Deactivate/re-activate WP Rocket allows to recreate the right config files and fixes the issues.

Describe the solution you'd like
Display a notice after a site was cloned to disable/re-enable WP Rocket.

Describe alternatives you've considered
Auto-detect the new domain/site URL and deactivate/re-activate WP Rocket in background.
Woocommerce detects when a new domain/site URL is found and automatically disable functionality like Subscriptions.

Additional context
Ticket: https://secure.helpscout.net/conversation/2114325821/393025/
HS Doc: https://docs.wp-rocket.me/article/705-changing-domains-migrating-sites-with-wp-rocket

@piotrbak
Copy link
Contributor

piotrbak commented Jan 9, 2023

Should be fixed together with:
#5647
#5549

@piotrbak piotrbak added type: enhancement Improvements that slightly enhance existing functionality and are fast to implement priority: medium Issues which are important, but no one will go out of business. module: filesystem needs: grooming labels Jan 9, 2023
@CrochetFeve0251 CrochetFeve0251 added GROOMING IN PROGRESS Use this label when the issue is currently being groomed. and removed needs: grooming labels Jan 16, 2023
@CrochetFeve0251
Copy link
Contributor

CrochetFeve0251 commented Jan 16, 2023

Identify the root cause

The root issue is that we never check the actual URL.

Scope a solution

A solution would be to develop a section of the code here to detect a change of domain with an action rocket_domain_changed.
And hook a piece of code corresponding to each issue in the corresponding part:

  • A clear of the cache inside the cache part.
  • A reset of the preload cache table inside the preload part.
  • A clear from the config and of advanced-cache.php

For the detecting part we can use an option to save the last url.
If this one dismatch the current URL then we can launch the action rocket_domain_changed that will launch the hooked actions.
To implement that part we will have to create a subscriber inside Engine\Admin in a subfolder DomainChange with the following content:

<?php
namespace WP_Rocket\Engine\Admin\DomainChange;

class Subscriber implements Subscriber_Interface {

  const LAST_BASE_URL_OPTION = 'wp_rocket_last_base_url';

   protected $filesystem;

   public function __construct($filesystem) {
     $this->filesystem = $filesystem;
   }

    public static function get_subscribed_events() {
     return [
     'admin_init'  => 'maybe_launch_domain_changed'
    ];
    }
    
    public function maybe_launch_domain_changed() {
     $base_url = trailingslashit(home_url());
     if(! get_option(self::LAST_BASE_URL_OPTION)) {
         update_option(self::LAST_BASE_URL_OPTION, $base_url);
        return;
      }
     $last_base_url = get_option(self::LAST_BASE_URL_OPTION);
    if($base_url === $last_base_url) {
     return;
    }
    update_option(self::LAST_BASE_URL_OPTION, $last_base_url);
    do_action('rocket_domain_changed');
   }
}

Then for the cache part we will have to add the following hook into the subscriber from the preload:

'rocket_domain_changed' => 'on_permalink_changed'

For the Cache part we can add the following logic to the AdminSubscriber to the events:

'rocket_domain_changed' => 'regenerate_configs'

with the following method:

public function regenerate_configs() {
     rocket_generate_advanced_cache_file();
}

Estimate the effort

Effort S

@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 Jan 17, 2023
@CrochetFeve0251 CrochetFeve0251 self-assigned this Jan 17, 2023
@piotrbak piotrbak added this to the 3.12.7 milestone Jan 25, 2023
@piotrbak piotrbak modified the milestones: 3.13.1, 3.13.2 Mar 22, 2023
@piotrbak piotrbak added the needs: documentation Issues which need to create or update a documentation label Apr 14, 2023
@piotrbak piotrbak removed this from the 3.13.2 milestone Apr 23, 2023
@piotrbak piotrbak added needs: copywriting status: blocked Issue or PR is blocked by external factor. labels May 21, 2023
@piotrbak piotrbak removed the status: blocked Issue or PR is blocked by external factor. label Jul 11, 2023
@piotrbak piotrbak added this to the 3.14.4 milestone Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort: [S] 1-2 days of estimated development time module: filesystem needs: copywriting 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. type: enhancement Improvements that slightly enhance existing functionality and are fast to implement
Projects
None yet
4 participants