1.8 Coredata migration

This commit is contained in:
Chris Li 2016-09-29 16:38:48 -04:00
parent 31aa28e2c3
commit 6578c7c9dc
11 changed files with 14 additions and 315 deletions

View File

@ -45,7 +45,7 @@ extension MainController: UIWebViewDelegate, SFSafariViewControllerDelegate, LPT
guard let url = webView.request?.URL, guard let url = webView.request?.URL,
let article = Article.addOrUpdate(url: url, context: NSManagedObjectContext.mainQueueContext) else {return} let article = Article.addOrUpdate(url: url, context: NSManagedObjectContext.mainQueueContext) else {return}
article.title = JSInjection.getTitle(from: webView) article.title = JSInjection.getTitle(from: webView)
article.thumbImageURL = URLResponseCache.shared.firstImage()?.path article.thumbImagePath = URLResponseCache.shared.firstImage()?.path
self.article = article self.article = article
// UI Updates // UI Updates

View File

@ -49,7 +49,7 @@
</dict> </dict>
</array> </array>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>1.8.1479</string> <string>1.8.1487</string>
<key>ITSAppUsesNonExemptEncryption</key> <key>ITSAppUsesNonExemptEncryption</key>
<false/> <false/>
<key>LSRequiresIPhoneOS</key> <key>LSRequiresIPhoneOS</key>

View File

@ -21,7 +21,7 @@
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>1.8.1483</string> <string>1.8.1491</string>
<key>NSExtension</key> <key>NSExtension</key>
<dict> <dict>
<key>NSExtensionMainStoryboard</key> <key>NSExtensionMainStoryboard</key>

View File

