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 + "]");
}
}
Aggregations