-
Notifications
You must be signed in to change notification settings - Fork 121
Refactor PluginsService to use plugin file path for better stability #15871
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
98b4d7b
Fetch storage system plugin by plugin file path instead of plugin nam…
jaclync a0e9cdd
Merge branch 'trunk' into feat/WOOMOB-760-fetch-plugin-by-slug
jaclync 26cb6ec
Update `pluginsService.waitForPluginInStorage` in legacy eligibility …
jaclync 6542f82
Update unit tests for `LegacyPOSTabEligibilityCheckerTests`.
jaclync 5f83b82
Update comment to match what it does better.
jaclync c6488a1
Rename `plugin` to `pluginPath` parameter in `PluginsServiceProtocol.…
jaclync File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,12 @@ import protocol Storage.StorageManagerType | |
| /// A service for system plugins. | ||
| public protocol PluginsServiceProtocol { | ||
| /// Waits for a specific plugin to be available in storage. | ||
| func waitForPluginInStorage(siteID: Int64, pluginName: String, isActive: Bool) async -> SystemPlugin | ||
| /// - Parameters: | ||
| /// - siteID: The site ID to search for the plugin. | ||
| /// - plugin: The plugin's file path (e.g., "woocommerce/woocommerce.php" for WooCommerce). | ||
| /// - isActive: Whether to wait for the plugin to be active or inactive. | ||
| /// - Returns: The SystemPlugin when found in storage. | ||
| func waitForPluginInStorage(siteID: Int64, plugin: String, isActive: Bool) async -> SystemPlugin | ||
| } | ||
|
|
||
| public class PluginsService: PluginsServiceProtocol { | ||
|
|
@@ -16,20 +21,20 @@ public class PluginsService: PluginsServiceProtocol { | |
| } | ||
|
|
||
| @MainActor | ||
| public func waitForPluginInStorage(siteID: Int64, pluginName: String, isActive: Bool) async -> SystemPlugin { | ||
| let predicate = \StorageSystemPlugin.siteID == siteID && \StorageSystemPlugin.name == pluginName && \StorageSystemPlugin.active == isActive | ||
| let nameDescriptor = NSSortDescriptor(keyPath: \StorageSystemPlugin.name, ascending: true) | ||
| public func waitForPluginInStorage(siteID: Int64, plugin: String, isActive: Bool) async -> SystemPlugin { | ||
|
||
| let predicate = \StorageSystemPlugin.siteID == siteID && \StorageSystemPlugin.plugin == plugin && \StorageSystemPlugin.active == isActive | ||
| let pluginDescriptor = NSSortDescriptor(keyPath: \StorageSystemPlugin.plugin, ascending: true) | ||
| let resultsController = ResultsController<StorageSystemPlugin>(storageManager: storageManager, | ||
| matching: predicate, | ||
| fetchLimit: 1, | ||
| sortedBy: [nameDescriptor]) | ||
| sortedBy: [pluginDescriptor]) | ||
| do { | ||
| try resultsController.performFetch() | ||
| if let plugin = resultsController.fetchedObjects.first { | ||
| return plugin | ||
| } | ||
| } catch { | ||
| DDLogError("Error loading plugin \(pluginName) for site \(siteID) initially: \(error.localizedDescription)") | ||
| DDLogError("Error loading plugin \(plugin) for site \(siteID) initially: \(error.localizedDescription)") | ||
| } | ||
|
|
||
| return await withCheckedContinuation { continuation in | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think the usage of "wait for" bit here could be miss leading, since we're not waiting but matching the current plugin state in storage. wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching this inaccurate comment, updated the comment in 5f83b82.