@ -13,6 +13,7 @@
970E68B61D37E224001E8514 /* SettingSearchHistoryTBVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 970E68B51D37E224001E8514 /* SettingSearchHistoryTBVC.swift */; }; 970E68B61D37E224001E8514 /* SettingSearchHistoryTBVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 970E68B51D37E224001E8514 /* SettingSearchHistoryTBVC.swift */; };
970E68BA1D3809A3001E8514 /* MainController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 970E68B71D3809A3001E8514 /* MainController.swift */; }; 970E68BA1D3809A3001E8514 /* MainController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 970E68B71D3809A3001E8514 /* MainController.swift */; };
970E68BB1D3809A3001E8514 /* MainControllerDelegates.swift in Sources */ = {isa = PBXBuildFile; fileRef = 970E68B81D3809A3001E8514 /* MainControllerDelegates.swift */; }; 970E68BB1D3809A3001E8514 /* MainControllerDelegates.swift in Sources */ = {isa = PBXBuildFile; fileRef = 970E68B81D3809A3001E8514 /* MainControllerDelegates.swift */; };
970E7F741D9DB0FC00741290 /* 1.8.xcmappingmodel in Sources */ = {isa = PBXBuildFile; fileRef = 970E7F731D9DB0FC00741290 /* 1.8.xcmappingmodel */; };
9711871C1CEB448400B9909D /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 9711871B1CEB448400B9909D /* libz.tbd */; }; 9711871C1CEB448400B9909D /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 9711871B1CEB448400B9909D /* libz.tbd */; };
9711871E1CEB449A00B9909D /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 9711871D1CEB449A00B9909D /* libz.tbd */; }; 9711871E1CEB449A00B9909D /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 9711871D1CEB449A00B9909D /* libz.tbd */; };
971187A91CEB694400B9909D /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 971187A81CEB694400B9909D /* WebKit.framework */; }; 971187A91CEB694400B9909D /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 971187A81CEB694400B9909D /* WebKit.framework */; };
@ -60,7 +61,6 @@
973DD4181D343F2F009D45DB /* libxapian.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 973DD40D1D343F2F009D45DB /* libxapian.a */; }; 973DD4181D343F2F009D45DB /* libxapian.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 973DD40D1D343F2F009D45DB /* libxapian.a */; };
973DD4191D343F2F009D45DB /* libzim.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 973DD40E1D343F2F009D45DB /* libzim.a */; }; 973DD4191D343F2F009D45DB /* libzim.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 973DD40E1D343F2F009D45DB /* libzim.a */; };
973DD4281D36E3E4009D45DB /* SettingSingleSwitchTBVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 973DD4271D36E3E4009D45DB /* SettingSingleSwitchTBVC.swift */; }; 973DD4281D36E3E4009D45DB /* SettingSingleSwitchTBVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 973DD4271D36E3E4009D45DB /* SettingSingleSwitchTBVC.swift */; };
974F33C41D99BBEB00879D35 /* 1.8.xcmappingmodel in Sources */ = {isa = PBXBuildFile; fileRef = 974F33C31D99BBEB00879D35 /* 1.8.xcmappingmodel */; };
974F33C61D99CAD700879D35 /* BookmarkOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 974F33C51D99CAD700879D35 /* BookmarkOperation.swift */; }; 974F33C61D99CAD700879D35 /* BookmarkOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 974F33C51D99CAD700879D35 /* BookmarkOperation.swift */; };
974F42821D47E19A00F8074C /* SettingWidgetBookmarksTBVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 974F42811D47E19A00F8074C /* SettingWidgetBookmarksTBVC.swift */; }; 974F42821D47E19A00F8074C /* SettingWidgetBookmarksTBVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 974F42811D47E19A00F8074C /* SettingWidgetBookmarksTBVC.swift */; };
975227821D020560001D1DDE /* Indexer.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 975227811D020560001D1DDE /* Indexer.storyboard */; }; 975227821D020560001D1DDE /* Indexer.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 975227811D020560001D1DDE /* Indexer.storyboard */; };
@ -222,6 +222,7 @@
970E68B51D37E224001E8514 /* SettingSearchHistoryTBVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SettingSearchHistoryTBVC.swift; path = "Kiwix-iOS/Controller/Setting/SettingSearchHistoryTBVC.swift"; sourceTree = SOURCE_ROOT; }; 970E68B51D37E224001E8514 /* SettingSearchHistoryTBVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SettingSearchHistoryTBVC.swift; path = "Kiwix-iOS/Controller/Setting/SettingSearchHistoryTBVC.swift"; sourceTree = SOURCE_ROOT; };
970E68B71D3809A3001E8514 /* MainController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MainController.swift; path = "Kiwix-iOS/Controller/Main/MainController.swift"; sourceTree = SOURCE_ROOT; }; 970E68B71D3809A3001E8514 /* MainController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MainController.swift; path = "Kiwix-iOS/Controller/Main/MainController.swift"; sourceTree = SOURCE_ROOT; };
970E68B81D3809A3001E8514 /* MainControllerDelegates.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MainControllerDelegates.swift; path = "Kiwix-iOS/Controller/Main/MainControllerDelegates.swift"; sourceTree = SOURCE_ROOT; }; 970E68B81D3809A3001E8514 /* MainControllerDelegates.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MainControllerDelegates.swift; path = "Kiwix-iOS/Controller/Main/MainControllerDelegates.swift"; sourceTree = SOURCE_ROOT; };
970E7F731D9DB0FC00741290 /* 1.8.xcmappingmodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcmappingmodel; name = 1.8.xcmappingmodel; path = Kiwix/CoreData/Migration/1.8.xcmappingmodel; sourceTree = SOURCE_ROOT; };
9711871B1CEB448400B9909D /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/lib/libz.tbd; sourceTree = DEVELOPER_DIR; }; 9711871B1CEB448400B9909D /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/lib/libz.tbd; sourceTree = DEVELOPER_DIR; };
9711871D1CEB449A00B9909D /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; }; 9711871D1CEB449A00B9909D /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; };
971187A81CEB694400B9909D /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/WebKit.framework; sourceTree = DEVELOPER_DIR; }; 971187A81CEB694400B9909D /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/WebKit.framework; sourceTree = DEVELOPER_DIR; };
@ -280,7 +281,6 @@
973DD40D1D343F2F009D45DB /* libxapian.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libxapian.a; path = Kiwix/libkiwix/iOS/libxapian.a; sourceTree = "<group>"; }; 973DD40D1D343F2F009D45DB /* libxapian.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libxapian.a; path = Kiwix/libkiwix/iOS/libxapian.a; sourceTree = "<group>"; };
973DD40E1D343F2F009D45DB /* libzim.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libzim.a; path = Kiwix/libkiwix/iOS/libzim.a; sourceTree = "<group>"; }; 973DD40E1D343F2F009D45DB /* libzim.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libzim.a; path = Kiwix/libkiwix/iOS/libzim.a; sourceTree = "<group>"; };
973DD4271D36E3E4009D45DB /* SettingSingleSwitchTBVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SettingSingleSwitchTBVC.swift; path = "Kiwix-iOS/Controller/Setting/SettingSingleSwitchTBVC.swift"; sourceTree = SOURCE_ROOT; }; 973DD4271D36E3E4009D45DB /* SettingSingleSwitchTBVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SettingSingleSwitchTBVC.swift; path = "Kiwix-iOS/Controller/Setting/SettingSingleSwitchTBVC.swift"; sourceTree = SOURCE_ROOT; };
974F33C31D99BBEB00879D35 /* 1.8.xcmappingmodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcmappingmodel; name = 1.8.xcmappingmodel; path = Kiwix/CoreData/Migration/1.8.xcmappingmodel; sourceTree = SOURCE_ROOT; };
974F33C51D99CAD700879D35 /* BookmarkOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BookmarkOperation.swift; sourceTree = "<group>"; }; 974F33C51D99CAD700879D35 /* BookmarkOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BookmarkOperation.swift; sourceTree = "<group>"; };
974F42811D47E19A00F8074C /* SettingWidgetBookmarksTBVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SettingWidgetBookmarksTBVC.swift; path = "Kiwix-iOS/Controller/Setting/SettingWidgetBookmarksTBVC.swift"; sourceTree = SOURCE_ROOT; }; 974F42811D47E19A00F8074C /* SettingWidgetBookmarksTBVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SettingWidgetBookmarksTBVC.swift; path = "Kiwix-iOS/Controller/Setting/SettingWidgetBookmarksTBVC.swift"; sourceTree = SOURCE_ROOT; };
975227811D020560001D1DDE /* Indexer.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = Indexer.storyboard; path = "Kiwix-OSX/StoryBoards/Indexer.storyboard"; sourceTree = SOURCE_ROOT; }; 975227811D020560001D1DDE /* Indexer.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = Indexer.storyboard; path = "Kiwix-OSX/StoryBoards/Indexer.storyboard"; sourceTree = SOURCE_ROOT; };
@ -543,7 +543,7 @@
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
97D6812F1D6F70EC00E5FA99 /* 1.5.xcmappingmodel */, 97D6812F1D6F70EC00E5FA99 /* 1.5.xcmappingmodel */,
974F33C31D99BBEB00879D35 /* 1.8.xcmappingmodel */, 970E7F731D9DB0FC00741290 /* 1.8.xcmappingmodel */,
97D681301D6F70EC00E5FA99 /* MigrationPolicy.swift */, 97D681301D6F70EC00E5FA99 /* MigrationPolicy.swift */,
); );
name = Migration; name = Migration;
@ -1531,8 +1531,8 @@
97D681371D6F711A00E5FA99 /* Article.swift in Sources */, 97D681371D6F711A00E5FA99 /* Article.swift in Sources */,
97D681231D6F70AC00E5FA99 /* GlobalQueue.swift in Sources */, 97D681231D6F70AC00E5FA99 /* GlobalQueue.swift in Sources */,
97A1FD3B1D6F724E00A80EE2 /* stringTools.cpp in Sources */, 97A1FD3B1D6F724E00A80EE2 /* stringTools.cpp in Sources */,
970E7F741D9DB0FC00741290 /* 1.8.xcmappingmodel in Sources */,
97A1FD321D6F723D00A80EE2 /* resourceTools.cpp in Sources */, 97A1FD321D6F723D00A80EE2 /* resourceTools.cpp in Sources */,
974F33C41D99BBEB00879D35 /* 1.8.xcmappingmodel in Sources */,
971A10321D022AD5007FC62C /* SearchBar.swift in Sources */, 971A10321D022AD5007FC62C /* SearchBar.swift in Sources */,
97E60A061D10504000EBCB9D /* LibraryBackupTBVC.swift in Sources */, 97E60A061D10504000EBCB9D /* LibraryBackupTBVC.swift in Sources */,
97A1FD451D6F728200A80EE2 /* StringTools.swift in Sources */, 97A1FD451D6F728200A80EE2 /* StringTools.swift in Sources */,

