def populateMemberTables(sqlStore):
    """
    Set the group kind and and members tables
    """
    @inlineCallbacks
    def doIt(txn, homeResourceID):
        """
        KIND is set to person by schema upgrade.
        To upgrade MEMBERS and FOREIGN_MEMBERS:
            1. Set group KIND (avoids assert)
            2. Write groups.  Write logic will fill in MEMBERS and FOREIGN_MEMBERS
                (Remember that all members resource IDs must already be in the address book).
        """
        home = yield txn.addressbookHomeWithResourceID(homeResourceID)
        abObjectResources = yield home.addressbook().objectResources()
        for abObject in abObjectResources:
            component = yield abObject.component()
            lcResourceKind = component.resourceKind().lower() if component.resourceKind() else component.resourceKind()
            if lcResourceKind == "group":
                # update kind
                abo = schema.ADDRESSBOOK_OBJECT
                yield Update({abo.KIND: _ABO_KIND_GROUP},
                                Where=abo.RESOURCE_ID == abObject._resourceID,
                                ).on(txn)
                abObject._kind = _ABO_KIND_GROUP
                #update rest
                yield abObject.setComponent(component)

    logUpgradeStatus("Starting Addressbook Populate Members")

    # Do this to each calendar home not already at version 2
    yield doToEachHomeNotAtVersion(sqlStore, schema.ADDRESSBOOK_HOME, UPGRADE_TO_VERSION, doIt, "Populate Members")
def removeOtherProperties(sqlStore):
    """
    Remove the following properties:

    DAV:acl
    DAV:getcontenttype
    DAV:resource-id
    {urn:ietf:params:xml:ns:caldav}originator
    {urn:ietf:params:xml:ns:caldav}recipient
    {urn:ietf:params:xml:ns:caldav}supported-calendar-component-set
    {http://calendarserver.org/ns/}getctag
    {http://twistedmatrix.com/xml_namespace/dav/private/}quota-used
    {http://twistedmatrix.com/xml_namespace/dav/}getcontentmd5
    {http://twistedmatrix.com/xml_namespace/dav/}schedule-auto-respond

    """
    logUpgradeStatus("Starting Calendar Remove Other Properties")

    sqlTxn = sqlStore.newTransaction(label="calendar_upgrade_from_4_to_5.removeOtherProperties")

    yield removeProperty(sqlTxn, PropertyName.fromElement(element.ACL))
    yield removeProperty(sqlTxn, PropertyName.fromElement(element.GETContentType))
    yield removeProperty(sqlTxn, PropertyName.fromElement(element.ResourceID))
    yield removeProperty(sqlTxn, PropertyName(caldavxml.caldav_namespace, "originator"))
    yield removeProperty(sqlTxn, PropertyName(caldavxml.caldav_namespace, "recipient"))
    yield removeProperty(sqlTxn, PropertyName.fromElement(caldavxml.SupportedCalendarComponentSet))
    yield removeProperty(sqlTxn, PropertyName.fromElement(customxml.GETCTag))
    yield removeProperty(sqlTxn, PropertyName.fromElement(TwistedQuotaUsedProperty))
    yield removeProperty(sqlTxn, PropertyName.fromElement(TwistedGETContentMD5))
    yield removeProperty(sqlTxn, PropertyName(element.twisted_dav_namespace, "schedule-auto-respond"))

    yield sqlTxn.commit()
    yield cleanPropertyStore()

    logUpgradeStatus("End Calendar Remove Other Properties")
