diff --git a/CHANGELOG.md b/CHANGELOG.md index c0533377..dac3e76d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,11 +42,11 @@ _None._ ### Bug Fixes -_None._ +- Fix a rare crash when accessing date formatter from different threads in StatsRemoteService. [#749] ### Internal Changes -_None._ +- Add WP.com theme type information. [#750] ## 14.0.1 diff --git a/WordPressKit/RemoteTheme.h b/WordPressKit/RemoteTheme.h index e39a9486..c067d9ad 100644 --- a/WordPressKit/RemoteTheme.h +++ b/WordPressKit/RemoteTheme.h @@ -3,6 +3,7 @@ @interface RemoteTheme : NSObject @property (nonatomic, assign) BOOL active; +@property (nonatomic, strong) NSString *type; @property (nonatomic, strong) NSString *author; @property (nonatomic, strong) NSString *authorUrl; @property (nonatomic, strong) NSString *desc; diff --git a/WordPressKit/StatsServiceRemoteV2.swift b/WordPressKit/StatsServiceRemoteV2.swift index cc342c25..f0567bfa 100644 --- a/WordPressKit/StatsServiceRemoteV2.swift +++ b/WordPressKit/StatsServiceRemoteV2.swift @@ -17,12 +17,12 @@ open class StatsServiceRemoteV2: ServiceRemoteWordPressComREST { public let siteID: Int private let siteTimezone: TimeZone - private lazy var periodDataQueryDateFormatter: DateFormatter = { + private var periodDataQueryDateFormatter: DateFormatter { let df = DateFormatter() df.locale = Locale(identifier: "en_US_POSIX") df.dateFormat = "yyyy-MM-dd" return df - }() + } private lazy var calendarForSite: Calendar = { var cal = Calendar(identifier: .iso8601) @@ -117,8 +117,9 @@ open class StatsServiceRemoteV2: ServiceRemoteWordPressComREST { return val1 } - wordPressComRestApi.GET(path, parameters: properties, success: { (response, _) in + wordPressComRestApi.GET(path, parameters: properties, success: { [weak self] (response, _) in guard + let self, let jsonResponse = response as? [String: AnyObject], let dateString = jsonResponse["date"] as? String, let date = self.periodDataQueryDateFormatter.date(from: dateString) diff --git a/WordPressKit/ThemeServiceRemote.m b/WordPressKit/ThemeServiceRemote.m index 6cd5f3d9..094a8982 100644 --- a/WordPressKit/ThemeServiceRemote.m +++ b/WordPressKit/ThemeServiceRemote.m @@ -359,6 +359,7 @@ - (RemoteTheme *)themeFromDictionary:(NSDictionary *)dictionary NSParameterAssert([dictionary isKindOfClass:[NSDictionary class]]); static NSString* const ThemeActiveKey = @"active"; + static NSString* const ThemeTypeKey = @"theme_type"; static NSString* const ThemeAuthorKey = @"author"; static NSString* const ThemeAuthorURLKey = @"author_uri"; static NSString* const ThemeCostPath = @"cost.number"; @@ -384,6 +385,7 @@ - (RemoteTheme *)themeFromDictionary:(NSDictionary *)dictionary [self loadLaunchDateForTheme:theme fromDictionary:dictionary]; theme.active = [[dictionary numberForKey:ThemeActiveKey] boolValue]; + theme.type = [dictionary stringForKey:ThemeTypeKey]; theme.author = [dictionary stringForKey:ThemeAuthorKey]; theme.authorUrl = [dictionary stringForKey:ThemeAuthorURLKey]; theme.demoUrl = [dictionary stringForKey:ThemeDemoURLKey]; diff --git a/WordPressKitTests/Utilities/URLSessionHelperTests.swift b/WordPressKitTests/Utilities/URLSessionHelperTests.swift index 997b69cd..d366d066 100644 --- a/WordPressKitTests/Utilities/URLSessionHelperTests.swift +++ b/WordPressKitTests/Utilities/URLSessionHelperTests.swift @@ -261,8 +261,9 @@ class URLSessionHelperTests: XCTestCase { HTTPStubsResponse(data: "success".data(using: .utf8)!, statusCode: 200, headers: nil) } - // Create a large file which will be uploaded - let file = try self.createLargeFile(megaBytes: 100) + // Create a large file which will be uploaded. The file size needs to be larger than the hardcoded threshold of + // creating a temporary file for upload. + let file = try self.createLargeFile(megaBytes: 30) defer { try? FileManager.default.removeItem(at: file) } @@ -290,8 +291,9 @@ class URLSessionHelperTests: XCTestCase { HTTPStubsResponse(error: URLError(.networkConnectionLost)) } - // Create a large file which will be uploaded - let file = try self.createLargeFile(megaBytes: 100) + // Create a large file which will be uploaded. The file size needs to be larger than the hardcoded threshold of + // creating a temporary file for upload. + let file = try self.createLargeFile(megaBytes: 30) defer { try? FileManager.default.removeItem(at: file) } @@ -331,16 +333,11 @@ class URLSessionHelperTests: XCTestCase { } private func createLargeFile(megaBytes: Int) throws -> URL { - let fileManager = FileManager.default - let file = try fileManager.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true) + let file = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true) .appendingPathComponent("large-file-\(UUID().uuidString).txt") - fileManager.createFile(atPath: file.path, contents: nil) - let handle = try FileHandle(forUpdating: file) - for _ in 0..