Esempio n. 1
0
def handleCookieCrumblerEvent(ob, event):
    """ Event subscriber for (un)registering a CC as a before traverse hook.
    """
    if not ICookieCrumbler.providedBy(ob):
        return

    if IObjectMovedEvent.providedBy(event):
        if event.newParent is not None:
            # register before traverse hook
            handle = ob.meta_type + '/' + ob.getId()
            nc = BeforeTraverse.NameCaller(ob.getId())
            BeforeTraverse.registerBeforeTraverse(event.newParent, nc, handle)
    elif IObjectWillBeMovedEvent.providedBy(event):
        if event.oldParent is not None:
            # unregister before traverse hook
            handle = ob.meta_type + '/' + ob.getId()
            BeforeTraverse.unregisterBeforeTraverse(event.oldParent, handle)
Esempio n. 2
0
def handleOpaqueItemEvent(ob, event):
    """ Event subscriber for (ICallableOpaqueItemEvents, IObjectEvent) events.
    """
    if IObjectAddedEvent.providedBy(event):
        if event.newParent is not None:
            ob.manage_afterAdd(ob, event.newParent)

    elif IObjectClonedEvent.providedBy(event):
        ob.manage_afterClone(ob)

    elif IObjectMovedEvent.providedBy(event):
        if event.newParent is not None:
            ob.manage_afterAdd(ob, event.newParent)

    elif IObjectWillBeMovedEvent.providedBy(event):
        if event.oldParent is not None:
            ob.manage_beforeDelete(ob, event.oldParent)
Esempio n. 3
0
def handleCookieCrumblerEvent(ob, event):
    """ Event subscriber for (un)registering a CC as a before traverse hook.
    """
    if not ICookieCrumbler.providedBy(ob):
        return

    if IObjectMovedEvent.providedBy(event):
        if event.newParent is not None:
            # register before traverse hook
            handle = ob.meta_type + '/' + ob.getId()
            nc = BeforeTraverse.NameCaller(ob.getId())
            BeforeTraverse.registerBeforeTraverse(event.newParent, nc, handle)
    elif IObjectWillBeMovedEvent.providedBy(event):
        if event.oldParent is not None:
            # unregister before traverse hook
            handle = ob.meta_type + '/' + ob.getId()
            BeforeTraverse.unregisterBeforeTraverse(event.oldParent, handle)
Esempio n. 4
0
def handleCachingPolicyManagerEvent(ob, event):
    """ Event subscriber for (un)registering a CPM as CacheManager
    """
    if not ICachingPolicyManager.providedBy(ob):
        return

    if IObjectMovedEvent.providedBy(event):
        if event.newParent is not None:
            ids = getVerifiedManagerIds(event.newParent)
            id = ob.getId()
            if id not in ids:
                setattr(event.newParent, ZCM_MANAGERS, ids + (id,))

    elif IObjectWillBeMovedEvent.providedBy(event):
        if event.oldParent is not None:
            ids = list(getVerifiedManagerIds(event.oldParent))
            id = ob.getId()
            if id in ids:
                ids.remove(id)
                setattr(event.oldParent, ZCM_MANAGERS, tuple(ids))
Esempio n. 5
0
def handleCachingPolicyManagerEvent(ob, event):
    """ Event subscriber for (un)registering a CPM as CacheManager
    """
    if not ICachingPolicyManager.providedBy(ob):
        return

    if IObjectMovedEvent.providedBy(event):
        if event.newParent is not None:
            ids = getVerifiedManagerIds(event.newParent)
            id = ob.getId()
            if id not in ids:
                setattr(event.newParent, ZCM_MANAGERS, ids + (id, ))

    elif IObjectWillBeMovedEvent.providedBy(event):
        if event.oldParent is not None:
            ids = list(getVerifiedManagerIds(event.oldParent))
            id = ob.getId()
            if id in ids:
                ids.remove(id)
                setattr(event.oldParent, ZCM_MANAGERS, tuple(ids))
