Beispiel #1
0
def version_created(version, event):
    if IObjectCopiedEvent.providedBy(event):
        return

    created = version == event.object
    ChangesTask.get().modified(version, created)
    if created:
        ICataloging(version).index()
        ICataloging(version.get_silva_object()).index(with_versions=False)
def index_content(parent, reindex=False):
    """Recursively index or index Silva Content.
    """
    count = 0
    for count, content in enumerate(walk_silva_tree(parent)):
        if count and count % 500 == 0:
            transaction.commit()
            logger.info('indexing: %d objects indexed' % count)
        if reindex:
            ICataloging(content).reindex()
        else:
            ICataloging(content).index()
    logger.info('catalog indexing: %d objects indexed' % count)
Beispiel #3
0
def content_created(content, event):
    if (content != event.object or IObjectCopiedEvent.providedBy(event)
            or IVersionedContent.providedBy(content)):
        return

    ICataloging(content).index()
    ChangesTask.get().modified(content, created=True)
Beispiel #4
0
def index_moved_content(content, event):
    """We index all added content (due to a move).
    """
    if getattr(content, '__initialization__', False):
        return

    if (not IObjectAddedEvent.providedBy(event)
            and not IObjectRemovedEvent.providedBy(event)):
        ICataloging(content).index()
Beispiel #5
0
def index_and_update_author_modified_content(content, event):
    """A content have been created of modifed. Update its author
    information.
    """
    # In the same way, we discard event on versioned content if they
    # are about adding or removing a version.
    if (IVersionedContent.providedBy(content)
            and IContainerModifiedEvent.providedBy(event)):
        return
    if getattr(content, '__initialization__', False):
        return
    ChangesTask.get().modified(content)
    ICataloging(content).reindex()
    def _store(self, values, set, set_id, reindex=0):
        if not values:
            return False

        # Update acquirable values
        for element_id, element, value in values:
            if element.isAcquireable():
                attr_name = encodeElement(set_id, element_id)
                if not (value == '' or value is None):
                    setattr(self.content, attr_name, value)
                else:
                    # Try and get rid of encoded attribute on the
                    # annotatable object; this will get acquisition
                    # of the value working again.
                    try:
                        delattr(self.content, attr_name)
                    except (KeyError, AttributeError):
                        pass

        # Save values in Annotations
        annotations = IAnnotations(aq_base(self.content))
        if set.metadata_uri not in annotations:
            annotations[set.metadata_uri] = PersistentMapping({})
        storage = annotations[set.metadata_uri]

        data = {}
        for element_id, element, value in values:
            if not (value == '' or value is None):
                storage[element_id] = value
            elif element_id in storage:
                del storage[element_id]
            # For the event
            data[element_id] = value

        # invalidate the cache version of the set if any
        # we do a check for cached acquired/non-acquired
        if (0, set_id) in self.cached_values:
            del self.cached_values[(0, set_id)]
        if (1, set_id) in self.cached_values:
            del self.cached_values[(1, set_id)]

        # mark both the content and the annotatable object as changed so
        # on txn commit bindings in other objectspaces get invalidated as well
        self.content._p_changed = 1

        # reindex object
        if reindex and not getattr(self.content, '__initialization__', False):
            ICataloging(self.content).reindex()
        notify(MetadataModifiedEvent(self.content, data))
        return True
Beispiel #7
0
def version_removed(version, event):
    if version == event.object:
        # Only interested about version removed by hand.
        ICataloging(version).unindex()
Beispiel #8
0
def version_modified(version, event):
    if not IPublishingEvent.providedBy(event):
        # This version have been modified
        ChangesTask.get().modified(version)
        ICataloging(version).reindex()
        ICataloging(version.get_silva_object()).reindex(with_versions=False)
Beispiel #9
0
def version_closed(version, event):
    ChangesTask.get().modified(version)
    ICataloging(version).unindex()
    ICataloging(version.get_silva_object()).reindex(with_versions=False)
Beispiel #10
0
def reindex_import_content(content, event):
    """Re-index imported content.
    """
    ICataloging(content).index()
Beispiel #11
0
def unindex_removed_content(content, event):
    """We unindex all content that is going to be moved, and/or
    deleted.
    """
    if not IObjectWillBeAddedEvent.providedBy(event):
        ICataloging(content).unindex()
Beispiel #12
0
    def upgrade(self, doc):
        logger.info('Upgrading HTML in: %s.', content_path(doc))
        # ID + Title
        identifier = doc.id
        title = doc.get_title()
        parent = aq_parent(doc)

        # Create a new doccopy the annotation
        try:
            new_doc = self.create_document(parent,
                                           identifier + 'conv__silva30', title)
        except ValueError:
            logger.error('Cannot convert document: %s.', content_path(doc))
            return doc
        new_identifier = new_doc.getId()  # The id can have changed
        # Copy annotation
        copy_annotation(doc, new_doc)
        # Move references
        move_references(doc, new_doc)

        # Last closed version
        last_closed_version_id = doc.get_last_closed_version()
        if last_closed_version_id is not None:
            last_closed_version = doc._getOb(last_closed_version_id, None)
            if last_closed_version is not None:
                new_last_closed_version = new_doc.get_editable()
                self.copy_version(last_closed_version, new_last_closed_version,
                                  True)
                new_doc.approve_version()
                if new_doc.get_public_version():
                    # The version can already be expired
                    new_doc.close_version()
                new_doc.create_copy()

        # Published version
        public_version = doc.get_viewable()
        if public_version is not None:
            new_public_version = new_doc.get_editable()
            self.copy_version(public_version, new_public_version, True)
            new_doc.approve_version()

        # Editable version
        editable_version = doc.get_editable()
        if editable_version is not None:
            if public_version is not None:
                new_doc.create_copy()
            new_editable_version = new_doc.get_editable()
            self.copy_version(editable_version, new_editable_version)

        # Markers
        new_mark_mg = IMarkManager(new_doc)
        for marker in IMarkManager(doc).usedMarkers:
            new_mark_mg.add_marker(marker)

        # Delete old document and rename content to final id
        order_mg = IOrderManager(parent)
        position = order_mg.get_position(doc)
        parent.manage_delObjects([identifier])
        try:
            parent.manage_renameObject(new_identifier, identifier)
        except CopyError:
            try:
                parent._checkId(identifier)
            except BadRequest:
                logger.error(
                    "Could not replace document with '%s' identifier, renaming it to '%s_changed'.",
                    identifier, identifier)
                identifier += '_changed'
                parent.manage_renameObject(new_identifier, identifier)
            else:
                raise
        new_doc = parent[identifier]
        if position > -1:
            order_mg.move(new_doc, position)
        ICataloging(new_doc).reindex()
        return new_doc