def removeOtherProperties(sqlStore):
    """
    Remove the following properties:

    DAV:acl
    DAV:getcontenttype
    DAV:resource-id
    {urn:ietf:params:xml:ns:caldav}originator
    {urn:ietf:params:xml:ns:caldav}recipient
    {urn:ietf:params:xml:ns:caldav}supported-calendar-component-set
    {http://calendarserver.org/ns/}getctag
    {http://twistedmatrix.com/xml_namespace/dav/private/}quota-used
    {http://twistedmatrix.com/xml_namespace/dav/}getcontentmd5
    {http://twistedmatrix.com/xml_namespace/dav/}schedule-auto-respond

    """
    logUpgradeStatus("Starting Calendar Remove Other Properties")

    sqlTxn = sqlStore.newTransaction()

    yield removeProperty(sqlTxn, PropertyName.fromElement(element.ACL))
    yield removeProperty(sqlTxn, PropertyName.fromElement(element.GETContentType))
    yield removeProperty(sqlTxn, PropertyName.fromElement(element.ResourceID))
    yield removeProperty(sqlTxn, PropertyName(caldavxml.caldav_namespace, "originator"))
    yield removeProperty(sqlTxn, PropertyName(caldavxml.caldav_namespace, "recipient"))
    yield removeProperty(sqlTxn, PropertyName.fromElement(caldavxml.SupportedCalendarComponentSet))
    yield removeProperty(sqlTxn, PropertyName.fromElement(customxml.GETCTag))
    yield removeProperty(sqlTxn, PropertyName.fromElement(TwistedQuotaUsedProperty))
    yield removeProperty(sqlTxn, PropertyName.fromElement(TwistedGETContentMD5))
    yield removeProperty(sqlTxn, PropertyName(element.twisted_dav_namespace, "schedule-auto-respond"))

    yield sqlTxn.commit()
    yield cleanPropertyStore()

    logUpgradeStatus("End Calendar Remove Other Properties")
def populateMemberTables(sqlStore):
    """
    Set the group kind and and members tables
    """
    @inlineCallbacks
    def doIt(txn, homeResourceID):
        """
        KIND is set to person by schema upgrade.
        To upgrade MEMBERS and FOREIGN_MEMBERS:
            1. Set group KIND (avoids assert)
            2. Write groups.  Write logic will fill in MEMBERS and FOREIGN_MEMBERS
                (Remember that all members resource IDs must already be in the address book).
        """
        home = yield txn.addressbookHomeWithResourceID(homeResourceID)
        abObjectResources = yield home.addressbook().objectResources()
        for abObject in abObjectResources:
            component = yield abObject.component()
            lcResourceKind = component.resourceKind().lower() if component.resourceKind() else component.resourceKind()
            if lcResourceKind == "group":
                # update kind
                abo = schema.ADDRESSBOOK_OBJECT
                yield Update(
                    {abo.KIND: _ABO_KIND_GROUP},
                    Where=abo.RESOURCE_ID == abObject._resourceID,
                ).on(txn)
                abObject._kind = _ABO_KIND_GROUP
                # update rest
                yield abObject.setComponent(component)

    logUpgradeStatus("Starting Addressbook Populate Members")

    # Do this to each calendar home not already at version 2
    yield doToEachHomeNotAtVersion(sqlStore, schema.ADDRESSBOOK_HOME, UPGRADE_TO_VERSION, doIt, "Populate Members")
def removeResourceType(sqlStore):
    logUpgradeStatus("Starting Calendar Remove Resource Type")

    sqlTxn = sqlStore.newTransaction()
    yield removeProperty(sqlTxn, PropertyName.fromElement(element.ResourceType))
    yield sqlTxn.commit()
    yield cleanPropertyStore()

    logUpgradeStatus("End Calendar Remove Resource Type")
def removeResourceType(sqlStore):
    logUpgradeStatus("Starting Addressbook Remove Resource Type")

    sqlTxn = sqlStore.newTransaction(label="addressbook_upgrade_from_1_to_2.removeResourceType")
    yield removeProperty(sqlTxn, PropertyName.fromElement(element.ResourceType))
    yield sqlTxn.commit()
    yield cleanPropertyStore()

    logUpgradeStatus("End Addressbook Remove Resource Type")
Example #7
0
def removeResourceType(sqlStore):
    logUpgradeStatus("Starting Calendar Remove Resource Type")

    sqlTxn = sqlStore.newTransaction(label="calendar_upgrade_from_3_to_4.removeResourceType")
    yield removeProperty(sqlTxn, PropertyName.fromElement(element.ResourceType))
    yield sqlTxn.commit()
    yield cleanPropertyStore()

    logUpgradeStatus("End Calendar Remove Resource Type")
def removeResourceType(sqlStore):
    logUpgradeStatus("Starting Addressbook Remove Resource Type")

    sqlTxn = sqlStore.newTransaction(label="addressbook_upgrade_from_1_to_2.removeResourceType")
    yield removeProperty(sqlTxn, PropertyName.fromElement(element.ResourceType))
    yield sqlTxn.commit()
    yield cleanPropertyStore()

    logUpgradeStatus("End Addressbook Remove Resource Type")
