Skip to content

Move model files from apps targets to WordPressData #24378

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 71 commits into
base: trunk
Choose a base branch
from

Conversation

mokagio
Copy link
Contributor

@mokagio mokagio commented Apr 1, 2025

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

@dangermattic
Copy link
Collaborator

dangermattic commented Apr 1, 2025

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
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...

#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
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...

@@ -11,7 +11,8 @@ public extension Blog {
/// - Warning: this method doesn't know if a Jetpack blog has the JSON API disabled.
@objc
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
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
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 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
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.

@@ -234,13 +235,14 @@ private extension ContextManager {
fatalError("Can't create object model named \(modelName) at \(modelFileURL)")
}

let startupEvent = SentryStartupEvent()
// FIXME: Import the Sentry stuff, too — But it accesses the app delegate!
// let startupEvent = SentryStartupEvent()
Copy link
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
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
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
Copy link
Contributor

wpmobilebot commented Apr 7, 2025

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 Number27506
VersionPR #24378
Bundle IDcom.jetpack.alpha
Commit200048d
Installation URL6c16vdi27pi00
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Apr 7, 2025

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 Number27506
VersionPR #24378
Bundle IDorg.wordpress.alpha
Commit200048d
Installation URL04hhmfjhmi7i0
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 added 14 commits April 23, 2025 10:57
Via

```
find WordPress/WordPressTest \
  -name "*.swift" \
  -type f \
  -exec perl -i -0pe 's/(@testable import WordPress\n)(\nclass (\w+): CoreDataTestCase \{)/\1\@testable import WordPressData\n\nclass \3: CoreDataTestCase {/g' \
  {} \;
```

and

```
find WordPress/WordPressTest \
  -name "*.swift" \
  -type f \
  -exec perl -i -0pe 's/(@testable import WordPress\n)(\nfinal class (\w+): CoreDataTestCase \{)/\1\@testable import WordPressData\n\nfinal class \3: CoreDataTestCase {/g' \
  {} \;
```
@mokagio mokagio force-pushed the mokagio/wordpressdata-target-xcdatamodeld-workbench-2-move-files branch from 930dc78 to 161a708 Compare April 23, 2025 00:58
mokagio added 6 commits April 23, 2025 11:04
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
```
@mokagio mokagio force-pushed the mokagio/wordpressdata-target-xcdatamodeld-workbench-2-move-files branch from 161a708 to f851bc5 Compare April 23, 2025 01:05
@mokagio
Copy link
Contributor Author

mokagio commented Apr 23, 2025

The current status here is that we are up to date with trunk, all targets build, but there are issues with the unit tests due to finding the models out of the framework.

I tried switching all to global namespace module, but it did not work 172031e

The situation is made a bit more complex by having a variety of ways with which we instantiate entities

image

Given there are only three possible core data module settings, one would expect it to be straightforward to try them and find the best one. Alas, it's proven a fiddly task for me.

I'll spend a bit more time on this today in the hope of getting to the bottom of it before hading over to @kean who offered to take over the last bits of integration.

mokagio added 4 commits April 23, 2025 20:37
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.
@mokagio mokagio force-pushed the mokagio/wordpressdata-target-xcdatamodeld-workbench-2-move-files branch from f851bc5 to 1deadc6 Compare April 23, 2025 11:57
* 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)
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot

See analysis details on SonarQube Cloud

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