Skip to content

Move model files from apps targets to WordPressData - #24378

Merged
mokagio merged 73 commits into
trunkfrom
mokagio/wordpressdata-target-xcdatamodeld-workbench-2-move-files
May 1, 2025
Merged

Move model files from apps targets to WordPressData#24378
mokagio merged 73 commits into
trunkfrom
mokagio/wordpressdata-target-xcdatamodeld-workbench-2-move-files

Conversation

@mokagio

@mokagio mokagio commented Apr 1, 2025

Copy link
Copy Markdown
Contributor

Builds on top of #24374, with standalone commits from #24375 and #24376, part of #24165.

@dangermattic

dangermattic commented Apr 1, 2025

Copy link
Copy Markdown
Collaborator
3 Warnings
⚠️ Modules/Package.swift was changed without updating its corresponding Package.resolved. Please resolve the Swift packages as appropriate to your project setup (e.g. in Xcode or by running swift package resolve).
⚠️ View files have been modified, but no screenshot or video is included in the pull request. Consider adding some for clarity.
⚠️ This PR is larger than 500 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.
1 Message
📖 This PR is still a Draft: some checks will be skipped.

Generated by 🚫 Danger

@mokagio mokagio mentioned this pull request Apr 1, 2025
14 tasks
Base automatically changed from mokagio/wordpressdata-target-xcdatamodeld-workbench-2 to trunk April 1, 2025 18:54
@mokagio
mokagio force-pushed the mokagio/wordpressdata-target-xcdatamodeld-workbench-2-move-files branch from 5e4258a to 8b47455 Compare April 1, 2025 20:38
@@ -0,0 +1 @@
// Here only to have the matching .m where to define the DDLogLevel value.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might not even be necessary. Gotta try that...

Comment thread Sources/WordPressData/WordPress-Swift.h Outdated
#ifndef WordPress_Swift_h
#define WordPress_Swift_h
// FIXME: Defined here to avoid compilation errors while files are migrated over...
#endif /* WordPress_Swift_h */

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be able to remove this now...

var wordPressComRestApi: WordPressComRestApi? {
account?.wordPressComRestApi
// FIXME: We are banking on the fact that by the time a consumer reads this, WPAccount will already have initialized its API client instance.
account?._private_wordPressComRestApi

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could decouple WPAccount wordPressComRestApi from WordPressAuthenticator using... a Notification?

@objc var wordPressComRestApi: WordPressComRestApi? {
if let api = _private_wordPressComRestApi {
return api
}
guard !authToken.isEmpty else {
DispatchQueue.main.async {
WordPressAuthenticationManager.showSigninForWPComFixingAuthToken()
}
return nil

private func makeWordPressComRestApi() -> WordPressComRestApi {
let api = WordPressComRestApi.defaultApi(
oAuthToken: authToken,
userAgent: WPUserAgent.defaultUserAgent(),
localeKey: WordPressComRestApi.LocaleKeyDefault
)
api.setInvalidTokenHandler { [weak self] in
guard let self else { return }
self.authToken = nil
WordPressAuthenticationManager.showSigninForWPComFixingAuthToken()

I suggest a Notification because I don't think injecting callbacks or using a delegate would be feasible with a model like this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #24392

@mokagio
mokagio force-pushed the mokagio/wordpressdata-target-xcdatamodeld-workbench-2-move-files branch from 710846d to 8e8a6d7 Compare April 2, 2025 03:44
Comment thread WordPress/Classes/Models/Blog/Blog.m Outdated
Comment on lines +572 to +581
return [self supportsRestApi] && [JetpackFeaturesRemovalCoordinator jetpackFeaturesEnabled];
// FIXME: See https://github.com/wordpress-mobile/WordPress-iOS/pull/24332
// return [self supportsRestApi] && [JetpackFeaturesRemovalCoordinator jetpackFeaturesEnabled];
return [self supportsRestApi];
case BlogFeatureTenor:
return [JetpackFeaturesRemovalCoordinator jetpackFeaturesEnabled];
// FIXME: See https://github.com/wordpress-mobile/WordPress-iOS/pull/24332
// return [JetpackFeaturesRemovalCoordinator jetpackFeaturesEnabled];
return NO;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#24393 should address this.


let startupEvent = SentryStartupEvent()
// FIXME: Import the Sentry stuff, too — But it accesses the app delegate!
// let startupEvent = SentryStartupEvent()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@crazytonyli is this ContextManager Sentry logging something that we need, or is it by any chance something that we added at the time of adoption just to monitor 🤞 ?

Being able to just chop it off would simplify things.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See also p1743115991824589/1743090023.463689-slack-C08HQR4C2TS

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry I missed this message. I don't think I added the events. It's very likely that they were there before my time. I doubt these events ever occur on production. I did a quick search on Sentry and don't see any related events. However, I think it's best to keep them in case we introduce some issues to the Core Data layer. At the bare minimum, we can send the events to the app via a notification.

@mokagio
mokagio force-pushed the mokagio/wordpressdata-target-xcdatamodeld-workbench-2-move-files branch from 8e8a6d7 to caa0730 Compare April 3, 2025 06:10
@mokagio
mokagio force-pushed the mokagio/wordpressdata-target-xcdatamodeld-workbench-2-move-files branch from caa0730 to f15a95b Compare April 3, 2025 10:56
@mokagio
mokagio force-pushed the mokagio/wordpressdata-target-xcdatamodeld-workbench-2-move-files branch 3 times, most recently from f0b8baf to 9747c86 Compare April 4, 2025 03:50
@mokagio
mokagio force-pushed the mokagio/wordpressdata-target-xcdatamodeld-workbench-2-move-files branch 3 times, most recently from 1b81897 to c5f7a76 Compare April 7, 2025 01:38
@wpmobilebot

wpmobilebot commented Apr 7, 2025

Copy link
Copy Markdown
Contributor
App Icon📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack
ConfigurationRelease-Alpha
Build Number27563
VersionPR #24378
Bundle IDcom.jetpack.alpha
Commit255fd0c
Installation URL4pqsd6d4r1f50
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot

wpmobilebot commented Apr 7, 2025

Copy link
Copy Markdown
Contributor
App Icon📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress
ConfigurationRelease-Alpha
Build Number27563
VersionPR #24378
Bundle IDorg.wordpress.alpha
Commit255fd0c
Installation URL035hhosmgq1go
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@mokagio
mokagio force-pushed the mokagio/wordpressdata-target-xcdatamodeld-workbench-2-move-files branch from c5f7a76 to 35a3999 Compare April 7, 2025 03:21
@mokagio
mokagio force-pushed the mokagio/wordpressdata-target-xcdatamodeld-workbench-2-move-files branch from 35a3999 to 85779b2 Compare April 7, 2025 05:11
mokagio and others added 15 commits May 1, 2025 11:27
Triggered by a few errors like

```
In file included from /Users/gio/Developer/a8c/wpios/WordPress/Classes/ViewRelated/Suggestions/SuggestionsTableViewCell.m:3:
/Users/gio/Developer/a8c/wpios/DerivedData/WordPress/Build/Intermediates.noindex/WordPress.build/Debug-iphonesimulator/Keystone.build/DerivedSources/Keystone-Swift.h:295:9: fatal error: module 'WebKit' not found
  295 | @import WebKit;
      |  ~~~~~~~^~~~~~
```

which I got after linking WordPressData against Keystone and moving all
the sources there.
Via

```
sed -i '' -E 's/representedClassName="(WordPress)?(\.)?([^"]+)"/representedClassName=".\3"/g' \
  Sources/WordPressData/Resources/WordPress.xcdatamodeld/WordPress\ 155.xcdatamodel/contents
```

which switched to "Current Product Module" but resulted in unit tests
failure in WordPressData, followed by

```
➜ sed -i '' -E 's/representedClassName="\.([^"]+)"/representedClassName="\1"/g' \
  Sources/WordPressData/Resources/WordPress.xcdatamodeld/WordPress\ 155.xcdatamodel/contents
```
Done via

```
find . \
  \( -path './DerivedData' -o -path './.git' -o -path './vendor' \) \
  -prune -o -type f -name "*.swift" \
  -exec sed -i '' -E 's/forEntityName: "([A-Za-z_][A-Za-z0-9_]*)"/forEntityName: \1.entityName()/g' {} +
```
Done via

```
find . \
  \( -path './DerivedData' -o -path './.git' -o -path './vendor' \) \
  -prune -o -type f -name "*.swift" \
  -exec sed -i '' -E 's/forEntityName: NSStringFromClass\(([A-Za-z_][A-Za-z0-9_]*)\.self\)/forEntityName: \1.entityName()/g' {} +
```

The goal is to have a single way to get the entity name so we can adapt
it to the new WordPressData setup in one go.
The goal is to have a single way to get the entity name so we can adapt
it to the new WordPressData setup in one go.
Done via

```
find . \( -path './DerivedData' -o -path './.git' -o -path './vendor' \) \
  -prune -o -type f -name "*.swift" \
  -exec sed -i '' -E 's/forEntityName: ([A-Za-z_][A-Za-z0-9_]*)\.classNameWithoutNamespaces\(\)/forEntityName: \1.entityName()/g' {} +
```

The goal is to have a single way to get the entity name so we can adapt
it to the new WordPressData setup in one go.
* Move remaining types to WordPressData

* Use Current Module for Swift-only types

* Fix ReaderTeamTopic compilation

* Add missing class names

* Remove unused SiteInfo

* Add Bundle.wordPressData and update DataMigratorTests

* Update CoreDataMigrationTests

* Fix unit tests (AppEnvironment required)
@mokagio
mokagio force-pushed the mokagio/wordpressdata-target-xcdatamodeld-workbench-2-move-files branch from 200048d to 200bb3e Compare May 1, 2025 01:53
}

let startupEvent = SentryStartupEvent()
// FIXME: Import the Sentry stuff, too — But it accesses the app delegate!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +98 to +108
// FIXME: Crashes because WPAccount fixture sets username and triggers BuildSettings access
// func testThatPluginManagementIsEnabledForJetpack() {
// let blog = BlogBuilder(mainContext)
// .withAnAccount()
// .withJetpack(version: "5.6", username: "test_user", email: "user@example.com")
// .with(isHostedAtWPCom: false)
// .with(isAdmin: true)
// .build()
//
// XCTAssertTrue(blog.supports(.pluginManagement))
// }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/// Creates a Blog
///
/// Defaults to creating a self-hosted blog
// FIXME: Currently duplicated from WordPressTests for ease of working. Eventually, should be extracted in a WordPressDataTestsHelper framework to share here and with the consumers.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sonarqubecloud

sonarqubecloud Bot commented May 1, 2025

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot

See analysis details on SonarQube Cloud

@mokagio
mokagio marked this pull request as ready for review May 1, 2025 03:14
@mokagio
mokagio requested review from crazytonyli and kean May 1, 2025 03:14
@mokagio
mokagio enabled auto-merge May 1, 2025 03:15
Comment thread Modules/Package.swift
// EmitSwiftModule normal arm64 (in target 'WordPressNotificationServiceExtension' from project 'WordPress')
// cd /path/to/repo/WordPress
//
// <unknown>:0: error: missing required modules: 'CocoaLumberjack', 'CocoaLumberjackSwiftSupport'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit, let's address later) we now have WPLogging.h for use in non-app targets (or any targets)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread Modules/Package.swift
//
"BuildSettingsKit",
"FormattableContentKit",
"SFHFKeychainUtils",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is duplicated dependency which produces a new warning.

Suggested change
"SFHFKeychainUtils",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see this comment, but noticed the warning elsewhere and addressed via #24514

GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
"WPDATA=1",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit) seems to be unused

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Thanks!

#24517

@mokagio
mokagio added this pull request to the merge queue May 1, 2025
Merged via the queue into trunk with commit c062a59 May 1, 2025
@mokagio
mokagio deleted the mokagio/wordpressdata-target-xcdatamodeld-workbench-2-move-files branch May 1, 2025 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants