## Script (Python) "writeStudentImages" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters= ##title= ## # $Id: removeImagesFromZODB.py 2349 2007-10-11 15:45:18Z joachim $ """ """ try: from Products.zdb import set_trace except: def set_trace(): pass mtool = context.portal_membership member = mtool.getAuthenticatedMember() if str(member) not in ('admin','joachim'): return import logging import DateTime logger = logging.getLogger('Skins.removeImagesFromZODB') request = context.REQUEST session = request.SESSION response = request.RESPONSE setheader = request.RESPONSE.setHeader def rwrite(s): response.setHeader('Content-type','text/html; charset=ISO-8859-15') response.write("%s
\n\r" % s) #logger.info('') students = context.students_catalog() starttime = DateTime.DateTime() logger.info("Start removing %d student images" % len(students)) count = 0 chunk = 50 stool = context.portal_schemas schemas = ['student_application', 'student_clearance', ] students_folder = context.portal_url.getPortalObject().campus.students image_keys = {} for schema_id in schemas: schema = getattr(stool,schema_id) image_keys[schema_id] = [key for key in schema.keys() if schema[key].meta_type == "CPS Image Field"] for student in students: count += 1 if count and not count % chunk: logger.info("removed %d of %d student images " % (count,len(students))) context.waeup_tool.doCommit() for schema_id in schemas: try: doc_id = getattr(getattr(students_folder,student.id), schema_id[len('student_'):]).getContent().getId() except: continue doc = context.portal_repository[doc_id] ids = [key for key in image_keys[schema_id] if key in doc.objectIds()] if not ids: continue try: doc.manage_delObjects(ids) #logger.info("removed %s images " % (student.id)) except: set_trace() logger.info("!!!!!!!could not remove %s images " % (student.id)) logger.info("Finished removing %d student images" % len(students))