Ejemplo n.º 1
0
def evolve(context):
    """ Migrate versionIds for objects that don't have them set
    """
    cat = context.portal_catalog
    brains = cat.searchResults(missing=True, Language="all")

    i = 0
    for brain in brains:
        obj = brain.getObject()
        if not IVersionEnhanced.providedBy(obj):
            continue

        # first, check the brain's versionId
        brain_version = brain.getVersionId
        if isinstance(brain_version, basestring) and brain_version:
            # everything fine
            continue

        if brain.portal_type == "Discussion Item":
            continue  # skipping Discussion Items, they can't be reindexed

        versionId = IGetVersions(obj).versionId
        if isinstance(brain_version, basestring) and not brain_version.strip():
            # an empty string, assigning new versionId
            IAnnotations(obj)[VERSION_ID] = _random_id(obj)
            #obj.reindexObject()
            msg = "Migrated versionId storage (empty string) for %s (%s)" % \
                    (obj.absolute_url(), versionId)
            logger.info(msg)
            if (i % 500) == 0:
                transaction.commit()
            i += 1
            continue

        if isinstance(versionId, basestring) and not versionId.strip():
            # an empty string, assigning new versionId
            IAnnotations(obj)[VERSION_ID] = _random_id(obj)
            #obj.reindexObject()
            msg = "Migrated versionId storage (empty string) for %s (%s)" % \
                    (obj.absolute_url(), versionId)
            logger.info(msg)
            if (i % 500) == 0:
                transaction.commit()
            i += 1
            continue

        if not brain.getVersionId:
            IAnnotations(obj)[VERSION_ID] = _random_id(obj)
            #obj.reindexObject()
            msg = "Migrated versionId storage (empty storage) for %s (%s)" % \
                    (obj.absolute_url(), versionId)
            logger.info(msg)
            if (i % 500) == 0:
                transaction.commit()
            i += 1
            continue

        migrate_versionId_storage(obj)  #this is an old storage:
Ejemplo n.º 2
0
def evolve(context):
    """ Migrate versionIds for objects that don't have them set
    """
    cat = context.portal_catalog
    brains = cat.searchResults(missing=True, Language="all")

    i = 0
    for brain in brains:
        obj = brain.getObject()
        if not IVersionEnhanced.providedBy(obj):
            continue

        # first, check the brain's versionId
        brain_version = brain.getVersionId
        if isinstance(brain_version, basestring) and brain_version:
            # everything fine
            continue

        if brain.portal_type == "Discussion Item":
            continue  # skipping Discussion Items, they can't be reindexed

        versionId = IGetVersions(obj).versionId
        if isinstance(brain_version, basestring) and not brain_version.strip():
            # an empty string, assigning new versionId
            IAnnotations(obj)[VERSION_ID] = _random_id(obj)
            # obj.reindexObject()
            msg = "Migrated versionId storage (empty string) for %s (%s)" % (obj.absolute_url(), versionId)
            logger.info(msg)
            if (i % 500) == 0:
                transaction.commit()
            i += 1
            continue

        if isinstance(versionId, basestring) and not versionId.strip():
            # an empty string, assigning new versionId
            IAnnotations(obj)[VERSION_ID] = _random_id(obj)
            # obj.reindexObject()
            msg = "Migrated versionId storage (empty string) for %s (%s)" % (obj.absolute_url(), versionId)
            logger.info(msg)
            if (i % 500) == 0:
                transaction.commit()
            i += 1
            continue

        if not brain.getVersionId:
            IAnnotations(obj)[VERSION_ID] = _random_id(obj)
            # obj.reindexObject()
            msg = "Migrated versionId storage (empty storage) for %s (%s)" % (obj.absolute_url(), versionId)
            logger.info(msg)
            if (i % 500) == 0:
                transaction.commit()
            i += 1
            continue

        migrate_versionId_storage(obj)  # this is an old storage:
Ejemplo n.º 3
0
def migrate_versionId_storage(obj):
    """Migrate storage of versionId
    """

    old_storage = obj.__annotations__.get("versionId")
    if not old_storage:
        msg = "no versionId stored for %s, but preset in catalog" % obj.absolute_url()
        logger.warning(msg)

    if isinstance(old_storage, basestring):
        msg = "Skipping migration of versionId for %s, " "already migrated" % obj
        return

    versionId = obj.__annotations__["versionId"]["versionId"].strip()
    obj.__annotations__["versionId"] = versionId

    # has versionId set but does not provide IVersionEnhanced
    # all versioned objects should provide IVersionEnhanced
    if versionId and not IVersionEnhanced.providedBy(obj):
        logger.info("versionId assigned without IVersionEnhanced " "provided %s", obj.absolute_url())
        alsoProvides(obj, IVersionEnhanced)

    # doesn't have a good versionId (could be empty string),
    # but provides IVersionEnhanced. Will supply object with new versionId
    if not versionId and IVersionEnhanced.providedBy(obj):
        obj.__annotations__["versionId"] = _random_id(obj)

    msg = "Migrated versionId storage for %s (%s)" % (obj.absolute_url(), versionId)
    logger.info(msg)
