Skip to content

Commit ecfc2b2

Browse files
committed
Merge branch 'trunk' into core-data-test-case
Conflicts: WordPress/WordPressTest/ContextManagerTests.swift
2 parents 41041b3 + a6696d8 commit ecfc2b2

File tree

90 files changed

+837
-975
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

+837
-975
lines changed

RELEASE-NOTES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* [*] Block Editor: Gallery block: Fix broken "Link To" settings and add "Image Size" settings [https://github.com/wordpress-mobile/gutenberg-mobile/pull/4841]
1414
* [*] Block Editor: Unsupported Block Editor: Prevent WordPress.com tour banner from displaying. [https://github.com/wordpress-mobile/gutenberg-mobile/pull/4820]
1515
* [*] Widgets: we fixed an issue where text appeared flipped in rtl languages [#18567]
16+
* [*] Stats: we fixed a crash that occurred sometimes in Stats [#18613]
1617
* [*] Posts list: we fixed an issue where the create button was not shown on iPad in split screen [#18609]
1718

1819
19.8

WordPress/Classes/Extensions/Post+BloggingPrompts.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ extension Post {
44
guard let prompt = prompt else {
55
return
66
}
7-
postTitle = prompt.title
7+
88
content = prompt.content
99
}
1010

WordPress/Classes/Utility/ContextManager.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33

44
NS_ASSUME_NONNULL_BEGIN
55

6+
/**
7+
A constant representing the current version of the data model.
8+
9+
@see -[ContextManager initWithModelName:storeURL:]
10+
*/
11+
FOUNDATION_EXTERN NSString * const ContextManagerModelNameCurrent;
12+
613
@protocol CoreDataStack
714
@property (nonatomic, readonly, strong) NSManagedObjectContext *mainContext;
815
- (NSManagedObjectContext *const)newDerivedContext;
@@ -34,6 +41,18 @@ NS_ASSUME_NONNULL_BEGIN
3441
*/
3542
+ (instancetype)internalSharedInstance;
3643

44+
/**
45+
Create a ContextManager instance with given model name and database location.
46+
47+
Note: This initialiser is only used for testing purpose at the moment.
48+
49+
@param modelName Model name in Core Data data model file.
50+
Use ContextManagerModelNameCurrent for current version, or
51+
"WordPress <version>" for specific version.
52+
@param storeURL Database location.
53+
*/
54+
- (instancetype)initWithModelName:(NSString *)modelName storeURL:(NSURL *)storeURL NS_DESIGNATED_INITIALIZER;
55+
3756

3857
///--------------------------
3958
///@name Contexts

WordPress/Classes/Utility/ContextManager.m

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#define SentryStartupEventAddError(event, error) [event addError:error file:__FILE__ function:__FUNCTION__ line:__LINE__]
77

8+
NSString * const ContextManagerModelNameCurrent = @"$CURRENT";
9+
810
// MARK: - Static Variables
911
//
1012
static ContextManager *_instance;
@@ -22,6 +24,8 @@ @interface ContextManager ()
2224
@property (nonatomic, strong) NSManagedObjectContext *mainContext;
2325
@property (nonatomic, strong) NSManagedObjectContext *writerContext;
2426
@property (nonatomic, assign) BOOL migrationFailed;
27+
@property (nonatomic, strong) NSString *modelName;
28+
@property (nonatomic, strong) NSURL *storeURL;
2529

2630
@end
2731

@@ -31,9 +35,25 @@ @interface ContextManager ()
3135
@implementation ContextManager
3236

3337
- (instancetype)init
38+
{
39+
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
40+
NSUserDomainMask,
41+
YES) lastObject];
42+
NSURL *storeURL = [NSURL fileURLWithPath:[documentsDirectory stringByAppendingPathComponent:@"WordPress.sqlite"]];
43+
44+
return [self initWithModelName:ContextManagerModelNameCurrent storeURL:storeURL];
45+
}
46+
47+
- (instancetype)initWithModelName:(NSString *)modelName storeURL:(NSURL *)storeURL
3448
{
3549
self = [super init];
3650
if (self) {
51+
NSParameterAssert([modelName isEqualToString:ContextManagerModelNameCurrent] || [modelName hasPrefix:@"WordPress "]);
52+
NSParameterAssert([storeURL isFileURL]);
53+
54+
self.modelName = modelName;
55+
self.storeURL = storeURL;
56+
3757
[NSValueTransformer registerCustomTransformers];
3858
// Create `mainContext` and `writerContext` during initialisation to
3959
// ensure they are only created once.
@@ -236,7 +256,16 @@ - (NSManagedObjectModel *)managedObjectModel
236256
}
237257
NSString *modelPath = [self modelPath];
238258
NSURL *modelURL = [NSURL fileURLWithPath:modelPath];
239-
_managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
259+
if ([self.modelName isEqualToString:ContextManagerModelNameCurrent]) {
260+
// Use the current version defined in data model.
261+
_managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
262+
} else {
263+
// Find the specific version defined in data model.
264+
NSURL *versionedModelURL = [[modelURL URLByAppendingPathComponent:self.modelName] URLByAppendingPathExtension:@"mom"];
265+
NSAssert([NSFileManager.defaultManager fileExistsAtPath:versionedModelURL.path],
266+
@"Can't find model '%@' at %@", self.modelName, modelPath);
267+
_managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:versionedModelURL];
268+
}
240269
return _managedObjectModel;
241270
}
242271

@@ -324,15 +353,6 @@ - (NSArray *)sortedModelNames
324353
return modelNames;
325354
}
326355

327-
- (NSURL *)storeURL
328-
{
329-
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
330-
NSUserDomainMask,
331-
YES) lastObject];
332-
333-
return [NSURL fileURLWithPath:[documentsDirectory stringByAppendingPathComponent:@"WordPress.sqlite"]];
334-
}
335-
336356
- (NSString *)modelPath
337357
{
338358
return [[NSBundle mainBundle] pathForResource:@"WordPress" ofType:@"momd"];

WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/Prompts/DashboardPromptsCardCell.swift

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ class DashboardPromptsCardCell: UICollectionViewCell, Reusable {
7373
}
7474
}
7575

76+
// This provides a quick way to toggle the `Remove from dashboard` menu item.
77+
// Since it (probably) will not be included in Blogging Prompts V1, it is disabled by default.
78+
private let removeFromDashboardEnabled = false
79+
7680
// Used to present:
7781
// - The menu sheet for contextual menu in iOS13.
7882
// - The Blogging Prompts list when selected from the contextual menu.
@@ -273,15 +277,16 @@ class DashboardPromptsCardCell: UICollectionViewCell, Reusable {
273277

274278
// Defines the structure of the contextual menu items.
275279
private var contextMenuItems: [[MenuItem]] {
276-
return [
277-
[
278-
.viewMore(viewMoreMenuTapped),
279-
.skip(skipMenuTapped)
280-
],
281-
[
282-
.remove(removeMenuTapped)
283-
]
280+
let defaultItems: [MenuItem] = [
281+
.viewMore(viewMoreMenuTapped),
282+
.skip(skipMenuTapped)
284283
]
284+
285+
if removeFromDashboardEnabled {
286+
return [defaultItems, [.remove(removeMenuTapped)]]
287+
}
288+
289+
return [defaultItems]
285290
}
286291

287292
private var contextMenu: UIMenu {

WordPress/Classes/ViewRelated/NUX/WordPressAuthenticationManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ extension WordPressAuthenticationManager: WordPressAuthenticatorDelegate {
525525
// This should be removed once the experiment is done
526526
//
527527
private func assignMySiteExperimentIfNeeded(event: WPAnalyticsStat) {
528-
if event == .signedIn {
528+
if event == .signedIn || event == .createdAccount {
529529
if FeatureFlag.mySiteDashboard.enabled {
530530
let isTreatment = BlogDashboardAB.shared.variant == .treatment
531531
MySiteSettings().setDefaultSection(isTreatment ? .dashboard : .siteMenu)

0 commit comments

Comments
 (0)