Exemple #1
0
def cleanup_stored_schemas(site):
    print '\t=== SITE: %s ===' % site.getId()
    # get schema saver:
    saver = queryUtility(ISchemaSaver)
    size_before = len(saver)
    # calculate in-use schema signatures:
    actively_used = set()  # in-use md5 schema signatures
    content = map(get, search(site, TYPEQUERY))
    for context in content:
        assert IDefinitionBase.providedBy(context)
        if context.signature is None:
            context.signature = saver.add(context.entry_schema)
        # consider the current schema (signature) used now by definition
        # or field group in question:
        actively_used.add(context.signature)
        if IFormDefinition.providedBy(context):
            # consider any past schema signatures on records now marked as
            # having schema immutability when definition is modified:
            actively_used.update(all_forms_signatures(context))
    # enumerate through schema saver:
    for signature in list(saver.keys()):
        if signature == DEFAULT_SIGNATURE:
            continue  # leave this alone, attempting to remove --> exception
        if signature not in actively_used:
            del (saver[signature])
    size_after = len(saver)
    removed = size_before - size_after
    if removed:
        print('\t\tRemoved %s (of %s) orphaned schemas from local storage.' % (
            removed,
            size_before,
        ))
        verify(site)
        commit(site, 'Cleaned up orphaned schemas')
Exemple #2
0
def cleanup_stored_schemas(site):
    print '\t=== SITE: %s ===' % site.getId()
    # get schema saver:
    saver = queryUtility(ISchemaSaver)
    size_before = len(saver)
    # calculate in-use schema signatures:
    actively_used = set()  # in-use md5 schema signatures
    content = map(get, search(site, TYPEQUERY))
    for context in content:
        assert IDefinitionBase.providedBy(context)
        assert context.signature is not None
        # consider the current schema (signature) used now by definition
        # or field group in question:
        actively_used.add(context.signature)
        if IFormDefinition.providedBy(context):
            # consider any past schema signatures on records now marked as
            # having schema immutability when definition is modified:
            actively_used.update(all_forms_signatures(context))
    # enumerate through schema saver:
    for signature in list(saver.keys()):
        if signature == DEFAULT_SIGNATURE:
            continue  # leave this alone, attempting to remove --> exception
        if signature not in actively_used:
            del(saver[signature])
    size_after = len(saver)
    removed = size_before - size_after
    if removed:
        print (
            '\t\tRemoved %s (of %s) orphaned schemas from local storage.' % (
                removed,
                size_before,
                )
            )
        verify(site)
        commit(site, 'Cleaned up orphaned schemas')
Exemple #3
0
def reserialize(context, schema):
    if not IDefinitionBase.providedBy(context.__parent__):
        return  # not an event we care about
    definition = context.__parent__
    saver = queryUtility(ISchemaSaver)
    new_signature = saver.add(schema)
    new_xml = saver.get(new_signature)
    definition.entry_schema = new_xml
    definition.signature = new_signature
    if IFormDefinition.providedBy(definition):
        update_form_entries(definition)
    # TODO: deal with nested groups and associated data objects contained
    if hasattr(aq_base(definition), '_v_schema'):
        delattr(aq_base(definition), '_v_schema')  # invalidate previous schema
    definition.reindexObject()