def add_missing_uuids(context): catalog = getToolByName(context, 'portal_catalog') query = {'object_provides': IDexterityContent.__identifier__} for b in catalog.unrestrictedSearchResults(query): ob = b.getObject() if IUUID(ob, None) is None: addAttributeUUID(ob, None) ob.reindexObject(idxs=['UID'])
def make_portal_referenceable(event): """ Enable the portal to support Archetypes references. """ if event.profile_id != 'profile-resonate:default': return portal = getToolByName(event.tool, 'portal_url').getPortalObject() handlers.addAttributeUUID(portal, None) uidcatalog.added_handler(portal, event)
def add_uuid(context): catalog = getToolByName(context, 'portal_catalog') brains = catalog.searchResults(object_provides=IAlias.__identifier__) for brain in brains: obj = brain.getObject() addAttributeUUID(obj, None) obj.reindexObject(idxs=['object_provides', 'UID']) try: for comment_id in obj.talkback.objectIds(): obj.unrestrictedTraverse(('talkback', comment_id)).unindexObject() except AttributeError: # no talkback pass
def add_uuid(context): catalog = getToolByName(context, 'portal_catalog') brains = catalog.searchResults(object_provides=IAlias.__identifier__) for brain in brains: obj = brain.getObject() addAttributeUUID(obj, None) obj.reindexObject(idxs=['object_provides', 'UID']) try: for comment_id in obj.talkback.objectIds(): obj.unrestrictedTraverse( ('talkback', comment_id)).unindexObject() except AttributeError: # no talkback pass
def get_id(self, context): """If an object is created via portal factory we don't get a id, we have to wait till the object is really created. TODO: a better check if we are in the portal factory! """ try: context_id = IUUID(context) # We must ensure that this case can't happen, any object translatable # will have an UUID (in any case we can be at the portal factory!) except KeyError: addAttributeUUID(context, None) context.reindexObject(idxs=['UID']) context_id = IUUID(context) return context_id
def upgrade(context): # Add missing UIDs to already existing dexterity content types # Borrowed from plone.app.dexterity :) logger = logging.getLogger('plone.multilingual') logger.info('Adding missing UUIDs to the already existing ' 'dexterity content types') catalog = getToolByName(context, 'portal_catalog') query = {'object_provides': IDexterityContent.__identifier__} results = catalog.unrestrictedSearchResults(query) for b in results: ob = b.getObject() if IUUID(ob, None) is None: addAttributeUUID(ob, None) ob.reindexObject(idxs=['UID']) logger.info('Added %s missing UUIDs' % len(results)) # Upgrade utility, and convert intids to uuids intids = queryUtility(IIntIds) if not intids: intids = getAllUtilitiesRegisteredFor(IIntIds)[0] oldstorage = getToolByName(context, 'canonical_storage') for canonicalintid in oldstorage.canonicals: canonicaluuid = IUUID(intids.getObject(canonicalintid)) translations = oldstorage.canonicals[canonicalintid].languages upgradedcanonical = Canonical() for lang in translations.keys(): langintid = translations[lang] langobj = intids.getObject(langintid) languuid = IUUID(langobj) upgradedcanonical.add_item(lang, languuid) storage = getUtility(IMultilingualStorage) storage.add_canonical(canonicaluuid, upgradedcanonical) logger.info('%s' % upgradedcanonical.languages)