How can I store data with a page or macro so that it's copied when the page is copied?

I have a p2 macro that stores data in AO. When the page is copied, I want to copy the macro’s data to new AO records for macros on the new page. To do this, I need to know what the source page of a copy was when rendering a macro on the copied page.

At first I tried listening to the page copy events but after testing these seem to only be fired when the page tree is copied, but not when an individual page is copied. Next I tried setting ContentEntityObject properties, both via CEO.setProperty and using the ContentPropertyManager. Values set with these methods do not persist after a page is copied.

I also tried finding a way to create an invisible (to the user) macro param or macro body that would allow me to propagate macro state across page copies using the storage format data. So far, I have not found a way to encode data in storage format that is invisible to a user.

The data would ideally be readable and writable during the execute method of the server-side macro class. This is normally a bodiless macro, so I would prefer to not have an editable body in the page editor.

Is there a way to set a content property that will persist through a page copy operation, to encode an invisible macro param, or encode invisible data into a macro body, any of which would be present in a copied page environment?


Welcome to the ever same problem that I encounter with macros. Because macros lack a unique identifier, all of these copy operations are inherently flawed and difficult. Not even Atlassian gets it right with checking / unchecking tasks (not quite a macro, but same problem - lack of unique ids), while a draft exists (data losing bug, but ranked with Severity “Minor”, no workaround).

To give some ideas:

  • I’d expect the PageCopy event to work, if not, you could also check for PageCreated or similar. Some event must be fired. Whatever it is, this will help identify the target page. As for identifying the source - not sure if this is possible via an event.
  • Your macro could store the current page id, i.e., upon saving a page, you could update the page id in the macro. Just use a macro parameter and hide it from the user, you can hide parameters in the atlassian-plugin.xml.
  • Once a page is copied and you detect it via one of the events, parse the page for your macro; get the page id; check that it differs and copy the macro data.

Thanks. I found the solution of using a hidden macro param earlier today. I Googled the heck out of that for quite a while and never turned up any indication that it was possible in documentation or discussions. Eventually I tried it out of desperation and it just seems to work, so problem solved. It’s anything but clear, however.

The PageCopy event only fires for me when copying a page tree, not a single page (using the normal “Copy” menu item). I forget whether I tried any other events as well, it may be that I wasn’t aware of that one at the time.

Nice tips, Dennis. Any ideas on how to save data for a page with no macros?

Hi @jason,

not sure if this is as straight forward compared to the macros.
We know from Unable to detect page copy event when copying page without children that two events are fired. But I doubt that you can get the source page from that.

ContentEntityProperties are not copied, according to @BobBergman, thus there is no easy way to store the current page-id in the entity properties and use that for comparison.

No other ideas right now. Let me think about it some more.

1 Like