View File

@ -25,5 +25,5 @@ extension Article {
@NSManaged var book: Book? @NSManaged var book: Book?
@NSManaged var tags: NSSet? @NSManaged var tags: NSSet?
@NSManaged var thumbImageURL: String? @NSManaged var thumbImagePath: String?
} }

View File

@ -51,7 +51,7 @@ class Article: NSManagedObject {
} }
var thumbImageData: NSData? { var thumbImageData: NSData? {
if let bookID = book?.id, let path = thumbImageURL, if let bookID = book?.id, let path = thumbImagePath,
let url = NSURL(bookID: bookID, contentPath: path), let url = NSURL(bookID: bookID, contentPath: path),
let data = NSData(contentsOfURL: url) { let data = NSData(contentsOfURL: url) {
return data return data

View File

@ -21,7 +21,6 @@ extension Book {
@NSManaged var favIcon: NSData? @NSManaged var favIcon: NSData?
@NSManaged var fileSize: Int64 @NSManaged var fileSize: Int64
@NSManaged var globalCount: Int64 @NSManaged var globalCount: Int64
@NSManaged var hasIndex: Bool
@NSManaged var hasPic: Bool @NSManaged var hasPic: Bool
@NSManaged var id: String @NSManaged var id: String
@NSManaged var includeInSearch: Bool @NSManaged var includeInSearch: Bool

View File

@ -9,7 +9,7 @@
<attribute name="needsUpdate" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES" syncable="YES"/> <attribute name="needsUpdate" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES" syncable="YES"/>
<attribute name="path" attributeType="String" syncable="YES"/> <attribute name="path" attributeType="String" syncable="YES"/>
<attribute name="snippet" optional="YES" attributeType="String" syncable="YES"/> <attribute name="snippet" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="thumbImageURL" optional="YES" attributeType="String" syncable="YES"/> <attribute name="thumbImagePath" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="title" attributeType="String" syncable="YES"/> <attribute name="title" attributeType="String" syncable="YES"/>
<relationship name="book" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Book" inverseName="articles" inverseEntity="Book" syncable="YES"/> <relationship name="book" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Book" inverseName="articles" inverseEntity="Book" syncable="YES"/>
<relationship name="tags" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="Tag" inverseName="articles" inverseEntity="Tag" syncable="YES"/> <relationship name="tags" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="Tag" inverseName="articles" inverseEntity="Tag" syncable="YES"/>
@ -22,7 +22,6 @@
<attribute name="favIcon" optional="YES" attributeType="Binary" syncable="YES"/> <attribute name="favIcon" optional="YES" attributeType="Binary" syncable="YES"/>
<attribute name="fileSize" optional="YES" attributeType="Integer 64" minValueString="0" defaultValueString="0" usesScalarValueType="YES" syncable="YES"/> <attribute name="fileSize" optional="YES" attributeType="Integer 64" minValueString="0" defaultValueString="0" usesScalarValueType="YES" syncable="YES"/>
<attribute name="globalCount" optional="YES" attributeType="Integer 64" minValueString="0" defaultValueString="0" usesScalarValueType="YES" syncable="YES"/> <attribute name="globalCount" optional="YES" attributeType="Integer 64" minValueString="0" defaultValueString="0" usesScalarValueType="YES" syncable="YES"/>
<attribute name="hasIndex" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES" syncable="YES"/>
<attribute name="hasPic" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES" syncable="YES"/> <attribute name="hasPic" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES" syncable="YES"/>
<attribute name="id" attributeType="String" syncable="YES"/> <attribute name="id" attributeType="String" syncable="YES"/>
<attribute name="includeInSearch" attributeType="Boolean" defaultValueString="YES" usesScalarValueType="YES" syncable="YES"/> <attribute name="includeInSearch" attributeType="Boolean" defaultValueString="YES" usesScalarValueType="YES" syncable="YES"/>
@ -81,8 +80,8 @@
<relationship name="articles" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="Article" inverseName="tags" inverseEntity="Article" syncable="YES"/> <relationship name="articles" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="Article" inverseName="tags" inverseEntity="Article" syncable="YES"/>
</entity> </entity>
<elements> <elements>
<element name="Article" positionX="-657" positionY="-153" width="128" height="225"/> <element name="Article" positionX="-657" positionY="-153" width="128" height="223"/>
<element name="Book" positionX="-947" positionY="-142" width="128" height="345"/> <element name="Book" positionX="-947" positionY="-142" width="128" height="328"/>
<element name="DownloadTask" positionX="-657" positionY="90" width="128" height="105"/> <element name="DownloadTask" positionX="-657" positionY="90" width="128" height="105"/>
<element name="Language" positionX="-657" positionY="216" width="128" height="103"/> <element name="Language" positionX="-657" positionY="216" width="128" height="103"/>
<element name="Tag" positionX="-425" positionY="-18" width="128" height="73"/> <element name="Tag" positionX="-425" positionY="-18" width="128" height="73"/>

File diff suppressed because one or more lines are too long

View File

@ -24,7 +24,7 @@ class MigrationPolicy1_8: NSEntityMigrationPolicy {
} }
} }
func articlePath(url: String) -> String { func path(url: String) -> String {
return NSURL(string: url)!.path! return NSURL(string: url)?.path ?? ""
} }
} }

View File

@ -95,17 +95,10 @@ class ScanLocalBookOperation: Operation {
return book ?? Book.add(reader.metaData, context: NSManagedObjectContext.mainQueueContext) return book ?? Book.add(reader.metaData, context: NSManagedObjectContext.mainQueueContext)
}() else {return} }() else {return}
book.state = .Local book.state = .Local
book.hasIndex = reader.hasIndex()
book.hasPic = !reader.fileURL.absoluteString!.containsString("nopic") book.hasPic = !reader.fileURL.absoluteString!.containsString("nopic")
if let downloadTask = book.downloadTask {context.deleteObject(downloadTask)} if let downloadTask = book.downloadTask {context.deleteObject(downloadTask)}
} }
for (id, book) in localBooks {
guard !context.deletedObjects.contains(book) else {continue}
guard let reader = ZimMultiReader.shared.readers[id] else {return}
book.hasIndex = reader.hasIndex()
}
if localBooks.count == 0 && addedZimFileIDs.count >= 1 { if localBooks.count == 0 && addedZimFileIDs.count >= 1 {
firstBookAdded = true firstBookAdded = true
} }