Closed paregorios closed 6 years ago
How are you invoking the script?
bin/instance run scripts/foobar_indexer.py
It does something like:
catalog = app.plone.portal_catalog
for b in catalog.unrestrictedSearchResults(portal_type='Place'):
ob = b._unrestrictedGetObject()
# do something to determine whether to reindex or not
ob.reindexObject()
It should work if you do bin/instance -Oplone run scripts/foobar_indexer.py
. That'll make sure that plone
is activated as the site to use for Zope component loookups.
My scripts to reindex often end up looking like this to make sure that it commits periodically rather than ending up with a giant long-running transaction that is more likely to conflict with other transactions:
import transaction
catalog = app.plone.portal_catalog
i = 0
for b in catalog.unrestrictedSearchResults(portal_type='Place'):
ob = b._unrestrictedGetObject()
# do something to determine whether to reindex or not
ob.reindexObject()
i += 1
if not i % 200:
print i
transaction.commit()
transaction.commit()
@davisagli thanks for the tip. That's got it!