def save_objectchanges(branch, batch_time, chgmap): logger = logging.getLogger('download') logger.info('Saving object change audit trail') userdict = dict([(user.name, user) for user in SalesforceUser.objects.all()]) inserted = 0 for aType in chgmap.keys(): logger.debug('Type: %s' % aType) for change in chgmap[aType]: if userdict.has_key(change.lastModifiedByName): theUser = userdict[change.lastModifiedByName] else: theUser = SalesforceUser() theUser.userid = change.lastModifiedById[0:15] theUser.name = change.lastModifiedByName theUser.save() userdict[theUser.name] = theUser fullName = change.fullName if SFAPIAssetMap.has_key(aType): fix = SFAPIAssetMap[aType] if fix.endswith(':'): fullName = fix + fullName else: fullName += fix lastchangelist = list(UserChange.objects.filter(branch=branch, apex_name=fullName).order_by('-last_update')) if len(lastchangelist) > 0: recent = lastchangelist[0] else: recent = UserChange() recent.branch = branch recent.apex_id = change.id recent.sfuser = theUser recent.apex_name = fullName recent.last_update = change.lastModifiedDate recent.batch_time = batch_time recent.object_type = aType recent.save() inserted += 1 logger.debug('Not found, inserting %s' % fullName) if recent.last_update < change.lastModifiedDate: logger.debug('changed: userid=%s userid=%s last_update=%s lastModified=%s' % (recent.sfuser.userid, theUser.userid, recent.last_update, change.lastModifiedDate)) recent = UserChange() recent.branch = branch recent.apex_id = change.id recent.sfuser = theUser recent.apex_name = fullName recent.last_update = change.lastModifiedDate recent.batch_time = batch_time recent.object_type = aType recent.save() inserted += 1 logger.debug('Changed, inserting %s' % fullName) logger.info('Audited objects inserted: %d' % inserted)
def save_userchanges(branch, classes, triggers, pages): allchanges = classes + triggers + pages batch_time = datetime.datetime.now() userdict = dict([(user.user_id, user) for user in SalesforceUser.objects.all()]) for change in allchanges: lastModId = change['LastModifiedById'] if userdict.has_key(lastModId): theUser = userdict[lastModId] else: theUser = SalesforceUser() theUser.user_id = lastModId theUser.name = change['LastModifiedBy']['Name'] theUser.email = change['LastModifiedBy']['Email'] theUser.save() recents = list( UserChange.objects.filter( apex_id__exact=change['Id'], branch=branch).order_by('last_update').reverse()[:1]) if len(recents) == 0: recent = UserChange() recent.branch = branch recent.apex_id = change['Id'] recent.apex_name = change['Name'] recent.sfuser = theUser lu = change['LastModifiedDate'][0:-9] recent.last_update = datetime.datetime.strptime( lu, '%Y-%m-%dT%H:%M:%S') recent.batch_time = batch_time else: recent = recents[0] if recent.sfuser == None or recent.sfuser.user_id != change[ 'LastModifiedById']: lu = change['LastModifiedDate'][0:-9] recent.last_update = datetime.datetime.strptime( lu, '%Y-%m-%dT%H:%M:%S') recent.batch_time = batch_time recent.save() return batch_time
def save_userchanges(branch, classes, triggers, pages): allchanges = classes + triggers + pages batch_time = datetime.datetime.now() userdict = dict([(user.user_id, user) for user in SalesforceUser.objects.all()]) for change in allchanges: lastModId = change['LastModifiedById'] if userdict.has_key(lastModId): theUser = userdict[lastModId] else: theUser = SalesforceUser() theUser.user_id = lastModId theUser.name = change['LastModifiedBy']['Name'] theUser.email = change['LastModifiedBy']['Email'] theUser.save() recents = list(UserChange.objects.filter(apex_id__exact=change['Id'], branch=branch).order_by('last_update').reverse()[:1]) if len(recents) == 0: recent = UserChange() recent.branch = branch recent.apex_id = change['Id'] recent.apex_name = change['Name'] recent.sfuser = theUser lu = change['LastModifiedDate'][0:-9] recent.last_update = datetime.datetime.strptime(lu, '%Y-%m-%dT%H:%M:%S') recent.batch_time = batch_time else: recent = recents[0] if recent.sfuser == None or recent.sfuser.user_id != change['LastModifiedById']: lu = change['LastModifiedDate'][0:-9] recent.last_update = datetime.datetime.strptime(lu, '%Y-%m-%dT%H:%M:%S') recent.batch_time = batch_time recent.save() return batch_time
def save_objectchanges(branch, batch_time, chgmap): logger = logging.getLogger('download') logger.info('Saving object change audit trail') userdict = dict([(user.name, user) for user in SalesforceUser.objects.all()]) inserted = 0 for aType in chgmap.keys(): logger.debug('Type: %s' % aType) for change in chgmap[aType]: if userdict.has_key(change.lastModifiedByName): theUser = userdict[change.lastModifiedByName] else: theUser = SalesforceUser() theUser.userid = change.lastModifiedById[0:15] theUser.name = change.lastModifiedByName theUser.save() userdict[theUser.name] = theUser fullName = change.fullName if SFAPIAssetMap.has_key(aType): fix = SFAPIAssetMap[aType] if fix.endswith(':'): fullName = fix + fullName else: fullName += fix lastchangelist = list( UserChange.objects.filter( branch=branch, apex_name=fullName).order_by('-last_update')) if len(lastchangelist) > 0: recent = lastchangelist[0] else: recent = UserChange() recent.branch = branch recent.apex_id = change.id recent.sfuser = theUser recent.apex_name = fullName recent.last_update = change.lastModifiedDate recent.batch_time = batch_time recent.object_type = aType recent.save() inserted += 1 logger.debug('Not found, inserting %s' % fullName) if recent.last_update < change.lastModifiedDate: logger.debug( 'changed: userid=%s userid=%s last_update=%s lastModified=%s' % (recent.sfuser.userid, theUser.userid, recent.last_update, change.lastModifiedDate)) recent = UserChange() recent.branch = branch recent.apex_id = change.id recent.sfuser = theUser recent.apex_name = fullName recent.last_update = change.lastModifiedDate recent.batch_time = batch_time recent.object_type = aType recent.save() inserted += 1 logger.debug('Changed, inserting %s' % fullName) logger.info('Audited objects inserted: %d' % inserted)