def splitCalendars(sqlStore):
    """
    Split all calendars by component type.
    """

    @inlineCallbacks
    def doIt(txn, homeResourceID):
        """
        Split each regular calendar in the home.
        """
        home = yield txn.calendarHomeWithResourceID(homeResourceID)
        yield home.splitCalendars()

    logUpgradeStatus("Starting Split Calendars")

    # Do this to each calendar home not already at version 2
    yield doToEachHomeNotAtVersion(sqlStore, schema.CALENDAR_HOME, UPGRADE_TO_VERSION, doIt, "Split Calendars")
Example #10
0
def splitCalendars(sqlStore):
    """
    Split all calendars by component type.
    """

    # This is already done when doing file->sql migration
    if sqlStore._migrating:
        returnValue(None)

    @inlineCallbacks
    def doIt(txn, homeResourceID):
        """
        Split each regular calendar in the home.
        """
        home = yield txn.calendarHomeWithResourceID(homeResourceID)
        yield home.splitCalendars()

    logUpgradeStatus("Starting Split Calendars")

    # Do this to each calendar home not already at version 2
    yield doToEachHomeNotAtVersion(sqlStore, schema.CALENDAR_HOME, UPGRADE_TO_VERSION, doIt, "Split Calendars")
def moveSupportedComponentSetProperties(sqlStore):
    """
    Need to move all the CalDAV:supported-component-set properties in the
    RESOURCE_PROPERTY table to the new CALENDAR_METADATA table column,
    extracting the new format value from the XML property.
    """

    logUpgradeStatus("Starting Move supported-component-set")

    sqlTxn = sqlStore.newTransaction(
        label="calendar_upgrade_from_1_to_2.moveSupportedComponentSetProperties"
    )
    try:
        # Do not move the properties if migrating, as migration will do a split and set supported-components,
        # however we still need to remove the old properties.
        if not sqlStore._migrating:
            calendar_rid = None
            rows = (yield
                    rowsForProperty(sqlTxn,
                                    caldavxml.SupportedCalendarComponentSet))
            total = len(rows)
            count = 0
            for calendar_rid, value in rows:
                prop = WebDAVDocument.fromString(value).root_element
                supported_components = ",".join(
                    sorted([
                        comp.attributes["name"].upper()
                        for comp in prop.children
                    ]))
                meta = schema.CALENDAR_METADATA
                yield Update(
                    {
                        meta.SUPPORTED_COMPONENTS: supported_components
                    },
                    Where=(meta.RESOURCE_ID == calendar_rid)).on(sqlTxn)
                count += 1
                logUpgradeStatus("Move supported-component-set", count, total)

        yield removeProperty(sqlTxn, caldavxml.SupportedCalendarComponentSet)
        yield sqlTxn.commit()

        logUpgradeStatus("End Move supported-component-set")
    except RuntimeError:
        yield sqlTxn.abort()
        logUpgradeError("Move supported-component-set",
                        "Last calendar: {}".format(calendar_rid))
        raise
def moveSupportedComponentSetProperties(sqlStore):
    """
    Need to move all the CalDAV:supported-component-set properties in the
    RESOURCE_PROPERTY table to the new CALENDAR_METADATA table column,
    extracting the new format value from the XML property.
    """

    logUpgradeStatus("Starting Move supported-component-set")

    sqlTxn = sqlStore.newTransaction()
    try:
        # Do not move the properties if migrating, as migration will do a split and set supported-components,
        # however we still need to remove the old properties.
        if not sqlStore._migrating:
            calendar_rid = None
            rows = (yield rowsForProperty(sqlTxn, caldavxml.SupportedCalendarComponentSet))
            total = len(rows)
            count = 0
            for calendar_rid, value in rows:
                prop = WebDAVDocument.fromString(value).root_element
                supported_components = ",".join(sorted([comp.attributes["name"].upper() for comp in prop.children]))
                meta = schema.CALENDAR_METADATA
                yield Update(
                    {
                        meta.SUPPORTED_COMPONENTS : supported_components
                    },
                    Where=(meta.RESOURCE_ID == calendar_rid)
                ).on(sqlTxn)
                count += 1
                logUpgradeStatus("Move supported-component-set", count, total)

        yield removeProperty(sqlTxn, caldavxml.SupportedCalendarComponentSet)
        yield sqlTxn.commit()

        logUpgradeStatus("End Move supported-component-set")
    except RuntimeError:
        yield sqlTxn.abort()
        logUpgradeError(
            "Move supported-component-set",
            "Last calendar: {}".format(calendar_rid)
        )
        raise