def rebuild_catalog(self): context = self.context upgrades.upgrade_plone(context) catalog = getToolByName(self.context, 'portal_catalog') upgrades.log('Recataloging items') brains = catalog.search({}) lb = len(brains) for i, itm in enumerate(brains): try: obj = context.unrestrictedTraverse(itm.getPath()) uid = '/'.join(obj.getPhysicalPath()) if not uid in catalog._catalog.uids: catalog.catalog_object(obj) catalog.indexObject(obj) # let the objects be wrapped now by plone.indexer if IIndexableObject.providedBy(obj): interface.noLongerProvides(obj, IIndexableObject) catalog.reindexObject(obj, [ "allowedRolesAndUsers", "object_provides", "sortable_title", "getObjPositionInParent", "getObjSize", "is_folderish", "syndication_enabled", "is_default_page", "getIcon", ]) except Exception, e: upgrades.log('pb cataloging %s; %s' % (itm.getPath(), e)) if i % 10 == 0: upgrades.log('Recatalog: %s on %s (%s %s)' % (i, lb, (i / (1.0 * lb) * 100), '%')) upgrades.commit(context)
def rebuild_catalog(self): context = self.context upgrades.upgrade_plone(context) catalog = getToolByName(self.context, 'portal_catalog') upgrades.log('Recataloging items') brains = catalog.search({}) lb = len(brains) for i, itm in enumerate(brains): try: obj = context.unrestrictedTraverse(itm.getPath()) uid = '/'.join(obj.getPhysicalPath()) if not uid in catalog._catalog.uids: catalog.catalog_object(obj) catalog.indexObject(obj) # let the objects be wrapped now by plone.indexer if IIndexableObject.providedBy(obj): interface.noLongerProvides(obj, IIndexableObject) catalog.reindexObject(obj, [ "allowedRolesAndUsers", "object_provides", "sortable_title", "getObjPositionInParent", "getObjSize", "is_folderish", "syndication_enabled", "is_default_page", "getIcon"] ) except Exception, e: upgrades.log('pb cataloging %s; %s' % (itm.getPath(), e)) if i % 10 == 0: upgrades.log('Recatalog: %s on %s (%s %s)' % ( i, lb, (i / (1.0 * lb) * 100), '%')) upgrades.commit(context)
def getWrappedObjectNew(self, obj, portal, catalog): # Returned wrapped 'obj' object with IIndexable wrapper wrapper = None if not IIndexableObject.providedBy(obj): # This is the CMF 2.2 compatible approach, # which should be used going forward wrapper = queryMultiAdapter((obj, catalog), IIndexableObject) return wrapper and wrapper or obj
def catalog_object(self, obj, uid=None, idxs=[], update_metadata=1, pghandler=None): mode = self.mode if mode in (DISABLE_MODE, DUAL_MODE): result = self.patched.catalog_object(obj, uid, idxs, update_metadata, pghandler) if mode == DISABLE_MODE: return result wrapped_object = None if not IIndexableObject.providedBy(obj): # This is the CMF 2.2 compatible approach, which should be used # going forward wrapper = queryMultiAdapter((obj, self.catalogtool), IIndexableObject) if wrapper is not None: wrapped_object = wrapper else: wrapped_object = obj else: wrapped_object = obj conn = self.conn catalog = self.catalog if idxs == []: idxs = catalog.indexes.keys() index_data = {} for index_name in idxs: index = getIndex(catalog, index_name) if index is not None: value = index.get_value(wrapped_object) if value in (None, 'None'): # yes, we'll index null data... value = None index_data[index_name] = value if update_metadata: metadata = {} for meta_name in catalog.names: attr = getattr(wrapped_object, meta_name, MV) if (attr is not MV and safe_callable(attr)): attr = attr() metadata[meta_name] = attr # XXX Also, always index path so we can use it with the brain # to make urls metadata['_path'] = wrapped_object.getPhysicalPath() index_data['_metadata'] = dumps(metadata) uid = getUID(obj) try: doc = conn.get(self.catalogsid, self.catalogtype, uid) self.registerInTransaction(uid, td.Actions.modify, doc) except NotFoundException: self.registerInTransaction(uid, td.Actions.add) conn.index(index_data, self.catalogsid, self.catalogtype, uid) if self.registry.auto_flush: conn.refresh()
def reimplement(self): catalog = getToolByName(self.context, 'portal_catalog') count = 0 for i in catalog.search({}): o = i.getObject() if not IIndexableObject.providedBy(o): count += 1 alsoProvides(o, IIndexableObject) msg = '%s have been marked as indexable' % count upgrades.log(msg)
def catalog_object(self, object, uid, idxs=[], update_metadata=1, pghandler=None): w = object if not IIndexableObject.providedBy(object): # This is the CMF 2.2 compatible approach, which should be used going forward wrapper = component.queryMultiAdapter((object, self), IIndexableObject) if wrapper is not None: w = wrapper ZCatalog.catalog_object(self, w, uid, idxs, update_metadata, pghandler=pghandler)
def catalog_object(self, obj, uid=None, idxs=[], update_metadata=1, pghandler=None): mode = self.mode if mode in (DISABLE_MODE, DUAL_MODE): result = self.patched.catalog_object( obj, uid, idxs, update_metadata, pghandler) if mode == DISABLE_MODE: return result wrapped_object = None if not IIndexableObject.providedBy(obj): # This is the CMF 2.2 compatible approach, which should be used # going forward wrapper = queryMultiAdapter((obj, self.catalogtool), IIndexableObject) if wrapper is not None: wrapped_object = wrapper else: wrapped_object = obj else: wrapped_object = obj conn = self.conn catalog = self.catalog if idxs == []: idxs = catalog.indexes.keys() index_data = {} for index_name in idxs: index = getIndex(catalog, index_name) if index is not None: value = index.get_value(wrapped_object) if value in (None, 'None'): # yes, we'll index null data... value = None index_data[index_name] = value if update_metadata: metadata = {} for meta_name in catalog.names: attr = getattr(wrapped_object, meta_name, MV) if (attr is not MV and safe_callable(attr)): attr = attr() metadata[meta_name] = attr # XXX Also, always index path so we can use it with the brain # to make urls metadata['_path'] = wrapped_object.getPhysicalPath() index_data['_metadata'] = dumps(metadata) uid = getUID(obj) try: doc = conn.get(self.catalogsid, self.catalogtype, uid) self.registerInTransaction(uid, td.Actions.modify, doc) except NotFoundException: self.registerInTransaction(uid, td.Actions.add) conn.index(index_data, self.catalogsid, self.catalogtype, uid) if self.registry.auto_flush: conn.refresh()
def get_wrapped_object(obj, es): wrapped_object = None if not IIndexableObject.providedBy(obj): # This is the CMF 2.2 compatible approach, which should be used # going forward wrapper = queryMultiAdapter((obj, es.catalogtool), IIndexableObject) if wrapper is not None: wrapped_object = wrapper else: wrapped_object = obj else: wrapped_object = obj return wrapped_object
def getWrappedObjectNew(self, obj, portal, catalog): # Returned wrapped 'obj' object with IIndexable wrapper w = obj if not IIndexableObject.providedBy(obj): # BBB: Compatibility wrapper lookup. Should be removed in Plone 4. register_bbb_indexers() wrapper = queryMultiAdapter((obj, portal), _old_IIndexableObjectWrapper) if wrapper is not None: w = wrapper else: # This is the CMF 2.2 compatible approach, which should be used going forward wrapper = queryMultiAdapter((obj, catalog), IIndexableObject) if wrapper is not None: w = wrapper return w
def get_indexable_wrapper(self, obj): if IS_NEW: wrapper = None if not IIndexableObject.providedBy(obj): wrapper = queryMultiAdapter((obj, self.catalog), IIndexableObject) else: wf = getattr(self.portal, 'portal_workflow', None) if wf is not None: vars = wf.getCatalogVariablesFor(obj) else: vars = {} wrapper = getMultiAdapter((obj, self.portal), _old_IIndexableObjectWrapper) wrapper.update(vars) return wrapper and wrapper or obj
def catalog_object(self, object, uid=None, idxs=None, update_metadata=1, pghandler=None): if idxs is None: idxs = [] self._increment_counter() w = object if not IIndexableObject.providedBy(object): # This is the CMF 2.2 compatible approach, which should be used # going forward wrapper = queryMultiAdapter((object, self), IIndexableObject) if wrapper is not None: w = wrapper ZCatalog.catalog_object(self, w, uid, idxs, update_metadata, pghandler=pghandler)
def plone_catalog_object(self, object, uid=None, idxs=None, update_metadata=1, pghandler=None, quick=False): if idxs is None: idxs = [] self._increment_counter() w = object if not IIndexableObject.providedBy(object): # This is the CMF 2.2 compatible approach, which should be used # going forward wrapper = queryMultiAdapter((object, self), IIndexableObject) if wrapper is not None: w = wrapper ZCatalog.catalog_object(self, w, uid, idxs, update_metadata, pghandler=pghandler, quick=quick)
def get_data(self, attributes): if not IIndexableObject.providedBy(self.context): catalog = getToolByName(self.context, 'portal_catalog') wrapped = queryMultiAdapter( (self.context, catalog), IIndexableObject, default=self.context) else: wrapped = self.context schema = self.manager.schema if attributes is None: attributes = set(schema.fields.keys()) else: attributes = set(schema.fields.keys()).intersection(attributes) if schema.unique_key not in attributes: attributes.add(schema.unique_key) data = {} for name in attributes: if name.startswith('_'): continue if name == 'path': value = '/'.join(self.context.getPhysicalPath()) else: try: value = getattr(wrapped, name) if callable(value): value = value() except (AttributeError, TypeError): continue if value is None: continue field_class = schema.field_types[ schema.fields[name][u'type']][u'class'] multivalued = schema.fields[name].get(u'multiValued', False) converter = CONVERTERS.get(field_class) if converter is not None: value = converter(value, multivalued) data[name] = value return data