Esempio n. 6
0
def handleContentishEvent(ob, event):
    """ Event subscriber for (IContentish, IObjectEvent) events.
    """
    if IObjectAddedEvent.providedBy(event):
        ob.notifyWorkflowCreated()
        ob.indexObject()

    elif IObjectMovedEvent.providedBy(event):
        if event.newParent is not None:
            ob.indexObject()

    elif IObjectWillBeMovedEvent.providedBy(event):
        if event.oldParent is not None:
            ob.unindexObject()

    elif IObjectCopiedEvent.providedBy(event):
        if hasattr(aq_base(ob), 'workflow_history'):
            del ob.workflow_history

    elif IObjectCreatedEvent.providedBy(event):
        if hasattr(aq_base(ob), 'addCreator'):
            ob.addCreator()
Esempio n. 7
0
def handleContentishEvent(ob, event):
    """ Event subscriber for (IContentish, IObjectEvent) events.
    """
    if IObjectAddedEvent.providedBy(event):
        ob.notifyWorkflowCreated()
        ob.indexObject()

    elif IObjectMovedEvent.providedBy(event):
        if event.newParent is not None:
            if hasattr(aq_base(ob), 'notifyModified'):
                ob.notifyModified()

            rid = getattr(ob, '__rid', None)

            if rid:
                catalog = api.portal.get_tool('portal_catalog')
                _catalog = catalog._catalog

                new_path = '/'.join(ob.getPhysicalPath())
                old_path = _catalog.paths[rid]

                del _catalog.uids[old_path]
                _catalog.uids[new_path] = rid
                _catalog.paths[rid] = new_path

                ob.reindexObject(idxs=[
                    'path', 'allowedRolesAndUsers', 'modified', 'id', 'getId'
                ])

                delattr(ob, '__rid')
            elif event.newParent is not None:
                # This may happen if "collective.indexing" is installed and an object
                # is added and renamed/moved in the same transaction (e.g. during the
                # creation of an object with "plone.api" in a subscriber listening
                # on "IObjectAddedEvent" as in https://github.com/4teamwork/ftw.events/blob/f1a77440866c6d963961497f68781098c1b4bc8f/ftw/events/configure.zcml#L22).
                ob.indexObject()

    elif IObjectWillBeMovedEvent.providedBy(event):

        from ftw.copymovepatches.utils import getQueue

        # Prepare Rename if indexing queue is implemented
        if event.oldParent == event.newParent and getQueue is not None:
            # The queue needs to be processed, since the `renameObjectsByPaths`
            # script allows the user to rename the object and also sets a new
            # title if he wants.
            # In some circumstances this leads to a inconsistent catalog state.
            # Mainly if other event handler also triggers a `process` queue by
            # asking the catalog for something.
            # The result was for example a "reindex" of a already deleted
            # object.
            queue = getQueue()
            queue.process()

        # Move/Rename
        if event.oldParent is not None and event.newParent is not None:
            catalog = api.portal.get_tool('portal_catalog')
            ob_path = '/'.join(ob.getPhysicalPath())
            if ob_path in catalog._catalog.uids:
                rid = catalog._catalog.uids[ob_path]
                setattr(ob, '__rid', rid)
            else:
                # This may happen if "collective.indexing" is installed and an object
                # is added and renamed/moved in the same transaction (e.g. during the
                # creation of an object with "plone.api" in a subscriber listening
                # on "IObjectAddedEvent" as in https://github.com/4teamwork/ftw.events/blob/f1a77440866c6d963961497f68781098c1b4bc8f/ftw/events/configure.zcml#L22).
                return
        elif event.oldParent is not None:
            # Delete
            ob.unindexObject()

    elif IObjectCopiedEvent.providedBy(event):
        if hasattr(aq_base(ob), 'workflow_history'):
            del ob.workflow_history

    elif IObjectCreatedEvent.providedBy(event):
        if hasattr(aq_base(ob), 'addCreator'):
            ob.addCreator()