Ejemplo n.º 1
0
 def _rawEnum(self, callback, *args, **kwargs):
     """Finds all object to check if they are 'referenceable'.
     """
     catalog = getToolByName(self, 'portal_catalog')
     brains = catalog(id=[])
     for b in brains:
         o = b.getObject()
         if o is not None:
             if IBaseObject.isImplementedBy(o):
                 callback(o, *args, **kwargs)
         else:
             log('no object for brain: %s:%s' % (b,b.getURL()))
Ejemplo n.º 2
0
def migrateUIDs(portal, out):
    count=0
    uc = getToolByName(portal, UID_CATALOG)    
    print >>out, 'Migrating uids\n'
    
    # temporary add a new index    
    if olduididx not in uc.indexes():
        uc.addIndex(olduididx, 'FieldIndex', extra=None)
        if not olduididx in uc.schema():
            uc.addColumn(olduididx)
    
    # clear UID Catalog 
    uc.manage_catalogClear()
    
    # rebuild UIDS on objects and in catalog
    allbrains = portal.portal_catalog()
    for brain in allbrains:
        # get a uid for each thingie
        obj = brain.getObject()
        if not IBaseObject.isImplementedBy(obj): 
            continue #its no Archetype instance, so leave it
        
        objUID = getattr(aq_base(obj), '_uid', None)        
        if objUID is not None: #continue    # not an old style AT?
            setattr(obj, olduididx, objUID) # this one can be part of the catalog
            delattr(obj, '_uid')
            setattr(obj, UUID_ATTR, None)
        obj._register()            # creates a new UID
        obj._updateCatalog(portal) # to be sure
        count+=1
        if not count % 10:
            print >>out, '.',
        # avoid eating up all RAM
        if not count % 250:
            print >>out, '*',
            transaction.savepoint(optimistic=True)
    print >>out, '\nDone\n'
    if USE_FULL_TRANSACTIONS:
        transaction.commit()
    else:
        transaction.savepoint(optimistic=True)

    print >>out, count, "UID's migrated."
Ejemplo n.º 3
0
Archivo: utils.py Proyecto: dtgit/dtedu
def install_indexes(self, out, types):
    portal_catalog = catalog = getToolByName(self, 'portal_catalog')
    for cls in types:
        if 'indexes' not in cls.installMode:
            continue

        for field in cls.schema.fields():
            if not field.index:
                continue

            if isinstance(field.index, basestring):
                index = (field.index,)
            elif isinstance(field.index, (tuple, list)):
                index = field.index
            else:
                raise SyntaxError("Invalid Index Specification %r"
                                  % field.index)

            for alternative in index:
                installed = None
                index_spec = alternative.split(':', 1)
                use_column  = 0
                if len(index_spec) == 2 and index_spec[1] in ('schema', 'brains'):
                    use_column = 1
                index_spec = index_spec[0]

                accessor = field.getIndexAccessorName()

                parts = index_spec.split('|')
                # we want to be able to specify which catalog we want to use
                # for each index. syntax is
                # index=('member_catalog/:schema',)
                # portal catalog is used by default if not specified
                if parts[0].find('/') > 0:
                    str_idx = parts[0].find('/')
                    catalog_name = parts[0][:str_idx]
                    parts[0] = parts[0][str_idx+1:]
                    catalog = getToolByName(self, catalog_name)
                else:
                    catalog = portal_catalog
                
                #####################
                # add metadata column 
                
                # lets see if the catalog is itself an Archetype:
                isArchetype = IBaseObject.isImplementedBy(catalog)
                # archetypes based zcatalogs need to provide a different method 
                # to list its schema-columns to not conflict with archetypes 
                # schema                
                hasNewWayMethod = hasattr(catalog, 'zcschema')
                hasOldWayMethod = not isArchetype and hasattr(catalog, 'schema')
                notInNewWayResults = hasNewWayMethod and accessor not in catalog.zcschema()
                notInOldWayResults = hasOldWayMethod and accessor not in catalog.schema()
                if use_column and (notInNewWayResults or notInOldWayResults):
                    try:
                        catalog.addColumn(accessor)
                    except:
                        import traceback
                        traceback.print_exc(file=out)

                ###########
                # add index
                
                # if you want to add a schema field without an index
                #if not parts[0]:
                #    continue

                for itype in parts:
                    extras = itype.split(',')
                    if len(extras) > 1:
                        itype = extras[0]
                        props = Extra()
                        for extra in extras[1:]:
                            name, value = extra.split('=')
                            setattr(props, name.strip(), value.strip())
                    else:
                        props = None
                    try:
                        #Check for the index and add it if missing
                        catalog.addIndex(accessor, itype,
                                         extra=props)
                        catalog.manage_reindexIndex(ids=(accessor,))
                    except:
                        # FIXME: should only catch "Index Exists"
                        # damned string exception !
                        pass
                    else:
                        installed = 1
                        break

                if installed:
                    break