Ejemplo n.º 4
0
def migrate_versionId_storage(obj):
    """Migrate storage of versionId
    """

    old_storage = obj.__annotations__.get('versionId')
    if not old_storage:
        msg = ("no versionId stored for %s, but preset in catalog" %
               obj.absolute_url())
        logger.warning(msg)

    if isinstance(old_storage, basestring):
        msg = ("Skipping migration of versionId for %s, "
               "already migrated" % obj)
        return

    versionId = obj.__annotations__['versionId']['versionId'].strip()
    obj.__annotations__['versionId'] = versionId

    #has versionId set but does not provide IVersionEnhanced
    #all versioned objects should provide IVersionEnhanced
    if versionId and not IVersionEnhanced.providedBy(obj):
        logger.info(
            "versionId assigned without IVersionEnhanced "
            "provided %s", obj.absolute_url())
        alsoProvides(obj, IVersionEnhanced)

    #doesn't have a good versionId (could be empty string),
    #but provides IVersionEnhanced. Will supply object with new versionId
    if not versionId and IVersionEnhanced.providedBy(obj):
        obj.__annotations__['versionId'] = _random_id(obj)

    msg = "Migrated versionId storage for %s (%s)" % \
            (obj.absolute_url(), versionId)
    logger.info(msg)
Ejemplo n.º 5
0
def new_version_id(obj):
    """
    :param obj: context object
    :type obj: object
    :return: new version id containing either random or incremented prefix value
    :rtype: str
    """
    version_prefix = get_version_prefix(obj)
    if version_prefix:
        pvalue = increment_version_prefix_number(version_prefix)
        ptitle = version_prefix.title
        cvid = '{0}-{1}'.format(ptitle, pvalue)
        if version_prefix.prefix_with_language:
            cvid = cvid + '-' + obj.getLanguage()
        return cvid
    else:
        return _random_id(obj)
Ejemplo n.º 6
0
def migrate_versionId_storage(obj):
    """Migrate storage of versionId
    """

    raw_versionId = obj.__annotations__["versionId"]["versionId"]
    logger.info("versionID: %s", raw_versionId)
    versionId = raw_versionId.strip()

    # doesn't have a good versionId (could be empty string),
    if not versionId and IVersionEnhanced.providedBy(obj):
        obj.__annotations__["versionId"] = _random_id(obj)
    else:
        obj.__annotations__["versionId"] = versionId

    msg = "Migrated versionId storage (old version) for %s (%s)" % (obj.absolute_url(), versionId)

    logger.info(msg)
Ejemplo n.º 7
0
def migrate_versionId_storage(obj):
    """Migrate storage of versionId
    """

    raw_versionId = obj.__annotations__['versionId']['versionId']
    logger.info('versionID: %s', raw_versionId)
    versionId = raw_versionId.strip()

    #doesn't have a good versionId (could be empty string),
    if not versionId and IVersionEnhanced.providedBy(obj):
        obj.__annotations__['versionId'] = _random_id(obj)
    else:
        obj.__annotations__['versionId'] = versionId

    msg = "Migrated versionId storage (old version) for %s (%s)" % \
            (obj.absolute_url(), versionId)

    logger.info(msg)
Ejemplo n.º 8
0
def evolve(context):
    """ Migrate versionIds for non-Archetypes objects that don't have them set
    """
    p_types = ['Newsletter', 'NewsletterTheme']

    cat = context.portal_catalog
    brains = cat.searchResults(portal_type=p_types, Language="all")

    for brain in brains:
        obj = brain.getObject()
        versionId = _random_id(obj)
        obj.__annotations__['versionId'] = versionId
        obj.reindexObject()
        msg = "Migrated versionId storage (empty storage) for %s (%s)" % \
              (obj.absolute_url(), versionId)
        logger.info(msg)

    logger.info("Finished migration of PG content types version ids")
Ejemplo n.º 9
0
def get_assessment_vid_for_spec_vid(context, versionid):
    """Returns an assessment version id

    Given a version id for a specification, returns the version id of the
    assessments that are contained in any of the Specifications from that
    versioning group.
    """

    vid = _random_id(context, 10)
    cat = getToolByName(context, 'portal_catalog')
    p = '/'.join(context.getPhysicalPath())
    brains = cat.searchResults({'getVersionId':versionid,
                                'portal_type':'Specification'})
    brains = [b for b in brains if b.getPath() != p]

    for brain in brains:
        obj = brain.getObject()
        children = obj.objectValues('Assessment')
        if children:
            vid = IGetVersions(children[0]).versionId
            break

    return vid
Ejemplo n.º 10
0
def get_assessment_vid_for_spec_vid(context, versionid):
    """Returns an assessment version id

    Given a version id for a specification, returns the version id of the
    assessments that are contained in any of the Specifications from that
    versioning group.
    """

    vid = _random_id(context, 10)
    cat = getToolByName(context, 'portal_catalog')
    p = '/'.join(context.getPhysicalPath())
    brains = cat.searchResults({'getVersionId':versionid,
                                'portal_type':'Specification'})
    brains = [b for b in brains if b.getPath() != p]

    for brain in brains:
        obj = brain.getObject()
        children = obj.objectValues('Assessment')
        if children:
            vid = IGetVersions(children[0]).versionId
            break

    return vid