Skip to content
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

Fix marketplace promotions action scheduler #46630

Merged
merged 2 commits into from Apr 16, 2024

Conversation

andfinally
Copy link
Contributor

@andfinally andfinally commented Apr 16, 2024

Submission Review Guidelines:

Changes proposed in this Pull Request:

WooCommerce 8.8.1 introduced some code dependent on Action Scheduler 3.3+. Under normal circumstances that'd be ok, as this WooCommerce version comes bundled with A-S 3.7.0. But other plugins that also bundle A-S might be loading their version of A-S unusually early, preventing the one in WC from loading. In this situation, activating WooCommerce would give rise to this fatal error.

PHP Fatal error:  Uncaught Error: Call to undefined function as_has_scheduled_action() in /wordpress/plugins/woocommerce/8.8.1/includes/admin/class-wc-admin-marketplace-promotions.php:80
Stack trace:
#0 /wordpress/core/6.5.2/wp-includes/class-wp-hook.php(324): WC_Admin_Marketplace_Promotions::schedule_promotion_fetch('')
#1 /wordpress/core/6.5.2/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array)
#2 /wordpress/core/6.5.2/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#3 /wordpress/core/6.5.2/wp-settings.php(695): do_action('init')
#4 /srv/htdocs/wp-config.php(81): require_once('/wordpress/core...')
#5 /wordpress/core/6.5.2/wp-load.php(55): require_once('/srv/htdocs/wp-...')
#6 /wordpress/core/6.5.2/wp-admin/admin-ajax.php(22): require_once('/wordpress/core...')
#7 {main}
  thrown in /wordpress/plugins/woocommerce/8.8.1/includes/admin/class-wc-admin-marketplace-promotions.php on line 80

This PR adds defensive checks to WC_Admin_Marketplace_Promotions to ensure A-S functions are available before it calls them.

Notes

How to test the changes in this Pull Request:

Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:

  1. Disable WooCommerce in your local testing environment.
  2. Check out this branch. Build WooCommerce:
nvm use
pnpm install
pnpm build
  1. Install and activate WP Mail SMTP 2.8.0. You can use this file: wp-mail-smtp.2.8.0.zip.
  2. Activate WooCommerce. You should be able to view wp-admin without getting the fatal error.

Testing the marketplace promotions still work

  1. Deactivate WP Mail SMTP.
  2. Edit plugins/woocommerce/includes/admin/class-wc-admin-marketplace-promotions.php and replace line 97 with this. This makes a request to a gist with dummy data that is valid until 1 May.
$raw_promotions = wp_safe_remote_get( 'https://gist.githubusercontent.com/andfinally/acd8646151c0108f92979c985c20a0d8/raw/promotions.json' );
  1. On line 21, change the frequency of the scheduled action to five minutes:
const SCHEDULED_ACTION_INTERVAL = 5 * MINUTE_IN_SECONDS;
  1. Visit the pending scheduled actions page and search for woocommerce_marketplace_fetch_promotions. If there's a pending action, cancel it using the "cancel" hover link under it in the list. A new action should be scheduled.
  2. After 5 minutes or so, the action should run. (You may need to jog it by viewing a page on your test site.)
  3. The menu bubble should appear on the WooCommerce > Extensions menu item, and the notice should appear on Marketplace pages like http://localhost:8888/wp-admin/admin.php?page=wc-admin&path=%2Fextensions.

image

Changelog entry

  • Automatically create a changelog entry from the details below.

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

Comment

@github-actions github-actions bot added focus: api tests Issues related to API tests. focus: documentation Issues and PRs related to improving documentation focus: e2e tests Issues related to e2e tests package: @woocommerce/e2e-core-tests Issues related to @woocommerce/e2e-core-tests package. package: @woocommerce/components issues related to @woocommerce/components package: @woocommerce/experimental issues related to @woocommerce/experimental package: @woocommerce/onboarding issues related to @woocommerce/onboarding plugin: woo-ai Issues related to the Woo AI features plugin. plugin: woocommerce Issues related to the WooCommerce Core plugin. plugin: woocommerce beta tester Issues related to the WooCommerce Beta Tester plugin. tool: monorepo infrastructure Issues and PRs related to monorepo tooling. labels Apr 16, 2024
@woocommercebot woocommercebot requested review from a team, psealock, ilyasfoo, lsinger, alexflorisca and imanish003 and removed request for a team April 16, 2024 07:49
Copy link
Contributor

github-actions bot commented Apr 16, 2024

Hi @lsinger, @Dan-Q, @corsonr, @psealock, @ilyasfoo, @alexflorisca, @imanish003, @woocommerce/rubik, @woocommerce/solaris, @woocommerce/mothra, @woocommerce/ghidorah, @woocommerce/woo-fse, @woocommerce/developer-advocacy, @woocommerce/vortex

Apart from reviewing the code changes, please make sure to review the testing instructions as well.

You can follow this guide to find out what good testing instructions should look like:
https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions

@andfinally andfinally reopened this Apr 16, 2024
@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Apr 16, 2024
@andfinally andfinally self-assigned this Apr 16, 2024
@andfinally andfinally marked this pull request as ready for review April 16, 2024 11:31
@andfinally andfinally added the needs: developer feedback Issues that need feedback from one of the WooCommerce Core developers. label Apr 16, 2024
@andfinally andfinally requested review from a team, Dan-Q and corsonr and removed request for a team April 16, 2024 11:32
@andfinally andfinally changed the title Fix/marketplace promotions action scheduler Fix marketplace promotions action scheduler Apr 16, 2024
Copy link
Member

@corsonr corsonr left a comment

Choose a reason for hiding this comment

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

All good, I can confirm that there's no more fatal error, and that the promotions do show fine on the extensions page so as the menu bubble.

Note to other reviewers: the gist adjustments should be done at line 100, not 97. Also do not forget to revert changes and cancel the 5min woocommerce_marketplace_fetch_promotions scheduled action so that it goes back to 12h.

@andfinally andfinally merged commit eb75902 into trunk Apr 16, 2024
56 checks passed
@andfinally andfinally deleted the fix/marketplace-promotions-action-scheduler branch April 16, 2024 13:08
@github-actions github-actions bot added this to the 8.9.0 milestone Apr 16, 2024
@github-actions github-actions bot added the needs: analysis Indicates if the PR requires a PR testing scrub session. label Apr 16, 2024
@alopezari alopezari added needs: internal testing Indicates if the PR requires further testing conducted by Solaris status: analysis complete Indicates if a PR has been analysed by Solaris and removed needs: analysis Indicates if the PR requires a PR testing scrub session. labels Apr 16, 2024
@nigeljamesstevenson nigeljamesstevenson modified the milestones: 8.9.0, 8.8.0 Apr 16, 2024
github-actions bot pushed a commit that referenced this pull request Apr 16, 2024
* Defensive coding for when `as_has_scheduled_action` Action Scheduler function is not defined.

* Changelog.
nigeljamesstevenson pushed a commit that referenced this pull request Apr 16, 2024
* Fix marketplace promotions action scheduler (#46630)

* Defensive coding for when `as_has_scheduled_action` Action Scheduler function is not defined.

* Changelog.

* Prep for cherry pick 46630

---------

Co-authored-by: And Finally <andfinally@users.noreply.github.com>
Co-authored-by: WooCommerce Bot <no-reply@woo.com>
nielslange pushed a commit that referenced this pull request Apr 20, 2024
* Defensive coding for when `as_has_scheduled_action` Action Scheduler function is not defined.

* Changelog.
@brettnzl
Copy link

@corsonr this fix has caused an issue with WooCommerce "Woo Subscriptions" from the day we updated to this, we have been getting several "Failed-scheduled-actions" logs.

Screenshot 2024-04-22 090402

2024-04-21T00:08:41+00:00 Notice scheduled action 665467 (subscription payment) failed to finish processing due to the following exception: Call to a member function meta_exists() on null
Additional context
{
"_legacy": true
}
2024-04-21T00:08:41+00:00 Notice action args: subscription_id: 7212
Additional context
{
"_legacy": true
}
2024-04-21T00:56:42+00:00 Notice scheduled action 665567 (subscription payment) failed to finish processing due to the following exception: Call to a member function meta_exists() on null
Additional context
2024-04-21T00:56:42+00:00 Notice action args: subscription_id: 9027
Additional context

@corsonr
Copy link
Member

corsonr commented Apr 22, 2024

A fix has already been pushed by @andfinally if I am correct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: developer feedback Issues that need feedback from one of the WooCommerce Core developers. needs: internal testing Indicates if the PR requires further testing conducted by Solaris plugin: woocommerce Issues related to the WooCommerce Core plugin. status: analysis complete Indicates if a PR has been analysed by Solaris
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants