Search in sources :

Example 1 with WikiDeletedEvent

use of org.xwiki.bridge.event.WikiDeletedEvent in project xwiki-platform by xwiki.

the class ContextComponentManagerTest method testDeleteWiki.

@Test
public void testDeleteWiki() throws ComponentLookupException, Exception {
    getMockery().checking(new Expectations() {

        {
            allowing(mockWikiDescriptorManager).getCurrentWikiId();
            will(returnValue("wiki"));
            allowing(mockCurrentSpaceReferenceProvider).get();
            will(returnValue(new SpaceReference("space", new WikiReference("wiki"))));
            allowing(mockCurrentDocumentReferenceProvider).get();
            will(returnValue(new DocumentReference("wiki", "space", "document")));
            allowing(mockDocumentAccessBridge).getCurrentUserReference();
            will(returnValue(new DocumentReference("wiki", "XWiki", "user")));
        }
    });
    // Register in the current wiki.
    ComponentManager wikiCM = getComponentManager().getInstance(ComponentManager.class, "wiki");
    DefaultComponentDescriptor<Role> cd = new DefaultComponentDescriptor<Role>();
    cd.setRoleType(Role.class);
    cd.setImplementation(RoleImpl.class);
    wikiCM.registerComponent(cd);
    ComponentManager contextCM = getComponentManager().getInstance(ComponentManager.class, "context");
    Assert.assertNotNull(contextCM.getComponentDescriptor(Role.class, "default"));
    ObservationManager observationManager = getComponentManager().getInstance(ObservationManager.class);
    observationManager.notify(new WikiDeletedEvent("wiki"), null, null);
    Assert.assertNull(contextCM.getComponentDescriptor(Role.class, "default"));
}
Also used : Expectations(org.jmock.Expectations) DefaultComponentDescriptor(org.xwiki.component.descriptor.DefaultComponentDescriptor) SpaceReference(org.xwiki.model.reference.SpaceReference) ComponentManager(org.xwiki.component.manager.ComponentManager) NamespacedComponentManager(org.xwiki.component.manager.NamespacedComponentManager) ObservationManager(org.xwiki.observation.ObservationManager) WikiReference(org.xwiki.model.reference.WikiReference) WikiDeletedEvent(org.xwiki.bridge.event.WikiDeletedEvent) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 2 with WikiDeletedEvent

use of org.xwiki.bridge.event.WikiDeletedEvent in project xwiki-platform by xwiki.

the class XWikiCacheStore method onEvent.

@Override
public void onEvent(Event event, Object source, Object data) {
    // only react to remote events since local actions are already taken into account
    if (this.remoteObservationManagerContext.isRemoteState()) {
        if (event instanceof WikiDeletedEvent) {
            flushCache();
        } else {
            XWikiDocument doc = (XWikiDocument) source;
            String key = doc.getKey();
            if (getCache() != null) {
                getCache().remove(key);
            }
            if (getPageExistCache() != null) {
                getPageExistCache().remove(key);
            }
        }
    }
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) WikiDeletedEvent(org.xwiki.bridge.event.WikiDeletedEvent)

Example 3 with WikiDeletedEvent

use of org.xwiki.bridge.event.WikiDeletedEvent in project xwiki-platform by xwiki.

the class DefaultWikiManager method delete.

@Override
public void delete(String wikiId) throws WikiManagerException {
    // Delete the wiki
    wikiDeleter.delete(wikiId);
    // Send an event
    observationManager.notify(new WikiDeletedEvent(wikiId), wikiId);
}
Also used : WikiDeletedEvent(org.xwiki.bridge.event.WikiDeletedEvent)

Example 4 with WikiDeletedEvent

use of org.xwiki.bridge.event.WikiDeletedEvent in project xwiki-platform by xwiki.

the class SolrIndexEventListener method onEvent.

@Override
public void onEvent(Event event, Object source, Object data) {
    try {
        if (event instanceof DocumentUpdatedEvent) {
            XWikiDocument document = (XWikiDocument) source;
            if (Locale.ROOT.equals(document.getLocale())) {
                // Index all the translations of a document when its default translation has been updated because
                // the default translation holds meta data shared by all translations (attachments, objects).
                indexTranslations(document, (XWikiContext) data);
            } else {
                // Index only the updated translation.
                this.solrIndexer.get().index(document.getDocumentReferenceWithLocale(), false);
            }
        } else if (event instanceof DocumentCreatedEvent) {
            XWikiDocument document = (XWikiDocument) source;
            if (!Locale.ROOT.equals(document.getLocale())) {
                // If a new translation is added to a document reindex the whole document (could be optimized a bit
                // by reindexing only the parent locales but that would always include objects and attachments
                // anyway)
                indexTranslations(document, (XWikiContext) data);
            } else {
                this.solrIndexer.get().index(document.getDocumentReferenceWithLocale(), false);
            }
        } else if (event instanceof DocumentDeletedEvent) {
            XWikiDocument document = ((XWikiDocument) source).getOriginalDocument();
            // We must pass the document reference with the REAL locale because when the indexer is going to delete
            // the document from the Solr index (later, on a different thread) the real locale won't be accessible
            // anymore since the XWiki document has been already deleted from the database. The real locale (taken
            // from the XWiki document) is used to compute the id of the Solr document when the document reference
            // locale is ROOT (i.e. for default document translations).
            // Otherwise the document won't be deleted from the Solr index (because the computed id won't match any
            // document from the Solr index) and we're going to have deleted documents that are still in the Solr
            // index. These documents will be filtered from the search results but not from the facet counts.
            // See XWIKI-10003: Cache problem with Solr facet filter results count
            this.solrIndexer.get().delete(new DocumentReference(document.getDocumentReference(), document.getRealLocale()), false);
        } else if (event instanceof AttachmentUpdatedEvent || event instanceof AttachmentAddedEvent) {
            XWikiDocument document = (XWikiDocument) source;
            String fileName = ((AbstractAttachmentEvent) event).getName();
            XWikiAttachment attachment = document.getAttachment(fileName);
            this.solrIndexer.get().index(attachment.getReference(), false);
        } else if (event instanceof AttachmentDeletedEvent) {
            XWikiDocument document = ((XWikiDocument) source).getOriginalDocument();
            String fileName = ((AbstractAttachmentEvent) event).getName();
            XWikiAttachment attachment = document.getAttachment(fileName);
            this.solrIndexer.get().delete(attachment.getReference(), false);
        } else if (event instanceof XObjectUpdatedEvent || event instanceof XObjectAddedEvent) {
            EntityEvent entityEvent = (EntityEvent) event;
            this.solrIndexer.get().index(entityEvent.getReference(), false);
        } else if (event instanceof XObjectDeletedEvent) {
            EntityEvent entityEvent = (EntityEvent) event;
            this.solrIndexer.get().delete(entityEvent.getReference(), false);
        } else if (event instanceof XObjectPropertyUpdatedEvent || event instanceof XObjectPropertyAddedEvent) {
            EntityEvent entityEvent = (EntityEvent) event;
            this.solrIndexer.get().index(entityEvent.getReference(), false);
        } else if (event instanceof XObjectPropertyDeletedEvent) {
            EntityEvent entityEvent = (EntityEvent) event;
            this.solrIndexer.get().delete(entityEvent.getReference(), false);
        } else if (event instanceof WikiDeletedEvent) {
            String wikiName = (String) source;
            WikiReference wikiReference = new WikiReference(wikiName);
            this.solrIndexer.get().delete(wikiReference, false);
        }
    } catch (Exception e) {
        this.logger.error("Failed to handle event [{}] with source [{}]", event, source, e);
    }
}
Also used : XObjectPropertyUpdatedEvent(com.xpn.xwiki.internal.event.XObjectPropertyUpdatedEvent) AttachmentAddedEvent(com.xpn.xwiki.internal.event.AttachmentAddedEvent) XObjectAddedEvent(com.xpn.xwiki.internal.event.XObjectAddedEvent) XObjectPropertyDeletedEvent(com.xpn.xwiki.internal.event.XObjectPropertyDeletedEvent) DocumentCreatedEvent(org.xwiki.bridge.event.DocumentCreatedEvent) XWikiContext(com.xpn.xwiki.XWikiContext) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) XWikiAttachment(com.xpn.xwiki.doc.XWikiAttachment) XWikiException(com.xpn.xwiki.XWikiException) XObjectUpdatedEvent(com.xpn.xwiki.internal.event.XObjectUpdatedEvent) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) XObjectPropertyAddedEvent(com.xpn.xwiki.internal.event.XObjectPropertyAddedEvent) EntityEvent(com.xpn.xwiki.internal.event.EntityEvent) AttachmentUpdatedEvent(com.xpn.xwiki.internal.event.AttachmentUpdatedEvent) AbstractAttachmentEvent(com.xpn.xwiki.internal.event.AbstractAttachmentEvent) XObjectDeletedEvent(com.xpn.xwiki.internal.event.XObjectDeletedEvent) AttachmentDeletedEvent(com.xpn.xwiki.internal.event.AttachmentDeletedEvent) WikiDeletedEvent(org.xwiki.bridge.event.WikiDeletedEvent) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 5 with WikiDeletedEvent

use of org.xwiki.bridge.event.WikiDeletedEvent in project xwiki-platform by xwiki.

the class WikiDeletedListener method onEvent.

@Override
public void onEvent(Event event, Object source, Object data) {
    String wikiId = ((WikiDeletedEvent) event).getWikiId();
    File directory = this.store.getWikiDir(wikiId);
    if (directory.exists() && directory.isDirectory()) {
        try {
            FileUtils.deleteDirectory(directory);
        } catch (IOException e) {
            this.logger.error("Failed to delete storage for the wiki [{}]", wikiId, e);
        }
    }
}
Also used : IOException(java.io.IOException) WikiDeletedEvent(org.xwiki.bridge.event.WikiDeletedEvent) File(java.io.File)

Aggregations

WikiDeletedEvent (org.xwiki.bridge.event.WikiDeletedEvent)7 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)3 ComponentManager (org.xwiki.component.manager.ComponentManager)2 DocumentReference (org.xwiki.model.reference.DocumentReference)2 WikiReference (org.xwiki.model.reference.WikiReference)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiException (com.xpn.xwiki.XWikiException)1 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)1 AbstractAttachmentEvent (com.xpn.xwiki.internal.event.AbstractAttachmentEvent)1 AttachmentAddedEvent (com.xpn.xwiki.internal.event.AttachmentAddedEvent)1 AttachmentDeletedEvent (com.xpn.xwiki.internal.event.AttachmentDeletedEvent)1 AttachmentUpdatedEvent (com.xpn.xwiki.internal.event.AttachmentUpdatedEvent)1 EntityEvent (com.xpn.xwiki.internal.event.EntityEvent)1 XObjectAddedEvent (com.xpn.xwiki.internal.event.XObjectAddedEvent)1 XObjectDeletedEvent (com.xpn.xwiki.internal.event.XObjectDeletedEvent)1 XObjectPropertyAddedEvent (com.xpn.xwiki.internal.event.XObjectPropertyAddedEvent)1 XObjectPropertyDeletedEvent (com.xpn.xwiki.internal.event.XObjectPropertyDeletedEvent)1 XObjectPropertyUpdatedEvent (com.xpn.xwiki.internal.event.XObjectPropertyUpdatedEvent)1 XObjectUpdatedEvent (com.xpn.xwiki.internal.event.XObjectUpdatedEvent)1 File (java.io.File)1