示例#1
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)
示例#2
0
    def run(self, root, options):
        if options.keep < 1:
            fail("You need to keep at least one version")
        logger.info('Removing old versions ...')
        removed = 0
        count = 0
        for count, content in enumerate(walk_silva_tree(root)):
            if not IVersionedContent.providedBy(content):
                continue
            versions = content._previous_versions
            if not versions:
                continue
            if count and count % 500 == 0:
                # Commit now and when
                transaction.commit()

            removable_versions = versions[:-options.keep]
            content._previous_versions = versions[-options.keep:]

            contained_ids = content.objectIds()
            removable_version_ids = set([
                str(version[0]) for version in removable_versions
                if version[0] in contained_ids])
            removed += len(removable_version_ids)

            content.manage_delObjects(list(removable_version_ids))

            if removed and removed % 500 == 0:
                logger.info('Removed %d versions, continuing ...' % removed)
        if removed:
            logger.info('Removed %d versions in total' % removed)
            transaction.commit()
        else:
            logger.info('Nothing removed')
示例#3
0
def walk_silva_tree_ex(content, requires=ISilvaObject, version=False):
    """A controllable generator to lazily get all the Silva object
    from a content / container. Send it True to recursively go down,
    or False to skip the recursion.
    """
    count = 0
    want_next = True
    if requires.providedBy(content):
        want_next = yield content
    if want_next:
        if IContainer.providedBy(content):
            for child in content.objectValues():
                walker_next = None
                walker = walk_silva_tree_ex(child, requires, version)
                while True:
                    count += 1
                    try:
                        walker_next = yield walker.send(walker_next)
                    except StopIteration:
                        break
                    if count > THRESHOLD:
                        # Review ZODB cache
                        content._p_jar.cacheGC()
                        count = 0
        if version and IVersionedContent.providedBy(content):
            yield content.get_previewable()
示例#4
0
 def walker(context):
     if requires.providedBy(context):
         # Version are indexed by the versioned content itself
         yield context
     if IContainer.providedBy(context):
         for child in context.objectValues():
             for context in walker(child):
                 yield context
     elif version and IVersionedContent.providedBy(context):
         yield context.get_previewable()
 def get_document(self):
     """Return the document version to which the External source is
     associated.
     """
     if IVersionedContent.providedBy(self.context):
         version = self.context.get_editable()
         if version is not None:
             return version
         version = self.context.get_viewable()
         if version is not None:
             return version
     return self.context
示例#6
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 get_document(self):
     """Return the document version to which the External source is
     associated.
     """
     if IVersionedContent.providedBy(self.context):
         version = self.context.get_editable()
         if version is not None:
             return version
         version = self.context.get_viewable()
         if version is not None:
             return version
     return self.context
示例#8
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()
示例#9
0
 def _getOb(self, id, default=_marker):
     content = super(Folder, self)._getOb(id, default)
     if content is _marker:
         raise AttributeError(id)
     if IVersionedContent.providedBy(content):
         if not hasattr(content, '_v_publication_status_updated'):
             try:
                 content._update_publication_status()
                 content._v_publication_status_updated = True
             except:
                 logger.exception(
                     "error while updating publication status for: %s",
                     '/'.join(self.getPhysicalPath() + (id, )))
     return content
 def _get_content_objects(self, object):
     objs = []
     if IVersionedContent.providedBy(object):
         editable = object.get_editable()
         if editable is not None:
             objs.append(
                 ('editable', editable.aq_parent.absolute_url(), editable))
         public_id = object.get_public_version()
         if public_id is not None:
             version = getattr(object, public_id)
             objs.append(
                 ('public', version.aq_parent.absolute_url(), version))
     else:
         objs = [('non-versioned', object.absolute_url(), object)]
     return objs
示例#11
0
 def notify_upgraded(self, content, modified=True):
     # XXX before 3.0, versioned content where not indexed in the catalog.
     if not IVersionedContent.providedBy(content):
         self._catalog_total += 1
     if not modified:
         return content
     self._count += 1
     if self._count > THRESHOLD:
         commit()
         if (hasattr(aq_base(content), '_p_jar') and
             content._p_jar is not None):
             # Cache minimize kill the ZODB cache
             # that is just resized at the end of the request
             # normally as well.
             content._p_jar.cacheMinimize()
             self._count = 0
         if self._catalog_expected:
             logger.info(
                 u'Estimated progression (from the catalog) %.02f%%',
                 self._catalog_total * 100.0 / self._catalog_expected)
     return content
 def validate(self, content):
     return (IVersionedContent.providedBy(content) and
             ('_cached_checked' in content.__dict__ or
              '_cached_data' in content.__dict__))
示例#13
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)