Skip to content

Commit

Permalink
Modified code to run on both dmsmail versions
Browse files Browse the repository at this point in the history
  • Loading branch information
sgeulette committed Sep 9, 2022
1 parent 8a315de commit 46c7240
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
18 changes: 9 additions & 9 deletions scripts/run-del-dv.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
# -*- coding: utf-8 -*-
from imio.helpers.content import object_values
from zope.annotation import IAnnotations

from plone import api

import logging
import transaction


portal = obj # noqa

logger = logging.getLogger('del dv')
types = ['dmsincomingmail', 'dmsincoming_email', 'dmsoutgoingmail']
count = 0

pc = portal.portal_catalog
brains = pc.unrestrictedSearchResults(portal_type=types)
for brain in brains:
mail = brain.getObject()
for fobj in object_values(mail, ['DmsFile', 'DmsAppendixFile', 'ImioDmsFile']):
annot = IAnnotations(fobj)
if 'collective.documentviewer' not in annot:
continue
del annot['collective.documentviewer']
for contained in mail.objectValues():
if contained.__class__.__name__ in ['DmsFile', 'DmsAppendixFile', 'ImioDmsFile']:
count += 1
api.content.delete(obj=contained, check_linkintegrity=False)

logger.warn('Deleted {} files'.format(count))
transaction.commit()
3 changes: 1 addition & 2 deletions scripts/run-del-files.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
count = 0
for brain in brains:
mail = brain.getObject()
# files = object_values(mail, ['DmsFile', 'DmsAppendixFile', 'ImioDmsFile']) dmsmail 3.0 only
for contained in mail.objectValues(): # works with dmsmail 2.3
for contained in mail.objectValues():
if contained.__class__.__name__ in ['DmsFile', 'DmsAppendixFile', 'ImioDmsFile']:
count += 1
api.content.delete(obj=contained, check_linkintegrity=False)
Expand Down

0 comments on commit 46c7240

Please sign in to comment.