def init_auditlog(portal): """Initialize the contents for the audit log """ # reindex the auditlog folder to display the icon right in the setup portal.bika_setup.auditlog.reindexObject() # Initialize contents for audit logging start = time.time() uid_catalog = api.get_tool("uid_catalog") brains = uid_catalog() total = len(brains) logger.info("Initializing {} objects for the audit trail...".format(total)) for num, brain in enumerate(brains): # Progress notification if num and num % 1000 == 0: transaction.commit() logger.info("{}/{} ojects initialized for audit logging".format( num, total)) # End progress notification if num + 1 == total: end = time.time() duration = float(end - start) logger.info( "{} ojects initialized for audit logging in {:.2f}s".format( total, duration)) if api.get_portal_type(brain) in SKIP_TYPES_FOR_AUDIT_LOG: continue obj = api.get_object(brain) if not supports_snapshots(obj): continue if has_snapshots(obj): continue # Take one snapshot per review history item rh = api.get_review_history(obj, rev=False) for item in rh: actor = item.get("actor") user = get_user(actor) if user: # remember the roles of the actor item["roles"] = get_roles(user) # The review history contains the variable "time" which we will set # as the "modification" time timestamp = item.pop("time", DateTime()) item["time"] = timestamp.ISO() item["modified"] = timestamp.ISO() item["remote_address"] = None take_snapshot(obj, **item)
def ObjectInitializedEventHandler(obj, event): """Object has been created """ # only snapshot supported objects if not supports_snapshots(obj): return # object has already snapshots if has_snapshots(obj): return # take a new snapshot take_snapshot(obj, action="create")