Jump to content

Module: Adapt URLs after Page Cloning


BitPoet
 Share

Recommended Posts

Here's a short module that adapts href and src links in CKEditor fields when a page is cloned:

ProcessPageCloneAdaptUrls

Normally, href links and image urls still point to the original page's assets folder when you copy (clone) a page. This module hooks into Pages::cloned and adapts all src and href attributes found in HTML tags that point to the old assets directory, rewriting them to link to the copy's assets.

This module was motivated by a feature request (#1687) on PW's github tracker.

Requires: ProcessPageClone (Core, but not installed by default)

Status: beta

Download: git repo

Module directory

Feedback: welcome! :)

Edited by BitPoet
  • Like 4
Link to comment
Share on other sites

I haven't tested it with extensively large subtrees, only ones of about 30 pages. I'm still a bit of two minds whether limiting replacements to href and src attributes is in fact necessary. If not, a direct database approach may be worth thinking about. Otherwise, the multiple statements necessary to catch all variants of attributes and quotes probably outweigh the memory and CPU impact of the regex replacement. I guess a lot depends on the environment too - cloning huge trees may run into memory or time limits in itself.

Now that I've written this, delaying the rewrites may be an option as well - just collecting ids in Pages::cloned if recursion level is > 0, then processing the rewrites after the last call to Pages::cloned.

Link to comment
Share on other sites

Update: thanks to LostKobrakai's prompting, I've looked at delayed operation and implemented a mix of immediate and delayed updates. This is a major change, so the code is still in alpha and available in the dev branch at github (there are also some screenshots to be found in the readme).

I've incorporated an admin page where pending updates can be seen and triggered, but the whole thing is still lacking permissions checks (both for visibility of the admin page and for listing viewable/editable pages), which may require some big changes to the code (perhaps even split hooks and update functionality into separate modules). Of course, if that happens, I'll make sure updating works.

  • Every page clone now stores a todo entry in the database.
  • When cloning a page, URL updates are triggered after the last page has been cloned and at most 50 pages are updated (configurable in module settings).
  • The rest of the updates have to be triggered manually in the admin page (for now).

So if anybody wants to give it a try, I'd love to get some feedback.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...