Details
-
New Feature
-
Resolution: Unresolved
-
Major
-
None
-
1.1
-
None
-
Unknown
-
Description
When a page under workflow has pinned child pages and gets pubished, the pinned pages in the published version should be updated to point at the published subpages instead of the draft ones.
The WikiComponent listener snippet below listening to DcumentPublishingEvent could be turned into a Java class packaged as a subextension in order to implement this feature, possibly by moving the PinnedChildPages object update to an additional method in PinnedChildPagesService – updatePinnedChildPages(XWikiDocument document, DocumentReference originalReference) – performing an update before the document gets saved (the method could be reused in other contexts then, eg when performing a simple copy).
{{groovy}} import org.xwiki.model.reference.DocumentReference; import org.xwiki.workflowpublication.DocumentPublishingEvent;logger = services.logging.getLogger('XWiki.PinnedChildPagesPublishingListener');try { def event = xcontext.method.input.get(0); def publishedDocument = xcontext.method.input.get(1); logger.debug('A DocumentPublishingEvent occurred: {}', publishedDocument.fullName); def pinnedChildPagesObject = publishedDocument.getXObject(services.model.resolveDocument('XWiki.PinnedChildPagesClass')); if (pinnedChildPagesObject != null && pinnedChildPagesObject.getListValue('pinnedChildPages').size() > 0) { def draftDocumentReference = services.publicationworkflow.getDraftDocument(publishedDocument.getDocumentReference()) def pinnedChildPages = pinnedChildPagesObject.getListValue('pinnedChildPages'); logger.debug('Draft: {} - PinnedChildPages: {}', draftDocumentReference, pinnedChildPages); def updatedPinnedChildPages = new ArrayList(); pinnedChildPages.each { it -> def pinnedChildPageReference = services.model.resolveDocument(it); pinnedChildPageReference = pinnedChildPageReference.replaceParent(draftDocumentReference.parent, publishedDocument.getDocumentReference().parent); updatedPinnedChildPages.add(services.model.serialize(pinnedChildPageReference)); } logger.debug('Updated PinnedChildPages: {}', updatedPinnedChildPages); pinnedChildPagesObject.setStringListValue('pinnedChildPages', updatedPinnedChildPages); } } catch(Exception e) { logger.warn("Uncaught exception", e); } {{/groovy}}