-
Notifications
You must be signed in to change notification settings - Fork 4
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
Revert aggressive page deletion - Flush cache and sleep #1304
Revert aggressive page deletion - Flush cache and sleep #1304
Conversation
Size Change: 0 B Total Size: 196 kB ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I can offer much about the specific implementation but it's working as expected!
[21-Sep-2023 12:01:06 UTC] WooExpress: Operation: (1695297666.8333) woocommerce_create_pages: INITIALIZED
[21-Sep-2023 12:01:06 UTC] WooExpress: Operation: (1695297666.8335) woocommerce_create_pages: START TRANSACTION
[21-Sep-2023 12:01:06 UTC] WooExpress: Operation: (1695297666.8341) woocommerce_create_pages: DELETING WOOCOMMERCE PAGES
[21-Sep-2023 12:01:06 UTC] WooExpress: Operation: (1695297666.8421) woocommerce_create_pages: deleted page shop
[21-Sep-2023 12:01:06 UTC] WooExpress: Operation: (1695297666.8472) woocommerce_create_pages: deleted page cart
[21-Sep-2023 12:01:06 UTC] WooExpress: Operation: (1695297666.852) woocommerce_create_pages: deleted page checkout
[21-Sep-2023 12:01:06 UTC] WooExpress: Operation: (1695297666.8568) woocommerce_create_pages: deleted page my-account
[21-Sep-2023 12:01:06 UTC] WooExpress: Operation: (1695297666.8617) woocommerce_create_pages: deleted page refund_returns
[21-Sep-2023 12:01:06 UTC] WooExpress: Operation: (1695297666.8621) woocommerce_create_pages: DELETING WOOCOMMERCE PAGE OPTIONS
[21-Sep-2023 12:01:06 UTC] WooExpress: Operation: (1695297666.8671) woocommerce_create_pages: deleted option woocommerce_shop_page_id : 14
[21-Sep-2023 12:01:06 UTC] WooExpress: Operation: (1695297666.8678) woocommerce_create_pages: deleted option woocommerce_cart_page_id : 15
[21-Sep-2023 12:01:06 UTC] WooExpress: Operation: (1695297666.8684) woocommerce_create_pages: deleted option woocommerce_checkout_page_id : 16
[21-Sep-2023 12:01:06 UTC] WooExpress: Operation: (1695297666.869) woocommerce_create_pages: deleted option woocommerce_myaccount_page_id : 17
[21-Sep-2023 12:01:06 UTC] WooExpress: Operation: (1695297666.8738) woocommerce_create_pages: deleted option woocommerce_refund_returns_page_id : 18
[21-Sep-2023 12:01:06 UTC] WooExpress: Operation: (1695297666.8738) woocommerce_create_pages: DELETING HEADSTART PAGES
[21-Sep-2023 12:01:06 UTC] WooExpress: Operation: (1695297666.8763) woocommerce_create_pages: FLUSH CACHE AND SLEEP
[21-Sep-2023 12:01:07 UTC] WooExpress: Operation: (1695297667.377) woocommerce_create_pages: CREATING PAGES
[21-Sep-2023 12:01:07 UTC] WooExpress: Operation: (1695297667.3786) woocommerce_create_pages: woocommerce_create_pages filter - updated content to use cart/checkout blocks
[21-Sep-2023 12:01:07 UTC] WooExpress: Operation: (1695297667.3818) woocommerce_create_pages: woocommerce_create_pages filter - pages:shop, cart, checkout, myaccount, refund_returns
[21-Sep-2023 12:01:07 UTC] WooExpress: Operation: (1695297667.3824) woocommerce_create_pages: woocommerce_create_page_id force create slug: shop
[21-Sep-2023 12:01:07 UTC] WooExpress: Operation: (1695297667.393) woocommerce_create_pages: woocommerce_page_created action - id: 19, slug: shop
[21-Sep-2023 12:01:07 UTC] WooExpress: Operation: (1695297667.394) woocommerce_create_pages: woocommerce_create_page_id force create slug: cart
[21-Sep-2023 12:01:07 UTC] WooExpress: Operation: (1695297667.4034) woocommerce_create_pages: woocommerce_page_created action - id: 20, slug: cart
[21-Sep-2023 12:01:07 UTC] WooExpress: Operation: (1695297667.4135) woocommerce_create_pages: woocommerce_create_page_id force create slug: checkout
[21-Sep-2023 12:01:07 UTC] WooExpress: Operation: (1695297667.4223) woocommerce_create_pages: woocommerce_page_created action - id: 21, slug: checkout
[21-Sep-2023 12:01:07 UTC] WooExpress: Operation: (1695297667.4325) woocommerce_create_pages: woocommerce_create_page_id force create slug: my-account
[21-Sep-2023 12:01:07 UTC] WooExpress: Operation: (1695297667.4395) woocommerce_create_pages: woocommerce_page_created action - id: 22, slug: my-account
[21-Sep-2023 12:01:07 UTC] WooExpress: Operation: (1695297667.4497) woocommerce_create_pages: woocommerce_create_page_id force create slug: refund_returns
[21-Sep-2023 12:01:07 UTC] WooExpress: Operation: (1695297667.4591) woocommerce_create_pages: woocommerce_page_created action - id: 23, slug: refund_returns
[21-Sep-2023 12:01:07 UTC] WooExpress: Operation: (1695297667.4688) woocommerce_create_pages: finished WC_Install::create_pages
[21-Sep-2023 12:01:07 UTC] WooExpress: Operation: (1695297667.4817) woocommerce_create_pages: created menu items
[21-Sep-2023 12:01:07 UTC] WooExpress: Operation: (1695297667.4827) woocommerce_create_pages: COMMIT and cache deleted
@@ -4,7 +4,7 @@ | |||
* | |||
* @package WC_Calypso_Bridge/Classes | |||
* @since 1.0.0 | |||
* @version 2.2.13 | |||
* @version x.x.x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this correct or does it need to be an actual version number? I'm not super familiar with how the versioning works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we bump the x.x.x
s when we're about to release, as we don't know in advance in which version this PR will make it.
|
||
return $valid_page_found; | ||
$this->write_to_log( $operation, 'woocommerce_create_page_id force create slug: ' . $slug ); | ||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than always forcing a recreate, do we want to follow the same logic as the delete code and ignore the page if it was created more than 10 minutes ago?
It feels like the current approach will not delete old Woo pages (because they're older than 10 minutes), but will always create a new page for the same purpose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are two scenarios to consider
Business with WooCommerce already installed
The one time job won't run, as it will bail out early - See
wc-calypso-bridge/includes/class-wc-calypso-bridge-setup.php
Lines 226 to 232 in dac76a8
// Set the operation as completed if the store is active for more than 10 minutes. | |
if ( WCAdminHelper::is_wc_admin_active_for( 5 * MINUTE_IN_SECONDS ) ) { | |
update_option( $this->option_prefix . $operation, 'completed', 'no' ); | |
$this->write_to_log( $operation, 'completed (10 minutes)' ); | |
return; | |
} |
Simple site with shop or any page with the same slugs as Woo
That's the reason we force the page creation. Imagine having a blog and on the /shop
page having info about your physical shop and on the /cart
page having info about shopping carts (just saying :) ) and they decide to upgrade to Ecommerce after 20 days.
We don't want those pages to be deleted if they are old (10 minutes+), and we want WooCommerce to create new pages with the same slugs (rather than claiming the existing and using them as Woo ones)
What will happen
- The one time job will run
- Ignore page deletion for
cart
andshop
- WooCommerce will create
my-account
,refund_returns
,checkout
andcart-2
,shop-2
and not touchcart
andshop
New Ecommerce/WooExpress sites
All Woo related pages will be deleted, and forced to be recreated, so no probs here.
$current_time_gmt_ts = current_time( 'U', true ); | ||
$diff_ts = $current_time_gmt_ts - $page_gmt_ts; | ||
|
||
if ( $diff_ts > 10 * MINUTE_IN_SECONDS ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to ignore old Headstart pages as well? Note that we can look at the _hs_old_id
post_meta
field if we do want to delete Headstart pages in all cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same principle as in my previous comment;
If headstart pages are old, we don't know if they have been modified for whatever reason. So if they are old, we keep them.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense -- once they're too old, we don't want to make any assumptions about those pages.
|
||
$page = get_page_by_path( $slug, ARRAY_A ); | ||
|
||
if ( is_array( $page ) && isset( $page['ID'] ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally minor, non-blocking suggestion: this might be a bit more readable as an early return.
if ( is_array( $page ) && isset( $page['ID'] ) ) { | |
if ( ! is_array( $page ) || ! isset( $page['ID'] ) ) { | |
return; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm all in for readability and bail out early! Thanks!
Co-authored-by: daledupreez <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look good to me, though I have one minor note about a stale inline comment.
Screenshots
Log output
[26-Sep-2023 11:21:57 UTC] WooExpress: Operation: woocommerce_create_pages: (1695727317.6997) INITIALIZED
[26-Sep-2023 11:21:57 UTC] WooExpress: Operation: woocommerce_create_pages: (1695727317.7) START TRANSACTION
[26-Sep-2023 11:21:57 UTC] WooExpress: Operation: woocommerce_create_pages: (1695727317.7004) DELETING WOOCOMMERCE PAGES
[26-Sep-2023 11:21:57 UTC] WooExpress: Operation: woocommerce_create_pages: (1695727317.7086) deleted page shop
[26-Sep-2023 11:21:57 UTC] WooExpress: Operation: woocommerce_create_pages: (1695727317.7141) deleted page cart
[26-Sep-2023 11:21:57 UTC] WooExpress: Operation: woocommerce_create_pages: (1695727317.7196) deleted page checkout
[26-Sep-2023 11:21:57 UTC] WooExpress: Operation: woocommerce_create_pages: (1695727317.725) deleted page my-account
[26-Sep-2023 11:21:57 UTC] WooExpress: Operation: woocommerce_create_pages: (1695727317.7307) deleted page refund_returns
[26-Sep-2023 11:21:57 UTC] WooExpress: Operation: woocommerce_create_pages: (1695727317.7311) DELETING WOOCOMMERCE PAGE OPTIONS
[26-Sep-2023 11:21:57 UTC] WooExpress: Operation: woocommerce_create_pages: (1695727317.7383) deleted option woocommerce_shop_page_id : 30
[26-Sep-2023 11:21:57 UTC] WooExpress: Operation: woocommerce_create_pages: (1695727317.7392) deleted option woocommerce_cart_page_id : 31
[26-Sep-2023 11:21:57 UTC] WooExpress: Operation: woocommerce_create_pages: (1695727317.74) deleted option woocommerce_checkout_page_id : 32
[26-Sep-2023 11:21:57 UTC] WooExpress: Operation: woocommerce_create_pages: (1695727317.7408) deleted option woocommerce_myaccount_page_id : 33
[26-Sep-2023 11:21:57 UTC] WooExpress: Operation: woocommerce_create_pages: (1695727317.7476) deleted option woocommerce_refund_returns_page_id : 34
[26-Sep-2023 11:21:57 UTC] WooExpress: Operation: woocommerce_create_pages: (1695727317.7476) DELETING HEADSTART PAGES
[26-Sep-2023 11:21:57 UTC] WooExpress: Operation: woocommerce_create_pages: (1695727317.7502) FLUSH CACHE AND SLEEP
[26-Sep-2023 11:21:58 UTC] WooExpress: Operation: woocommerce_create_pages: (1695727318.251) CREATING PAGES
[26-Sep-2023 11:21:58 UTC] WooExpress: Operation: woocommerce_create_pages: (1695727318.2584) woocommerce_create_pages filter - updated content to use cart/checkout blocks
[26-Sep-2023 11:21:58 UTC] WooExpress: Operation: woocommerce_create_pages: (1695727318.2614) woocommerce_create_pages filter - pages:shop, cart, checkout, myaccount, refund_returns
[26-Sep-2023 11:21:58 UTC] WooExpress: Operation: woocommerce_create_pages: (1695727318.262) woocommerce_create_page_id force create slug: shop
[26-Sep-2023 11:21:58 UTC] WooExpress: Operation: woocommerce_create_pages: (1695727318.2722) woocommerce_page_created action - id: 35, slug: shop
[26-Sep-2023 11:21:58 UTC] WooExpress: Operation: woocommerce_create_pages: (1695727318.2866) woocommerce_create_page_id force create slug: cart
[26-Sep-2023 11:21:58 UTC] WooExpress: Operation: woocommerce_create_pages: (1695727318.296) woocommerce_page_created action - id: 36, slug: cart
[26-Sep-2023 11:21:58 UTC] WooExpress: Operation: woocommerce_create_pages: (1695727318.3098) woocommerce_create_page_id force create slug: checkout
[26-Sep-2023 11:21:58 UTC] WooExpress: Operation: woocommerce_create_pages: (1695727318.3178) woocommerce_page_created action - id: 37, slug: checkout
[26-Sep-2023 11:21:58 UTC] WooExpress: Operation: woocommerce_create_pages: (1695727318.3312) woocommerce_create_page_id force create slug: my-account
[26-Sep-2023 11:21:58 UTC] WooExpress: Operation: woocommerce_create_pages: (1695727318.3375) woocommerce_page_created action - id: 38, slug: my-account
[26-Sep-2023 11:21:58 UTC] WooExpress: Operation: woocommerce_create_pages: (1695727318.3511) woocommerce_create_page_id force create slug: refund_returns
[26-Sep-2023 11:21:58 UTC] WooExpress: Operation: woocommerce_create_pages: (1695727318.3611) woocommerce_page_created action - id: 39, slug: refund_returns
[26-Sep-2023 11:21:58 UTC] WooExpress: Operation: woocommerce_create_pages: (1695727318.3742) finished WC_Install::create_pages
[26-Sep-2023 11:21:58 UTC] WooExpress: Operation: woocommerce_create_pages: (1695727318.3864) created menu items
[26-Sep-2023 11:21:58 UTC] WooExpress: Operation: woocommerce_create_pages: (1695727318.3874) COMMIT and cache deleted
@@ -224,7 +224,7 @@ public function woocommerce_create_pages_callback() { | |||
$this->write_to_log( $operation, 'INITIALIZED' ); | |||
|
|||
// Set the operation as completed if the store is active for more than 10 minutes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: the comment says 10 minutes, but the code is now set to 5 minutes.
// Set the operation as completed if the store is active for more than 10 minutes. | |
// Set the operation as completed if the store is active for more than 5 minutes. |
Changes proposed in this Pull Request:
Closes #1302 closes #1303 .
TLDR;
Instead of deleting all pages except for
'faq', 'contact-us', 'blog'
, we now delete only WooCommerce related pages.We're extra careful, and check if the Woo Page we're about to delete is old.
For example, if we have a simple site with a page called
shop
, when an Ecommerce plan is purchased, this page won't be overwritten. but instead we instruct WooCommerce to create a new page"Old" pages, are considered those that are older than 10 minutes.
How to test the changes in this Pull Request:
https://wordpress.com/wp-admin/network/admin.php?page=store-admin&action=blog_id_search&id=https%3A%2F%2FYOURTESTSITE.wordpress.com
Transfers to Atomic dev server pool
and clickAdd dev blog
Settings > Hosting management
and activate SFTP/SSH access (keep the credentials handy for the SSH and SCP commands further down)fix/1302-1303-revert-page-deletion-fix-cache
scp ./includes/class-wc-calypso-bridge-setup.php [email protected]:/srv/htdocs/wp-content/mu-plugins/wpcomsh/vendor/automattic/wc-calypso-bridge/includes
to your WOA DEV sitetail -f -n1000 /tmp/php-errors
to see the logfile (keep it open)Upgrades
and upgrade to Ecommerce planYou would see something similar to in your terminal - Please copy/paste it in your comments when you wrap up the test.
Other information:
FOR PR REVIEWER ONLY: