Skip to content

Commit f9915fe

Browse files
authored
Clobber all migrations mappings and policies — Very old (#24208)
* Clobber all migrations mappings and policies — Very old For the sake of convenience and code maintenance, we decided to remove these migrations because we consider it safe to assume all existing users are on later versions. If no user will ever run the migrations, the code is essentially dead code that we can remove. For reference, the current version is 154 and the oldest migration was 91-to-92. The model version 92 dates back to 2019, see dcdba23 * Move a few more utils types to WordPressShared (#24210) - KeychainUtils & co - UserPersistentRepository & co - LocalFileStore & co
1 parent a6eaa7a commit f9915fe

File tree

90 files changed

+227
-20294
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+227
-20294
lines changed

Modules/Package.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,15 @@ let package = Package(
8383
.target(name: "WordPressFlux", swiftSettings: [.swiftLanguageMode(.v5)]),
8484
.target(name: "WordPressCore", dependencies: [.target(name: "WordPressShared"), .product(name: "WordPressAPI", package: "wordpress-rs")]),
8585
.target(name: "WordPressSharedObjC", resources: [.process("Resources")], swiftSettings: [.swiftLanguageMode(.v5)]),
86-
.target(name: "WordPressShared", dependencies: [.target(name: "WordPressSharedObjC")], resources: [.process("Resources")], swiftSettings: [.swiftLanguageMode(.v5)]),
86+
.target(
87+
name: "WordPressShared",
88+
dependencies: [
89+
.target(name: "SFHFKeychainUtils"),
90+
.target(name: "WordPressSharedObjC"),
91+
],
92+
resources: [.process("Resources")],
93+
swiftSettings: [.swiftLanguageMode(.v5)]
94+
),
8795
.target(name: "WordPressTesting", resources: [.process("Resources")]),
8896
.target(
8997
name: "WordPressUI",

Modules/Sources/WordPressShared/Utility/FileManager+FolderSize.swift renamed to Modules/Sources/WordPressShared/FileManager/FileManager+FolderSize.swift

File renamed without changes.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import Foundation
2+
3+
extension FileManager: LocalFileStore {
4+
public func containerURL(forAppGroup appGroup: String) -> URL? {
5+
return containerURL(forSecurityApplicationGroupIdentifier: appGroup)
6+
}
7+
8+
public func fileExists(at url: URL) -> Bool {
9+
return fileExists(atPath: url.path)
10+
}
11+
12+
@discardableResult
13+
public func save(contents: Data, at url: URL) -> Bool {
14+
return createFile(atPath: url.path, contents: contents)
15+
}
16+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import Foundation
2+
3+
public protocol LocalFileStore {
4+
func data(from url: URL) throws -> Data
5+
6+
func fileExists(at url: URL) -> Bool
7+
8+
@discardableResult
9+
func save(contents: Data, at url: URL) -> Bool
10+
11+
func containerURL(forAppGroup appGroup: String) -> URL?
12+
13+
func removeItem(at url: URL) throws
14+
15+
func copyItem(at srcURL: URL, to dstURL: URL) throws
16+
}
17+
18+
public extension LocalFileStore {
19+
func data(from url: URL) throws -> Data {
20+
return try Data(contentsOf: url)
21+
}
22+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
public protocol KeychainAccessible {
2+
func getPassword(for username: String, serviceName: String) throws -> String
3+
func setPassword(for username: String, to newValue: String?, serviceName: String) throws
4+
}

WordPress/Classes/Utility/KeychainUtils.swift renamed to Modules/Sources/WordPressShared/Keychain/KeychainUtils.swift

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import SFHFKeychainUtils
22

33
@objcMembers
4-
class KeychainUtils: NSObject {
4+
public class KeychainUtils: NSObject {
55

66
private let keychainUtils: SFHFKeychainUtils.Type
77

8-
init(keychainUtils: SFHFKeychainUtils.Type = SFHFKeychainUtils.self) {
8+
public init(keychainUtils: SFHFKeychainUtils.Type = SFHFKeychainUtils.self) {
99
self.keychainUtils = keychainUtils
1010
}
1111

@@ -29,7 +29,8 @@ class KeychainUtils: NSObject {
2929
return try keychainUtils.getPasswordForUsername(username, andServiceName: serviceName, accessGroup: accessGroup)
3030
}
3131

32-
func store(username: String, password: String, serviceName: String, accessGroup: String? = nil, updateExisting: Bool) throws {
32+
// FIXME: Might become internal once all consumers interface with this via `KeychainAccessible`
33+
public func store(username: String, password: String, serviceName: String, accessGroup: String? = nil, updateExisting: Bool) throws {
3334
return try keychainUtils.storeUsername(username,
3435
andPassword: password,
3536
forServiceName: serviceName,
@@ -39,20 +40,15 @@ class KeychainUtils: NSObject {
3940
}
4041

4142
extension KeychainUtils: KeychainAccessible {
42-
func getPassword(for username: String, serviceName: String) throws -> String {
43+
public func getPassword(for username: String, serviceName: String) throws -> String {
4344
try self.keychainUtils.getPasswordForUsername(username, andServiceName: serviceName)
4445
}
4546

46-
func setPassword(for username: String, to newValue: String?, serviceName: String) throws {
47+
public func setPassword(for username: String, to newValue: String?, serviceName: String) throws {
4748
if let newValue {
4849
try keychainUtils.storeUsername(username, andPassword: newValue, forServiceName: serviceName, updateExisting: true)
4950
} else {
5051
try keychainUtils.deleteItem(forUsername: username, andServiceName: serviceName)
5152
}
5253
}
5354
}
54-
55-
protocol KeychainAccessible {
56-
func getPassword(for username: String, serviceName: String) throws -> String
57-
func setPassword(for username: String, to newValue: String?, serviceName: String) throws
58-
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import Foundation
2+
3+
public typealias UserPersistentRepository = UserPersistentRepositoryReader & UserPersistentRepositoryWriter & UserPersistentRepositoryUtility
4+
5+
extension UserDefaults: UserPersistentRepository {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
public protocol UserPersistentRepositoryReader {
2+
func string(forKey key: String) -> String?
3+
func bool(forKey key: String) -> Bool
4+
func integer(forKey key: String) -> Int
5+
func float(forKey key: String) -> Float
6+
func double(forKey key: String) -> Double
7+
func array(forKey key: String) -> [Any]?
8+
func dictionary(forKey key: String) -> [String: Any]?
9+
func url(forKey key: String) -> URL?
10+
func dictionaryRepresentation() -> [String: Any]
11+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
public protocol UserPersistentRepositoryUtility: AnyObject {
2+
var onboardingNotificationsPromptDisplayed: Bool { get set }
3+
var notificationPrimerAlertWasDisplayed: Bool { get set }
4+
}
5+
6+
public enum UPRUConstants {
7+
static let promptKey = "onboarding_notifications_prompt_displayed"
8+
static let questionKey = "onboarding_question_selection"
9+
static let notificationPrimerAlertWasDisplayed = "NotificationPrimerAlertWasDisplayed"
10+
public static let notificationsTabAccessCount = "NotificationsTabAccessCount"
11+
public static let notificationPrimerInlineWasAcknowledged = "notificationPrimerInlineWasAcknowledged"
12+
public static let secondNotificationsAlertCount = "secondNotificationsAlertCount"
13+
public static let hasShownCustomAppIconUpgradeAlert = "custom-app-icon-upgrade-alert-shown"
14+
public static let savedPostsPromoWasDisplayed = "SavedPostsV1PromoWasDisplayed"
15+
public static let currentAnnouncementsKey = "currentAnnouncements"
16+
public static let currentAnnouncementsDateKey = "currentAnnouncementsDate"
17+
public static let announcementsVersionDisplayedKey = "announcementsVersionDisplayed"
18+
public static let isJPContentImportCompleteKey = "jetpackContentImportComplete"
19+
public static let jetpackContentMigrationStateKey = "jetpackContentMigrationState"
20+
public static let mediaAspectRatioModeEnabledKey = "mediaAspectRatioModeEnabled"
21+
public static let readerSidebarSelectionKey = "readerSidebarSelectionKey"
22+
public static let isReaderSelectedKey = "isReaderSelectedKey"
23+
public static let readerSearchHistoryKey = "readerSearchHistoryKey"
24+
public static let readerDidSelectInterestsKey = "readerDidSelectInterestsKey"
25+
}
26+
27+
public extension UserPersistentRepositoryUtility {
28+
var onboardingNotificationsPromptDisplayed: Bool {
29+
get {
30+
UserPersistentStoreFactory.instance().bool(forKey: UPRUConstants.promptKey)
31+
}
32+
set {
33+
UserPersistentStoreFactory.instance().set(newValue, forKey: UPRUConstants.promptKey)
34+
}
35+
}
36+
37+
var notificationPrimerAlertWasDisplayed: Bool {
38+
get {
39+
UserPersistentStoreFactory.instance().bool(forKey: UPRUConstants.notificationPrimerAlertWasDisplayed)
40+
}
41+
set {
42+
UserPersistentStoreFactory.instance().set(newValue, forKey: UPRUConstants.notificationPrimerAlertWasDisplayed)
43+
}
44+
}
45+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
public protocol UserPersistentRepositoryWriter: KeyValueDatabase {
2+
func set(_ value: Any?, forKey key: String)
3+
func set(_ value: Int, forKey key: String)
4+
func set(_ value: Float, forKey key: String)
5+
func set(_ value: Double, forKey key: String)
6+
func set(_ value: Bool, forKey key: String)
7+
func set(_ url: URL?, forKey key: String)
8+
func removeObject(forKey key: String)
9+
}

0 commit comments

Comments
 (0)