恐怕您需要手动遍历整个 ZODB。如果这些对象是内容对象,您应该能够使用标准的 OFS 方法:
from collections import deque
from datetime import datetime
import transaction
from zope.app.component.hooks import setSite
from Testing.makerequest import makerequest
from AccessControl.SecurityManagement import newSecurityManager
from my.newproduct.types import ArchetypesContentType
site_id = 'Plone' # adjust to match your Plone site object id.
admin_user = 'admin' # usually 'admin', probably won't need adjusting
app = makerequest(app)
site = app[site_id]
setSite(site)
user = app.acl_users.getUser(admin_user).__of__(site.acl_users)
newSecurityManager(None, user)
def treeWalker(root):
# stack holds (parent, id, obj) tuples
stack = deque([(None, None, root)])
while stack:
parent, id, next = stack.popleft()
try:
stack.extend((next, id, child) for id, child in next.objectItems())
except AttributeError:
# No objectItems method
pass
yield parent, id, next
count = 0
for parent, id, obj in treeWalker(site):
if isinstance(obj, ArchetypesContentType):
print 'Found content type object {} at {}'.format(id, '/'.join(object.getPhysicalPath()))
obj._p_changed = True # mark it as changed, force a commit
count += 1
if count % 100 == 0:
# flush changes so far to disk to minimize memory usage
transaction.savepoint(True)
print '{} - Processed {} items'.format(datetime.now(), count)
transaction.commit()
这假设您已经包含了您链接到的解决方法;尝试对ZODB.broken.Broken
对象进行上述操作没有什么意义。
上面的脚本作为一个bin/instance run
脚本,这样运行它:
bin/instance run path/to/this/script.py
您将处理站点中的所有内容,这是一个相当繁重的过程,将涉及大量缓存流失,并且可能涉及具有潜在冲突的大量提交。您真的不想将其作为通过网络脚本运行。