Skip to content

Commit

Permalink
Workaround for a bug in iTC that could cause duplicate weekly reports
Browse files Browse the repository at this point in the history
  • Loading branch information
Ole Zorn committed Mar 26, 2012
1 parent fd918a9 commit 7991dea
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Classes/ReportDownloadOperation.m
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -183,6 +183,23 @@ - (void)main
if (originalFilename && [reportCSV length] > 0) { if (originalFilename && [reportCSV length] > 0) {
//Parse report CSV: //Parse report CSV:
Report *report = [Report insertNewReportWithCSV:reportCSV inAccount:account]; Report *report = [Report insertNewReportWithCSV:reportCSV inAccount:account];

//Check if the downloaded report is actually the one we expect
//(mostly to work around a bug in iTC that causes the wrong weekly report to be downloaded):
NSString *downloadedReportDateString = nil;
if ([report isKindOfClass:[WeeklyReport class]]) {
WeeklyReport *weeklyReport = (WeeklyReport *)report;
downloadedReportDateString = [dateFormatter stringFromDate:weeklyReport.endDate];
} else {
downloadedReportDateString = [dateFormatter stringFromDate:report.startDate];
}
if (![reportDateString isEqualToString:downloadedReportDateString]) {
NSLog(@"Downloaded report has incorrect date, ignoring");
[[report managedObjectContext] deleteObject:report];
report = nil;
continue;
}

if (report && originalFilename) { if (report && originalFilename) {
NSManagedObject *originalReport = [NSEntityDescription insertNewObjectForEntityForName:@"ReportCSV" inManagedObjectContext:moc]; NSManagedObject *originalReport = [NSEntityDescription insertNewObjectForEntityForName:@"ReportCSV" inManagedObjectContext:moc];
[originalReport setValue:reportCSV forKey:@"content"]; [originalReport setValue:reportCSV forKey:@"content"];
Expand Down

0 comments on commit 7991dea

Please sign in to comment.