diff --git a/storage/compat/common.py b/storage/compat/common.py index 879d4df..d0fb583 100644 --- a/storage/compat/common.py +++ b/storage/compat/common.py @@ -26,7 +26,6 @@ class Storage(common.Storage): self.session.execute(stmt) mark_changed(self.session) - def getUidTable(self, schema=None): #table = getExistingTable(self.storage, self.tableName) #if table is None: diff --git a/util.py b/util.py index 154079a..78d0130 100644 --- a/util.py +++ b/util.py @@ -142,14 +142,25 @@ def records(context, name, factory): # UID stuff class IUid(Interface): - """Provides uid property.""" uid = Attribute("Unique Identifier") + def getItem(uid, intIds=None, storage=None): if storage is not None and '-' in uid: return storage.getItem(uid) - return getObjectForUid(uid, intIds=intIds) + obj = getObjectForUid(uid, intIds=intIds) + if obj is None and storage is not None: + return getMigratedItem(uid, storage) + return obj + +def getMigratedItem(uid, storage): + t = self.getUidTable + stmt = t.select().where(t.c.legacy == int(uid)) + newId = storage.session.execute(stmt).scalar() + if newId is not None: + return storage.getItem(newUid) + return None def getObjectForUid(uid, intIds=None): if uid == '*': # wild card @@ -173,9 +184,10 @@ def getUidForObject(obj, intIds=None): intIds = component.getUtility(IIntIds) return str(intIds.queryId(obj)) -def getObjectsForUids(uids, adapt=True): +def getObjectsForUids(uids, adapt=True, storage=None): intIds = component.getUtility(IIntIds) - result = [getObjectForUid(uid, intIds) for uid in uids] + #result = [getObjectForUid(uid, intIds) for uid in uids] + result = [getItem(uid, intIds, storage=storage) for uid in uids] if adapt: from loops.common import adapted return [adapted(obj) for obj in result if obj is not None]