Fix woo subscriptions being in staging mode when site is duplicated#262
Fix woo subscriptions being in staging mode when site is duplicated#262superdav42 merged 2 commits intomainfrom
Conversation
|
Warning Rate limit exceeded@superdav42 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 11 minutes and 14 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
WalkthroughModified the Site Duplicator class to improve error handling in the override_site method by inverting success checks, and added a new method to reset WooCommerce Subscriptions staging mode after site duplication completes. Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant Site Duplicator
participant WP Context
participant WCS
participant Options
Caller->>Site Duplicator: process_duplication()
activate Site Duplicator
Note over Site Duplicator: Perform duplication actions
Site Duplicator->>Site Duplicator: reset_woocommerce_subscriptions_staging_mode()
activate Site Duplicator
Site Duplicator->>WP Context: Validate site_id
alt Invalid site_id
Site Duplicator-->>Caller: Return early
end
Site Duplicator->>WCS: Check if WooCommerce Subscriptions active
Site Duplicator->>WP Context: switch_to_blog(site_id)
activate WP Context
Site Duplicator->>Site Duplicator: Generate obfuscated site URL
Site Duplicator->>Options: Update wc_subscriptions_siteurl
Site Duplicator->>Options: Delete wcs_ignore_duplicate_siteurl_notice
deactivate WP Context
Site Duplicator->>WP Context: restore_current_blog()
deactivate Site Duplicator
deactivate Site Duplicator
Site Duplicator-->>Caller: Return result
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
inc/helpers/class-site-duplicator.php (2)
347-355: Consider adding validation for URL parsing edge cases.The obfuscation logic is sound, but consider adding validation for edge cases where
wp_parse_url()might returnnullorfalsefor the scheme, or where the resulting URL might be malformed.// Generate the obfuscated key that WooCommerce Subscriptions uses - // It inserts '_[wc_subscriptions_siteurl]_' in the middle of the URL + // It inserts '_[wc_subscriptions_siteurl]_' in the middle of the domain/path portion $scheme = wp_parse_url($site_url, PHP_URL_SCHEME) . '://'; + + // Validate scheme was parsed successfully + if ($scheme === '://') { + wu_log_add('site-duplication', sprintf('Failed to parse scheme from site URL %s during WCS staging mode reset', $site_url), LogLevel::WARNING); + return; + } + $site_url = str_replace($scheme, '', $site_url);
358-361: Consider logging the WCS option updates for debugging.Adding logging for the option updates would help with debugging if staging mode issues persist or if the reset operation fails silently.
// Update the WooCommerce Subscriptions site URL option - update_option('wc_subscriptions_siteurl', $obfuscated_url); + $updated = update_option('wc_subscriptions_siteurl', $obfuscated_url); + + if ($updated) { + wu_log_add('site-duplication', sprintf('Reset WCS staging mode for site %d', $site_id), LogLevel::INFO); + } // Delete the "ignore notice" option to ensure a clean state delete_option('wcs_ignore_duplicate_siteurl_notice');
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
inc/helpers/class-site-duplicator.php(3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
inc/helpers/class-site-duplicator.php (1)
inc/functions/helper.php (1)
wu_log_add(208-211)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: cypress (8.2, chrome)
🔇 Additional comments (2)
inc/helpers/class-site-duplicator.php (2)
142-155: Improved error handling looks good.The change to explicitly check
is_wp_error($saved)instead of a truthy check is more correct, as WordPress save methods can returnWP_Errorobjects (which are truthy). The error logging and early return pattern is well-implemented.
267-271: Well-placed staging mode reset.The call to reset WooCommerce Subscriptions staging mode is correctly positioned after all duplication operations complete, ensuring the new site won't be incorrectly detected as a staging environment.
Summary by CodeRabbit
Bug Fixes
New Features