Brion VIBBER has submitted this change and it was merged. Change subject: Tie together the migrator and the importer ......................................................................
Tie together the migrator and the importer Creates saved page records for all old-app saved pages upon first load, then removes one of the old data files to keep it from triggering again. Note that pages are not actually fetched and saved yet -- you have to load them at least once to populate them. May want to consider a fetch-all process which can be triggered in the background or something. Change-Id: Ibbb839e8396e13971ac1641008bb8b36f9afde88 --- M Wikipedia.xcodeproj/project.pbxproj M wikipedia/AppDelegate.m M wikipedia/DataMigrator.m M wikipedia/Importer/ArticleImporter.m M wikipedia/View Controllers/WebView/WebViewController.m 5 files changed, 48 insertions(+), 28 deletions(-) Approvals: Brion VIBBER: Verified; Looks good to me, approved diff --git a/Wikipedia.xcodeproj/project.pbxproj b/Wikipedia.xcodeproj/project.pbxproj index b8e7c5c..32cd3d1 100644 --- a/Wikipedia.xcodeproj/project.pbxproj +++ b/Wikipedia.xcodeproj/project.pbxproj @@ -586,8 +586,8 @@ D4991466181D51DF00E6073C /* Wikipedia_Tests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Wikipedia_Tests.m; sourceTree = "<group>"; }; D4BC22B3181E9E6300CAC673 /* empty.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = empty.png; sourceTree = "<group>"; }; D4DE203018283FF200148CA2 /* CommunicationBridgeTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CommunicationBridgeTests.m; sourceTree = "<group>"; }; - D4E8A8A2190835C100DA4765 /* DataMigrator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DataMigrator.h; sourceTree = "<group>"; }; - D4E8A8A3190835C100DA4765 /* DataMigrator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DataMigrator.m; sourceTree = "<group>"; }; + D4E8A8A2190835C100DA4765 /* DataMigrator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DataMigrator.h; path = wikipedia/DataMigrator.h; sourceTree = SOURCE_ROOT; }; + D4E8A8A3190835C100DA4765 /* DataMigrator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = DataMigrator.m; path = wikipedia/DataMigrator.m; sourceTree = SOURCE_ROOT; }; D4E8A8A519084F1300DA4765 /* SQLiteHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SQLiteHelper.h; sourceTree = "<group>"; }; D4E8A8A619084F1300DA4765 /* SQLiteHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SQLiteHelper.m; sourceTree = "<group>"; }; D4E8A8A819085CEA00DA4765 /* libsqlite3.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libsqlite3.dylib; path = usr/lib/libsqlite3.dylib; sourceTree = SDKROOT; }; @@ -619,6 +619,8 @@ 040E5C831846AC13007AFE6F /* ArticleDataContextSingleton.m */, 04EA7779184E4CED00D2F3C9 /* Model */, 04D149E5188889CA006B4104 /* Operations */, + D4E8A8A11908357600DA4765 /* Data Migration */, + 04B0EA42190AFDBA007458AF /* Importer */, ); path = Data; sourceTree = "<group>"; @@ -852,7 +854,8 @@ 04B0EA43190AFDD8007458AF /* ArticleImporter.h */, 04B0EA44190AFDD8007458AF /* ArticleImporter.m */, ); - path = Importer; + name = Importer; + path = ../Importer; sourceTree = "<group>"; }; 04B7B9BA18B5569600A63551 /* Captcha */ = { @@ -1213,12 +1216,10 @@ 045A9F0C18F6090E0057EA85 /* assets */, 04C43AB7183442FC006C643B /* Categories */, 040E5C50184673F2007AFE6F /* Data */, - D4E8A8A11908357600DA4765 /* Data Migration */, 04292FFB185FC026002A13FC /* Defines */, 0442F57C1900718600F55DF9 /* Fonts */, 04D34DA31863D2D600610A87 /* HTML Parsing */, 0466F44C183A30CC00EA1FD7 /* Images */, - 04B0EA42190AFDBA007458AF /* Importer */, 0463639518A844380049EE4F /* Keychain */, 04CF1CB5187C8F4400E9516F /* Languages */, 048A26741906268100395F53 /* PaddedLabel */, @@ -1284,6 +1285,7 @@ D4E8A8A619084F1300DA4765 /* SQLiteHelper.m */, ); name = "Data Migration"; + path = ..; sourceTree = "<group>"; }; D4EE00BB182445670090790F /* mw-support */ = { diff --git a/wikipedia/AppDelegate.m b/wikipedia/AppDelegate.m index e6f4598..d0dd972 100644 --- a/wikipedia/AppDelegate.m +++ b/wikipedia/AppDelegate.m @@ -3,7 +3,6 @@ #import "AppDelegate.h" #import "URLCache.h" -#import "DataMigrator.h" @implementation AppDelegate @@ -26,18 +25,6 @@ //[[NSUserDefaults standardUserDefaults] synchronize]; // Override point for customization after application launch. - - // This probably belongs elsewhere... maybe tie it into one of the main pages on the nav stack. - DataMigrator *dataMigrator = [[DataMigrator alloc] init]; - if ([dataMigrator hasData]) { - NSLog(@"Old data to migrate found!"); - NSArray *titles = [dataMigrator extractSavedPages]; - for (NSDictionary *item in titles) { - NSLog(@"Need to import saved page: %@ %@", item[@"lang"], item[@"title"]); - } - } else { - NSLog(@"No pld data to migrate."); - } return YES; } diff --git a/wikipedia/DataMigrator.m b/wikipedia/DataMigrator.m index 98fdb5b..e1b1b6b 100644 --- a/wikipedia/DataMigrator.m +++ b/wikipedia/DataMigrator.m @@ -50,7 +50,10 @@ - (void)removeOldData { if ([self hasData]) { - NSLog(@"todo: implement removeOldData in DataMigrator"); + NSLog(@"Deleting old app's Caches/Databases.db"); + masterDB = nil; + NSString *dbPath = [self localLibraryPath:@"Caches/Databases.db"]; + [[NSFileManager defaultManager] removeItemAtPath:dbPath error:nil]; } } diff --git a/wikipedia/Importer/ArticleImporter.m b/wikipedia/Importer/ArticleImporter.m index d3ac48c..c350867 100644 --- a/wikipedia/Importer/ArticleImporter.m +++ b/wikipedia/Importer/ArticleImporter.m @@ -20,24 +20,24 @@ NSError *error = nil; for (NSDictionary *articleDict in articleDictionaries) { - // Ensure both domain and title keys are present in this article dict. - if (![articleDict objectForKey:@"domain"] || ![articleDict objectForKey:@"title"]){ - NSLog(@"Error: domain or title missing."); + // Ensure both lang and title keys are present in this article dict. + if (![articleDict objectForKey:@"lang"] || ![articleDict objectForKey:@"title"]){ + NSLog(@"Error: lang or title missing."); continue; } NSString *title = articleDict[@"title"]; - NSString *domain = articleDict[@"domain"]; + NSString *lang = articleDict[@"lang"]; - // Ensure both domain and title strings are not zero length. - if ((title.length == 0) || (domain.length == 0)){ - NSLog(@"Error: domain or title zero length."); + // Ensure both lang and title strings are not zero length. + if ((title.length == 0) || (lang.length == 0)){ + NSLog(@"Error: lang or title zero length."); continue; } // Get existing article record. Create article record if not found. Article *article = nil; - NSManagedObjectID *existingArticleID = [context getArticleIDForTitle:title domain:domain]; + NSManagedObjectID *existingArticleID = [context getArticleIDForTitle:title domain:lang]; if (existingArticleID) { article = (Article *)[context objectWithID:existingArticleID]; }else{ @@ -64,7 +64,7 @@ // All needed data in place and no saved record already exists, so safe to proceed. article.dateCreated = [NSDate date]; article.site = @"wikipedia.org"; - article.domain = domain; + article.domain = lang; article.title = title; article.needsRefresh = @YES; article.lastmodifiedby = @""; diff --git a/wikipedia/View Controllers/WebView/WebViewController.m b/wikipedia/View Controllers/WebView/WebViewController.m index abf1013..e405d0f 100644 --- a/wikipedia/View Controllers/WebView/WebViewController.m +++ b/wikipedia/View Controllers/WebView/WebViewController.m @@ -35,6 +35,9 @@ #import "ZeroStatusLabel.h" //#import "UIView+Debugging.h" +#import "DataMigrator.h" +#import "ArticleImporter.h" + #define TOC_TOGGLE_ANIMATION_DURATION 0.3f #define NAV ((NavController *)self.navigationController) @@ -161,6 +164,10 @@ // UIWebView has a bug which causes a black bar to appear at // bottom of the web view if toc quickly dragged on and offscreen. self.webView.opaque = NO; + + // This is the first view that's opened when the app opens... + // Perform any first-time data migration as needed. + [self migrateDataIfNecessary]; } -(void)viewDidAppear:(BOOL)animated @@ -1539,4 +1546,25 @@ } } +- (void)migrateDataIfNecessary +{ + DataMigrator *dataMigrator = [[DataMigrator alloc] init]; + if ([dataMigrator hasData]) { + NSLog(@"Old data to migrate found!"); + NSArray *titles = [dataMigrator extractSavedPages]; + ArticleImporter *importer = [[ArticleImporter alloc] init]; + + for (NSDictionary *item in titles) { + NSLog(@"Will import saved page: %@ %@", item[@"lang"], item[@"title"]); + } + + [importer importArticles:titles]; + + [dataMigrator removeOldData]; + } else { + NSLog(@"No old data to migrate."); + } + +} + @end -- To view, visit https://gerrit.wikimedia.org/r/130326 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ibbb839e8396e13971ac1641008bb8b36f9afde88 Gerrit-PatchSet: 2 Gerrit-Project: apps/ios/wikipedia Gerrit-Branch: master Gerrit-Owner: Brion VIBBER <br...@wikimedia.org> Gerrit-Reviewer: Brion VIBBER <br...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits