Skip to content

Create AJAX runtime environment setup/cleanup#101

Merged
jjgrainger merged 14 commits into
trunkfrom
feature/ajax-runtime-environment-setup
Mar 27, 2023
Merged

Create AJAX runtime environment setup/cleanup#101
jjgrainger merged 14 commits into
trunkfrom
feature/ajax-runtime-environment-setup

Conversation

@jjgrainger
Copy link
Copy Markdown
Contributor

Closes #86

@jjgrainger jjgrainger requested a review from felixarntz March 17, 2023 17:09
@jjgrainger
Copy link
Copy Markdown
Contributor Author

Hi @felixarntz

After setting this up I've been facing errors where the wp_get_cache function do not exist. From what I can tell this is due to setting up and preparing the Runners in the object-cache.php file, in particular when getting the plugin parameter and using the Plugin_Request_Utility::get_plugin_basename_from_input which calls get_plugins() that uses wp_get_cache.

The reason these functions are called is because we need to create the Check_Context for the Checks class in order to return the array of checks to then work out if there is a runtime check and setup the environment.

I'm wondering what the best path forward is here? Whether we refactor the Checks class so we can return the array of Checks without needing a Check_Context (though I think we would still need to test if the plugin is active based on the logic we are trying to run) or if we simply could require_once wp-includes/cache.php before the get_plugins call is made?

Happy to discuss this over a call as I feel this is somewhat related to my other comment - #100 (comment)

Thanks

@felixarntz
Copy link
Copy Markdown
Member

felixarntz commented Mar 17, 2023

@jjgrainger Good catch!

Maybe we can get around this without any notable refactoring, just by executing that logic later? While we have to call the code in object-cache.php, it doesn't necessarily have to be executed right away.

Potentially, we can hook the code into the muplugins_loaded action? That action should still be in time for us to do the other things, like filter out plugins etc. If there is an earlier action that we can reasonably use, that would be even better, but I'm not sure there is.

@jjgrainger jjgrainger marked this pull request as ready for review March 20, 2023 19:02
@jjgrainger
Copy link
Copy Markdown
Contributor Author

Thanks @felixarntz

I've updated the PR to use the muplugins_loaded action to initialize the runner and this is ready for review.

After updating this I came across a different error where the WP_PLUGIN_CHECK_MAIN_FILE and WP_PLUGIN_CHECK_PLUGIN_DIR_PATH constants were not defined in the Universal_Runtime_Preparation.

I've put in a small fix to get around this but I'm not sure this is the best approach but we can discuss as part of the code review.

Copy link
Copy Markdown
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

@jjgrainger Left a few comments, some of them similar to what I mentioned on #100.

Comment thread includes/Admin/Admin_AJAX.php Outdated
Comment thread includes/Admin/Admin_AJAX.php Outdated
Comment thread includes/Admin/Admin_AJAX.php Outdated
Comment thread includes/Admin/Admin_AJAX.php Outdated
Comment on lines +104 to +105
'plugin' => $plugin,
'checks' => $checks,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see you're returning all these values from every AJAX endpoint just to be able to chain the AJAX requests in the JS file. I think that makes for a confusing architecture and requires us to include unnecessary data in the AJAX responses. No need to fix that here since it's already happening in existing code, but I think that will be something we should resolve as part of the architecture review.

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.

Thanks @felixarntz I agree and let's tackle this as part of the architectural review.

Comment thread assets/js/plugin-check-admin.js Outdated
Comment on lines +15 to +17
.then( setupEnvironment )
.then( runChecks )
.then( cleanupEnvironment )
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

See my comment below, rather than chaining these and thereby forcing every AJAX response to include its request parameters to pass it on to the next AJAX request, I think we should decouple them.

We can then change the JS functions to accept dedicated parameters for the things that each function needs rather than the generic data object from the previous AJAX response.

But like my comment above, let's handle this refactoring in a separate PR.

Comment thread includes/Admin/Admin_AJAX.php Outdated
Copy link
Copy Markdown
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

@jjgrainger Almost good to go, just one thing that is off in the FormData set, and a few nit-picks.

Comment thread assets/js/plugin-check-admin.js Outdated
Comment thread assets/js/plugin-check-admin.js Outdated
Comment thread assets/js/plugin-check-admin.js Outdated
Comment thread assets/js/plugin-check-admin.js
@jjgrainger jjgrainger requested a review from felixarntz March 22, 2023 14:27
Copy link
Copy Markdown
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

@jjgrainger One last question :)

Comment thread includes/Admin/Admin_AJAX.php Outdated
Copy link
Copy Markdown
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

Thanks @jjgrainger!

@jjgrainger jjgrainger requested a review from spacedmonkey March 22, 2023 18:25
Comment thread assets/js/plugin-check-admin.js
Comment thread assets/js/plugin-check-admin.js
Comment thread includes/Checker/AJAX_Runner.php
Comment thread includes/Checker/Preparations/Force_Single_Plugin_Preparation.php
Comment on lines +57 to +62
if ( ! defined( 'WP_PLUGIN_CHECK_PLUGIN_DIR_PATH' ) ) {
$plugins_dir = defined( 'WP_PLUGIN_DIR' ) ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/plugins';
$theme_folder = $plugins_dir . '/plugin-check/test-content/themes';
} else {
$theme_folder = WP_PLUGIN_CHECK_PLUGIN_DIR_PATH . 'test-content/themes';
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Comment thread includes/Admin/Admin_AJAX.php
Copy link
Copy Markdown
Member

@spacedmonkey spacedmonkey left a comment

Choose a reason for hiding this comment

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

LGTM

@felixarntz
Copy link
Copy Markdown
Member

@jjgrainger Now that #100 was merged, there's a merge conflict here, could you look into that please?

@jjgrainger
Copy link
Copy Markdown
Contributor Author

Thanks @felixarntz @spacedmonkey I've addressed the conflicts and will merge now

@jjgrainger jjgrainger merged commit 95a26fd into trunk Mar 27, 2023
@jjgrainger jjgrainger deleted the feature/ajax-runtime-environment-setup branch March 27, 2023 17:38
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.

AJAX Runtime Environment Setup/Cleanup

4 participants