Skip to content

fix: refresh Divi clone generated caches#1432

Merged
superdav42 merged 3 commits into
mainfrom
fix/divi-cache-refresh
Jun 16, 2026
Merged

fix: refresh Divi clone generated caches#1432
superdav42 merged 3 commits into
mainfrom
fix/divi-cache-refresh

Conversation

@superdav42

@superdav42 superdav42 commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Replace cloned wp-content/uploads/sites/{template_blog_id} references with the cloned blog ID during database replacement, including JSON-escaped paths.
  • Clear copied Divi generated CSS postmeta/options before forcing regenerated static CSS.
  • Flush known page caches after Divi clone cache invalidation so stale HTML does not keep pointing at old generated CSS versions.

Verification

  • php -l inc/duplication/data.php && php -l inc/compat/class-general-compat.php && php -l tests/WP_Ultimo/General_Compat_Test.php && php -l tests/WP_Ultimo/Duplication/MUCD_Data_Test.php
  • vendor/bin/phpcs inc/compat/class-general-compat.php inc/duplication/data.php
  • vendor/bin/phpstan analyse inc/compat/class-general-compat.php inc/duplication/data.php tests/WP_Ultimo/General_Compat_Test.php tests/WP_Ultimo/Duplication/MUCD_Data_Test.php
  • Pre-commit hook passed for staged production PHP files.
  • Live deployment smoke test passed on a fresh Divi clone from template blog 25:
    • wu_flush_known_caches fired during duplication.
    • Clone content rewrote wp-content/uploads/sites/25 to the new clone upload path.
    • Copied Divi cache postmeta/options were absent before first frontend load.
    • First normal frontend load returned 200 without stale template cache references.
    • Public et-core-unified-deferred-5.min.css for the clone returned 200 and contained the previously missing Divi rules: padding-top:20vh, .et_pb_image_0, and position:absolute!important.
  • Disposable live test clone was removed after verification.

Notes

  • Focused PHPUnit filters are blocked locally because wp-tests-config.php is missing.
  • Broad PHPCS on tests/WP_Ultimo/Duplication/MUCD_Data_Test.php still reports pre-existing test-file style issues outside this patch.

Summary by CodeRabbit

  • Bug Fixes

    • Improved site duplication cache clearing to properly remove generated cache metadata and flush page caches on cloned sites.
    • Enhanced upload path replacement logic during site duplication to correctly handle serialized data.
  • Tests

    • Added comprehensive test coverage for cache clearing and upload path replacement in duplication scenarios.
  • Chores

    • Code cleanup and improved internal validation.

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 60f877d7-b69a-4f57-af41-2ddbd1230a47

📥 Commits

Reviewing files that changed from the base of the PR and between b936bb7 and bcca3d3.

📒 Files selected for processing (4)
  • inc/duplication/data.php
  • inc/duplication/duplicate.php
  • inc/integrations/providers/laravel-forge/class-laravel-forge-integration.php
  • tests/WP_Ultimo/Duplication/MUCD_Data_Test.php
✅ Files skipped from review due to trivial changes (2)
  • inc/integrations/providers/laravel-forge/class-laravel-forge-integration.php
  • inc/duplication/duplicate.php

📝 Walkthrough

Walkthrough

clear_divi_static_css_cache() is extended to delete cloned Divi post meta/options and flush page caches in addition to filesystem cache. The Divi cache directory enumerator is rewritten to return structured {root, dir} entries with uploads fallback. Site duplication gains upload path-segment (wp-content/uploads/sites/{id}) replacement including JSON-escaped forms. Tests cover both changes.

Changes

Divi Cache Invalidation

Layer / File(s) Summary
Cache directory enumeration and deletion boundary
inc/compat/class-general-compat.php
get_divi_static_css_cache_directories() is rewritten to return {root, dir} structured entries covering network-scoped, legacy, and uploads-based et-cache paths with deduplication. delete_divi_static_css_cache_directory() gains an explicit cache_root parameter instead of deriving it internally.
Meta/options deletion helpers and orchestration
inc/compat/class-general-compat.php
Adds private helpers to delete copied Divi static CSS post meta and options on the cloned blog, adds flush_divi_cloned_site_page_cache() to flush via Ultimate Multisite's cache manager, and updates clear_divi_static_css_cache() to call all three steps in sequence.
Multisite PHPUnit tests for uploads fallback and metadata clearing
tests/WP_Ultimo/General_Compat_Test.php
test_clear_divi_static_css_cache_deletes_uploads_fallback_cache_only() asserts only the targeted blog's et-cache directory is removed. test_clear_divi_static_css_cache_deletes_cloned_site_divi_cache_metadata_only() asserts only the targeted blog's post meta and options are cleared and wu_flush_known_caches fires exactly once.

Upload Path-Segment Replacement in Site Duplication

Layer / File(s) Summary
Upload path segment replacement and data.php cleanup
inc/duplication/data.php
db_update_data() gains $string_to_replace and $json_replacements entries for wp-content/uploads/sites/{from_id}{to_id} path segments. copy_data() drops an unused variable assignment. do_sql_query() switches to strict string comparison for last_error. PHPCS ignore annotations are added to get_primary_key() and try_replace() without control-flow changes.
PHPUnit test for serialized upload path replacement
tests/WP_Ultimo/Duplication/MUCD_Data_Test.php
test_try_replace_upload_site_id_path_preserves_serialized_data() builds serialized settings with origin sites/25 URLs, runs two try_replace passes (raw and JSON-escaped), and asserts valid unserialization, numeric data preservation, absence of sites/25, and correct sites/47 values throughout.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant clear_divi_static_css_cache
  participant delete_divi_cloned_css_post_meta
  participant delete_divi_cloned_css_options
  participant get_divi_static_css_cache_directories
  participant delete_divi_static_css_cache_directory
  participant flush_divi_cloned_site_page_cache

  Caller->>clear_divi_static_css_cache: call(site_id)
  clear_divi_static_css_cache->>delete_divi_cloned_css_post_meta: delete Divi CSS post meta on cloned blog
  clear_divi_static_css_cache->>delete_divi_cloned_css_options: delete Divi CSS options on cloned blog
  clear_divi_static_css_cache->>get_divi_static_css_cache_directories: enumerate {root, dir} entries
  get_divi_static_css_cache_directories-->>clear_divi_static_css_cache: network + legacy + uploads fallback entries
  loop each {root, dir} entry
    clear_divi_static_css_cache->>delete_divi_static_css_cache_directory: delete(dir, cache_root)
  end
  clear_divi_static_css_cache->>flush_divi_cloned_site_page_cache: trigger wu_flush_known_caches
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Ultimate-Multisite/ultimate-multisite#1369: Modifies General_Compat::clear_divi_static_css_cache() with stronger path-root validation for Divi cache directory deletion and matching General_Compat_Test coverage — directly precedes this PR's structured root/dir enumeration approach.
  • Ultimate-Multisite/ultimate-multisite#1403: Modifies clear_divi_static_css_cache() and helpers to enumerate {root, dir} Divi et-cache locations including uploads fallback, with multisite regression tests for targeted cache deletion — overlaps directly with the Divi cache enumerator rewrite here.
  • Ultimate-Multisite/ultimate-multisite#334: Changes MUCD_Data URL/try_replace replacement logic including JSON-escaped handling and extends MUCD_Data_Test for serialized/JSON replacement — directly related to the upload path-segment replacement additions in this PR.

Suggested labels

origin:interactive, status:in-review

🐇 Hop hop, the cache is clear today,
Old Divi meta has been swept away!
The uploads path now follows the clone,
No sites/25 left all alone.
Root guards the dir, strict checks are set —
The cleanest multisite you've seen yet! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately summarizes the main changes: addressing Divi cache management issues when cloning WordPress sites, specifically invalidating and refreshing generated caches.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/divi-cache-refresh

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@superdav42

Copy link
Copy Markdown
Collaborator Author

Rebase needed — PR has merge conflicts and no origin:* label

This PR has merge conflicts against the default branch and lacks both origin:interactive and origin:worker labels. The pulse merge pass treats it as the label-agnostic stuck state (t3193) and surfaces it here with a one-shot rebase nudge.

To resolve

git fetch origin
git checkout fix/divi-cache-refresh
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Or use the GitHub web UI's Update branch button if the conflicts are trivial enough.

Why this PR slipped through the existing nudges

The existing rebase-nudge family (_post_rebase_nudge_on_interactive_conflicting, _post_rebase_nudge_on_contributor_conflicting, _post_rebase_nudge_on_worker_conflicting) keys on the origin:* labels. PRs created without those labels — typically docs/migration commits made directly via the web UI or via a worker that didn't apply its origin label — were silently re-evaluated every cycle without surfacing.

Posted automatically by pulse-merge-stuck.sh (t3193 / GH#21895).


aidevops.sh v3.20.85 automated scan.

@github-actions

Copy link
Copy Markdown

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

@superdav42 superdav42 merged commit bc05a8b into main Jun 16, 2026
11 checks passed
@superdav42

Copy link
Copy Markdown
Collaborator Author

Summary

  • Replace cloned wp-content/uploads/sites/{template_blog_id} references with the cloned blog ID during database replacement, including JSON-escaped paths.
  • Clear copied Divi generated CSS postmeta/options before forcing regenerated static CSS.
  • Flush known page caches after Divi clone cache invalidation so stale HTML does not keep pointing at old generated CSS versions.

Verification

  • php -l inc/duplication/data.php && php -l inc/compat/class-general-compat.php && php -l tests/WP_Ultimo/General_Compat_Test.php && php -l tests/WP_Ultimo/Duplication/MUCD_Data_Test.php
  • vendor/bin/phpcs inc/compat/class-general-compat.php inc/duplication/data.php
  • vendor/bin/phpstan analyse inc/compat/class-general-compat.php inc/duplication/data.php tests/WP_Ultimo/General_Compat_Test.php tests/WP_Ultimo/Duplication/MUCD_Data_Test.php
  • Pre-commit hook passed for staged production PHP files.
  • Live deployment smoke test passed on a fresh Divi clone from template blog 25:
    • wu_flush_known_caches fired during duplication.
    • Clone content rewrote wp-content/uploads/sites/25 to the new clone upload path.
    • Copied Divi cache postmeta/options were absent before first frontend load.
    • First normal frontend load returned 200 without stale template cache references.
    • Public et-core-unified-deferred-5.min.css for the clone returned 200 and contained the previously missing Divi rules: padding-top:20vh, .et_pb_image_0, and position:absolute!important.
  • Disposable live test clone was removed after verification.

Notes

  • Focused PHPUnit filters are blocked locally because wp-tests-config.php is missing.
  • Broad PHPCS on tests/WP_Ultimo/Duplication/MUCD_Data_Test.php still reports pre-existing test-file style issues outside this patch.


Merged via PR #1432 to main.
Merged by deterministic merge pass (pulse-wrapper.sh).


aidevops.sh v3.20.85 spent 19m on this as a headless bash routine.

@superdav42 superdav42 added the review-feedback-scanned Merged PR already scanned for quality feedback label Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review-feedback-scanned Merged PR already scanned for quality feedback

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant