Search in sources :

Example 1 with XarExtensionExtension

use of org.xwiki.extension.xar.XarExtensionExtension in project xwiki-platform by xwiki.

the class Packager method reset.

/**
 * @since 9.3RC1
 */
public void reset(DocumentReference reference, DocumentReference authorReference) throws IOException, XarException, XWikiException, XarExtensionExtension {
    Collection<XarInstalledExtension> installedExtensions = getXarInstalledExtensionRepository().getXarInstalledExtensions(reference);
    if (!installedExtensions.isEmpty()) {
        XarInstalledExtension extension = installedExtensions.iterator().next();
        // Remove the version if any since it does not make sense in a XAR
        DocumentReference documentReference = cleanDocumentReference(reference);
        XWikiDocument document = getXWikiDocument(documentReference, extension);
        if (document != null) {
            XWikiContext xcontext = this.xcontextProvider.get();
            // Get database document
            XWikiDocument databaseDocument = xcontext.getWiki().getDocument(documentReference, xcontext);
            // Override data of database document with extension document
            databaseDocument.apply(document, true);
            // Make sure new version will have the right author
            databaseDocument.setAuthorReference(authorReference);
            databaseDocument.setContentAuthorReference(authorReference);
            // Force generating new version
            databaseDocument.setMetaDataDirty(true);
            databaseDocument.setContentDirty(true);
            // Save
            xcontext.getWiki().saveDocument(databaseDocument, "Reset document from extension [" + extension + "]", xcontext);
        } else {
            throw new XarExtensionExtension("Can't find any document with reference [" + documentReference + "] in extension [" + extension.getId() + "]");
        }
    } else {
        throw new XarExtensionExtension("Can't find any installed extension associated with the document reference [" + reference + "]");
    }
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XarInstalledExtension(org.xwiki.extension.xar.internal.repository.XarInstalledExtension) XarExtensionExtension(org.xwiki.extension.xar.XarExtensionExtension) XWikiContext(com.xpn.xwiki.XWikiContext) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) DocumentReference(org.xwiki.model.reference.DocumentReference)

Aggregations

XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 XarExtensionExtension (org.xwiki.extension.xar.XarExtensionExtension)1 XarInstalledExtension (org.xwiki.extension.xar.internal.repository.XarInstalledExtension)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)1