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 """ 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()
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. """ sqlTxn = sqlStore.newTransaction() try: rows = (yield rowsForProperty(sqlTxn, caldavxml.SupportedCalendarComponentSet)) 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) yield removeProperty(sqlTxn, caldavxml.SupportedCalendarComponentSet) yield sqlTxn.commit() except RuntimeError: yield sqlTxn.abort() raise
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")
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 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
def removeResourceType(sqlStore): sqlTxn = sqlStore.newTransaction() yield removeProperty(sqlTxn, PropertyName.fromElement(element.ResourceType)) yield sqlTxn.commit() yield cleanPropertyStore()
def moveCalendarTranspProperties(sqlStore): """ Need to move all the CalDAV:schedule-calendar-transp properties in the RESOURCE_PROPERTY table to the new CALENDAR_BIND table columns, extracting the new value from the XML property. """ cb = schema.CALENDAR_BIND rp = schema.RESOURCE_PROPERTY try: calendars_for_id = {} while True: sqlTxn = sqlStore.newTransaction() rows = (yield rowsForProperty(sqlTxn, caldavxml.ScheduleCalendarTransp, with_uid=True, batch=BATCH_SIZE)) if len(rows) == 0: yield sqlTxn.commit() break delete_ids = [] for calendar_rid, value, viewer in rows: delete_ids.append(calendar_rid) if calendar_rid not in calendars_for_id: ids = yield Select( [cb.CALENDAR_HOME_RESOURCE_ID, cb.BIND_MODE, ], From=cb, Where=cb.CALENDAR_RESOURCE_ID == calendar_rid, ).on(sqlTxn) calendars_for_id[calendar_rid] = ids if viewer: calendarHome = (yield sqlTxn.calendarHomeWithUID(viewer)) else: calendarHome = None for row in calendars_for_id[calendar_rid]: home_id, bind_mode = row if bind_mode == _BIND_MODE_OWN: calendarHome = (yield sqlTxn.calendarHomeWithResourceID(home_id)) break if calendarHome is not None: prop = WebDAVDocument.fromString(value).root_element calendar = (yield calendarHome.childWithID(calendar_rid)) if calendar is not None: yield calendar.setUsedForFreeBusy(prop == caldavxml.ScheduleCalendarTransp(caldavxml.Opaque())) # Always delete the rows so that batch processing works correctly yield Delete( From=rp, Where=(rp.RESOURCE_ID.In(Parameter("ids", len(delete_ids)))).And (rp.NAME == PropertyName.fromElement(caldavxml.ScheduleCalendarTransp).toString()), ).on(sqlTxn, ids=delete_ids) yield sqlTxn.commit() sqlTxn = sqlStore.newTransaction() yield removeProperty(sqlTxn, PropertyName.fromElement(caldavxml.CalendarFreeBusySet)) yield sqlTxn.commit() yield cleanPropertyStore() except RuntimeError: f = Failure() yield sqlTxn.abort() f.raiseException()