Fjalapeno has uploaded a new change for review. https://gerrit.wikimedia.org/r/209024
Change subject: Migration "fixes" - Bug: T96607 Sending migration failures to OTRS Adding build number to user agent string Adding logic to remove old backups after 30 days ...................................................................... Migration "fixes" - Bug: T96607 Sending migration failures to OTRS Adding build number to user agent string Adding logic to remove old backups after 30 days Change-Id: I2c9dccbfb04803dc4d80ee8dcae64b76f13a39e3 --- M Wikipedia/AppDelegate.m M Wikipedia/Data/OldDataSchemaMigrator.h M Wikipedia/Data/OldDataSchemaMigrator.m M Wikipedia/View Controllers/DataMigration/DataMigrationProgressViewController.h M Wikipedia/View Controllers/DataMigration/DataMigrationProgressViewController.m M Wikipedia/mw-utils/WikipediaAppUtils.m 6 files changed, 97 insertions(+), 13 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/apps/ios/wikipedia refs/changes/24/209024/1 diff --git a/Wikipedia/AppDelegate.m b/Wikipedia/AppDelegate.m index 32c5e32..e24558c 100644 --- a/Wikipedia/AppDelegate.m +++ b/Wikipedia/AppDelegate.m @@ -48,6 +48,8 @@ #endif if (![self presentDataMigrationViewControllerIfNeeded]) { + [self performMigrationCleanup]; + [self presentRootViewController:NO withSplash:YES]; } @@ -137,6 +139,10 @@ #pragma mark - Migration +- (void)performMigrationCleanup { + [DataMigrationProgressViewController removeOldDataBackupIfNeeded]; +} + - (BOOL)presentDataMigrationViewControllerIfNeeded { if ([DataMigrationProgressViewController needsMigration]) { UIAlertView* dialog = @@ -160,7 +166,7 @@ - (void)alertView:(UIAlertView*)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex { if (alertView == self.dataMigrationAlert) { if (buttonIndex == alertView.cancelButtonIndex) { - [DataMigrationProgressViewController removeOldData]; + [DataMigrationProgressViewController moveOldDataToBackupLocation]; [self presentRootViewController:YES withSplash:NO]; } else { DataMigrationProgressViewController* migrationVC = [[DataMigrationProgressViewController alloc] init]; diff --git a/Wikipedia/Data/OldDataSchemaMigrator.h b/Wikipedia/Data/OldDataSchemaMigrator.h index bf7c549..c2ccdbd 100644 --- a/Wikipedia/Data/OldDataSchemaMigrator.h +++ b/Wikipedia/Data/OldDataSchemaMigrator.h @@ -50,6 +50,20 @@ */ - (void)migrateData; -+ (void)removeOldData; +/** + * Moves old data to backup location + */ ++ (void)moveOldDataToBackupLocation; + +/** + * Removes old data if it is older than the grace period for backups + */ ++ (void)removeOldDataIfOlderThanMaximumGracePeriod; + +/** + * Removes backups immediately + */ ++ (void)removeOldDataImmediately; + @end diff --git a/Wikipedia/Data/OldDataSchemaMigrator.m b/Wikipedia/Data/OldDataSchemaMigrator.m index cb45974..aa597ec 100644 --- a/Wikipedia/Data/OldDataSchemaMigrator.m +++ b/Wikipedia/Data/OldDataSchemaMigrator.m @@ -13,6 +13,10 @@ #import "NSManagedObjectContext+SimpleFetch.h" #import "Article+ConvenienceAccessors.h" +static NSString* const kWMFOldDataSchemaBackupDateKey = @"kWMFOldDataSchemaBackupDateKey"; +static NSUInteger const kWMFOldDataSchemaBackupExpirationTimeInDays = 30; + + @interface OldDataSchemaMigrator () @property (nonatomic, strong) ArticleDataContextSingleton* context; @@ -47,7 +51,13 @@ return [[NSFileManager defaultManager] fileExistsAtPath:filePath]; } -+ (void)removeOldData { ++ (BOOL)backupExists { + NSString* filePath = [self sqlitePath]; + NSString* backupPath = [filePath stringByAppendingString:@".bak"]; + return [[NSFileManager defaultManager] fileExistsAtPath:backupPath]; +} + ++ (void)moveOldDataToBackupLocation { NSString* filePath = [self sqlitePath]; NSString* backupPath = [filePath stringByAppendingString:@".bak"]; NSError* err = nil; @@ -56,7 +66,52 @@ error:&err]; if (err) { NSLog(@"Error backing up %@: %@", filePath, err); + } else { + [self setBackDateToNow]; } +} + ++ (void)removeOldDataIfOlderThanMaximumGracePeriod { + [self setBackupDateForPreexistingBackups]; + + if ([self shouldRemoveBackup]) { + [self removeOldDataImmediately]; + } +} + ++ (void)removeOldDataImmediately { + NSString* filePath = [self sqlitePath]; + NSString* backupPath = [filePath stringByAppendingString:@".bak"]; + [[NSFileManager defaultManager] removeItemAtPath:backupPath error:nil]; +} + ++ (void)setBackDateToNow { + NSDate* backupDate = [NSDate new]; + [[NSUserDefaults standardUserDefaults] setDouble:backupDate.timeIntervalSinceReferenceDate forKey:kWMFOldDataSchemaBackupDateKey]; + [[NSUserDefaults standardUserDefaults] synchronize]; +} + ++ (void)setBackupDateForPreexistingBackups { + if (([[NSUserDefaults standardUserDefaults] doubleForKey:kWMFOldDataSchemaBackupDateKey] < 1.0) && [self backupExists]) { + [self setBackDateToNow]; + } +} + ++ (BOOL)shouldRemoveBackup { + NSTimeInterval backupTimeInterval = [[NSUserDefaults standardUserDefaults] doubleForKey:kWMFOldDataSchemaBackupDateKey]; + if (backupTimeInterval < 1.0) { + return NO; + } + + NSDate* backupDate = [NSDate dateWithTimeIntervalSinceReferenceDate:backupTimeInterval]; + + NSTimeInterval backupExpiraton = kWMFOldDataSchemaBackupExpirationTimeInDays * 24 * 60 * 60; + + if ([[NSDate new] timeIntervalSinceDate:backupDate] > backupExpiraton) { + return YES; + } + + return NO; } - (void)migrateData { @@ -106,7 +161,7 @@ } [self.context saveContextAndPropagateChangesToStore:context completionBlock:^(NSError* error) { - [[self class] removeOldData]; + [[self class] moveOldDataToBackupLocation]; if (error) { [self.progressDelegate oldDataSchema:self didFinishWithError:error]; diff --git a/Wikipedia/View Controllers/DataMigration/DataMigrationProgressViewController.h b/Wikipedia/View Controllers/DataMigration/DataMigrationProgressViewController.h index cb3a248..0152416 100644 --- a/Wikipedia/View Controllers/DataMigration/DataMigrationProgressViewController.h +++ b/Wikipedia/View Controllers/DataMigration/DataMigrationProgressViewController.h @@ -23,8 +23,13 @@ @property (weak, nonatomic) IBOutlet UILabel* progressLabel; @property (weak, nonatomic) id<DataMigrationProgressDelegate> delegate; -// TODO: refactor these into class methods + (BOOL)needsMigration; -+ (void)removeOldData; + + ++ (void)moveOldDataToBackupLocation; + + ++ (void)removeOldDataBackupIfNeeded; + @end diff --git a/Wikipedia/View Controllers/DataMigration/DataMigrationProgressViewController.m b/Wikipedia/View Controllers/DataMigration/DataMigrationProgressViewController.m index 654217e..a1e4cda 100644 --- a/Wikipedia/View Controllers/DataMigration/DataMigrationProgressViewController.m +++ b/Wikipedia/View Controllers/DataMigration/DataMigrationProgressViewController.m @@ -81,9 +81,13 @@ return [OldDataSchemaMigrator exists] || [DataMigrator hasData]; } -+ (void)removeOldData { - [DataMigrator removeOldData]; - [OldDataSchemaMigrator removeOldData]; ++ (void)moveOldDataToBackupLocation { + [DataMigrator removeOldData]; //we do not back old old data + [OldDataSchemaMigrator moveOldDataToBackupLocation]; +} + ++ (void)removeOldDataBackupIfNeeded { + [OldDataSchemaMigrator removeOldDataIfOlderThanMaximumGracePeriod]; } - (void)runNewMigration { @@ -178,10 +182,10 @@ - (void)submitDataToDevs { MFMailComposeViewController* picker = [[MFMailComposeViewController alloc] init]; - picker.mailComposeDelegate = self; // + picker.mailComposeDelegate = self; - picker.subject = @"Wikipedia iOS app data migration failure"; - picker.toRecipients = @[@"bvib...@wikimedia.org"]; // @fixme do we have a better place to send these? + picker.subject = [NSString stringWithFormat:@"Feedback:%@", [WikipediaAppUtils versionedUserAgent]]; + picker.toRecipients = @[@"mobile-ios-wikipe...@wikimedia.org"]; NSString* filename = @"articleData6.sqlite"; NSArray* documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); diff --git a/Wikipedia/mw-utils/WikipediaAppUtils.m b/Wikipedia/mw-utils/WikipediaAppUtils.m index c471c2a..086a629 100644 --- a/Wikipedia/mw-utils/WikipediaAppUtils.m +++ b/Wikipedia/mw-utils/WikipediaAppUtils.m @@ -51,7 +51,7 @@ + (NSString*)versionedUserAgent { UIDevice* d = [UIDevice currentDevice]; return [NSString stringWithFormat:@"WikipediaApp/%@ (%@ %@; %@)", - [self appVersion], + [[NSBundle mainBundle] wmf_debugVersion], [d systemName], [d systemVersion], [self formFactor] -- To view, visit https://gerrit.wikimedia.org/r/209024 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I2c9dccbfb04803dc4d80ee8dcae64b76f13a39e3 Gerrit-PatchSet: 1 Gerrit-Project: apps/ios/wikipedia Gerrit-Branch: master Gerrit-Owner: Fjalapeno <cfl...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits