use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.
the class DefaultSearchSuggestCustomConfigDeleter method deleteSearchSuggestCustomConfig.
@Override
public void deleteSearchSuggestCustomConfig(String wikiId) throws XWikiException {
XWikiContext xcontext = xcontextProvider.get();
XWiki xwiki = xcontext.getWiki();
DocumentReference searchConfigDocRef = new DocumentReference(wikiId, XWiki.SYSTEM_SPACE, "SearchSuggestConfig");
DocumentReference searchConfigClass = new DocumentReference(wikiId, XWiki.SYSTEM_SPACE, "SearchSuggestSourceClass");
XWikiDocument searchConfigDoc = xwiki.getDocument(searchConfigDocRef, xcontext);
// Get the config objects
List<BaseObject> objects = searchConfigDoc.getXObjects(searchConfigClass);
if (objects != null) {
boolean found = false;
// Find the object to remove
for (BaseObject object : objects) {
if (object == null) {
continue;
}
// Look if the object is to remove
String name = object.getStringValue("name");
if (name.equals("platform.workspace.searchSuggestSourceWorkspaces")) {
String query = object.getStringValue("query");
String engine = object.getStringValue("engine");
String url = object.getStringValue("url");
if (isSolrObject(query, engine, url) || isLuceneObject(query, engine, url)) {
searchConfigDoc.removeXObject(object);
found = true;
}
}
}
if (found) {
xwiki.saveDocument(searchConfigDoc, "Remove object previously introduced by WorkspaceManager.Install", xcontext);
}
}
}
use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.
the class WorkspacesMigration method isWorkspace.
private boolean isWorkspace(String wikiId) throws DataMigrationException, XWikiException {
// The main wiki is not a workspace
if (wikiId.equals(wikiDescriptorManager.getMainWikiId())) {
return false;
}
// Context, XWiki
XWikiContext context = getXWikiContext();
XWiki xwiki = context.getWiki();
// Get the old wiki descriptor
DocumentReference oldWikiDescriptorReference = new DocumentReference(wikiDescriptorManager.getMainWikiId(), XWiki.SYSTEM_SPACE, String.format("XWikiServer%s", StringUtils.capitalize(wikiId)));
XWikiDocument oldWikiDescriptor = xwiki.getDocument(oldWikiDescriptorReference, context);
// Try to get the old workspace object
DocumentReference oldClassDocument = new DocumentReference(wikiDescriptorManager.getMainWikiId(), WORKSPACE_CLASS_SPACE, WORKSPACE_CLASS_PAGE);
BaseObject oldObject = oldWikiDescriptor.getXObject(oldClassDocument);
return (oldObject != null) || isWorkspaceTemplate(wikiId);
}
use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.
the class WorkspacesMigration method restoreDeletedDocuments.
/**
* The WorkspaceManager.Install script has removed some pages, that we need to restore.
* - XWiki.AdminRegistrationSheet
* - XWiki.RegistrationConfig
* - XWiki.RegistrationHelp
* - XWiki.AdminUsersSheet
*
* @param wikiId id of the wiki to upgrade
*/
private void restoreDeletedDocuments(String wikiId) {
XWikiContext xcontext = getXWikiContext();
XWiki xwiki = xcontext.getWiki();
// Create the list of documents to restore
List<DocumentReference> documentsToRestore = new LinkedList<DocumentReference>();
documentsToRestore.add(new DocumentReference(wikiId, XWiki.SYSTEM_SPACE, "AdminRegistrationSheet"));
documentsToRestore.add(new DocumentReference(wikiId, XWiki.SYSTEM_SPACE, "RegistrationConfig"));
documentsToRestore.add(new DocumentReference(wikiId, XWiki.SYSTEM_SPACE, "RegistrationHelp"));
documentsToRestore.add(new DocumentReference(wikiId, XWiki.SYSTEM_SPACE, "AdminUsersSheet"));
// Remove from the list the document that already exists (so we don't need to restore them)
Iterator<DocumentReference> itDocumentsToRestore = documentsToRestore.iterator();
while (itDocumentsToRestore.hasNext()) {
DocumentReference docRef = itDocumentsToRestore.next();
if (xwiki.exists(docRef, xcontext)) {
itDocumentsToRestore.remove();
}
}
// If the list is empty, there is nothing to do
if (documentsToRestore.isEmpty()) {
return;
}
// Try to restore from the workspace-template.xar
restoreDocumentsFromWorkspaceXar(documentsToRestore);
// If the list is empty, the job is done
if (documentsToRestore.isEmpty()) {
return;
}
// Try to copy these documents from the main wiki
restoreDocumentFromMainWiki(documentsToRestore);
// If the list is empty, the job is done
if (!documentsToRestore.isEmpty()) {
String documentsToRestoreAsString = new String();
int counter = 0;
for (DocumentReference d : documentsToRestore) {
if (counter++ > 0) {
documentsToRestoreAsString += ", ";
}
documentsToRestoreAsString += d;
}
logger.warn("Failed to restore some documents: [{}]. You should import manually " + "(1) xwiki-platform-administration-ui.xar and then (2) xwiki-platform-wiki-ui-wiki.xar into your" + " wiki, to restore these documents.", documentsToRestoreAsString);
}
}
use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.
the class WikiManagerScriptService method checkProgrammingRights.
// TODO: move to new API a soon as a proper helper is provided
private void checkProgrammingRights() throws AuthorizationException {
XWikiContext xcontext = this.xcontextProvider.get();
authorizationManager.checkAccess(Right.PROGRAM, xcontext.getDoc().getAuthorReference(), xcontext.getDoc().getDocumentReference());
}
use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.
the class WikiManagerScriptService method deleteWiki.
/**
* Delete the specified wiki.
*
* @param wikiId unique identifier of the wiki to delete
* @return true if the wiki has been successfully deleted
*/
public boolean deleteWiki(String wikiId) {
// Test if the script has the programming right
XWikiContext context = xcontextProvider.get();
try {
// Check if the current script has the programming rights
checkProgrammingRights();
// Test right
if (!canDeleteWiki(entityReferenceSerializer.serialize(context.getUserReference()), wikiId)) {
throw new AuthorizationException("You don't have the right to delete the wiki");
}
// Delete the wiki
wikiManager.delete(wikiId);
// Return success
return true;
} catch (Exception e) {
error(String.format("Failed to delete wiki [%s]", wikiId), e);
}
return false;
}
Aggregations