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 missing AS missing DB tables issue #4897

Merged

Conversation

engahmeds3ed
Copy link
Contributor

@engahmeds3ed engahmeds3ed commented Apr 6, 2022

Description

In some cases when client updates to our latest version 3.11.0.2, they face fatal error because one or more tables related to Action Scheduler isn't there, the error is like the following:-

[05-Apr-2022 12:36:29 UTC] PHP Fatal error:  Uncaught RuntimeException: Error saving action: Table 'wordpress.wp_actionscheduler_actions' doesn't exist in /var/www/html/wordpress/wp-content/plugins/wp-rocket/inc/Dependencies/ActionScheduler/classes/data-stores/ActionScheduler_DBStore.php:86
Stack trace:
#0 /var/www/html/wordpress/wp-content/plugins/wp-rocket/inc/Dependencies/ActionScheduler/classes/ActionScheduler_ActionFactory.php(177): ActionScheduler_DBStore->save_action()
#1 /var/www/html/wordpress/wp-content/plugins/wp-rocket/inc/Dependencies/ActionScheduler/classes/ActionScheduler_ActionFactory.php(105): ActionScheduler_ActionFactory->store()
#2 /var/www/html/wordpress/wp-content/plugins/wp-rocket/inc/Dependencies/ActionScheduler/functions.php(54): ActionScheduler_ActionFactory->recurring()
#3 /var/www/html/wordpress/wp-content/plugins/wp-rocket/inc/Engine/Common/Queue/AbstractASQueue.php(51): as_schedule_recurring_action()
#4 /var/www/html/wordpress/wp-content/plugins/wp-rocket/inc/Engine/Optimization/RUCSS/Controller/Queue.php(57): WP_Rocket\Eng in /var/www/html/wordpress/wp-content/plugins/wp-rocket/inc/Dependencies/ActionScheduler/classes/data-stores/ActionScheduler_DBStore.php on line 86

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (non-breaking change which improves an existing functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Is the solution different from the one proposed during the grooming?

Not groomed.

How Has This Been Tested?

I need to test the queue runner by sending too much jobs from different groups and see if it'll handle our jobs with priority.

To test that you need to delete wp_actionscheduler_actions table from the DB and then check the site, with this PR you should see the admin area without a problem but in the log file you will still see the fatal error, but with the next refresh all tables are created and no fatal error should happen.

Checklist:

Please delete the options that are not relevant.

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@engahmeds3ed engahmeds3ed self-assigned this Apr 6, 2022
@engahmeds3ed engahmeds3ed marked this pull request as ready for review April 6, 2022 23:25
@engahmeds3ed engahmeds3ed requested a review from a team April 6, 2022 23:28
@Mai-Saad Mai-Saad added type: bug Indicates an unexpected problem or unintended behavior priority: high Issues which should be resolved as quickly as possible severity: critical Defect that prevents the testing/use of the software module: remove unused css labels Apr 7, 2022
@piotrbak
Copy link
Contributor

piotrbak commented Apr 7, 2022

@engahmeds3ed If we detect this problem we should display not dismissable error (red) notice as follows:
WP Rocket: We detected missing database table related to Action Scheduler. Please visit the following URL(link) to recreate it, as it's needed for WP Rocket to work correctly.

@piotrbak piotrbak added this to the 3.11.0.3 milestone Apr 7, 2022
@Tabrisrp
Copy link
Contributor

Tabrisrp commented Apr 7, 2022

@piotrbak Action Scheduler automatically takes care of creating missing tables and displaying a notice for it

$table_list = array(
'actionscheduler_actions',
'actionscheduler_logs',
'actionscheduler_groups',
'actionscheduler_claims',
);
$found_tables = $wpdb->get_col( "SHOW TABLES LIKE '{$wpdb->prefix}actionscheduler%'" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
foreach ( $table_list as $table_name ) {
if ( ! in_array( $wpdb->prefix . $table_name, $found_tables ) ) {
$this->admin_notices[] = array(
'class' => 'error',
'message' => __( 'It appears one or more database tables were missing. Attempting to re-create the missing table(s).' , 'action-scheduler' ),
);
$this->recreate_tables();
parent::display_admin_notices();
return;
}
}

@piotrbak
Copy link
Contributor

piotrbak commented Apr 7, 2022

@Tabrisrp From what @engahmeds3ed told me, it's happening only on their admin page. That's why we need to have our own info notice there.

Let's talk about this on the standup

@engahmeds3ed
Copy link
Contributor Author

With this last change I did the following:-

  • Show the admin notice in all pages except for the Action Scheduler tools page.
  • Cache the number of AS tables for 24 hours.
  • Remove this cache (transient) once any fatal error is detected.

@Tabrisrp Tabrisrp changed the base branch from develop to trunk April 8, 2022 19:30
@Tabrisrp Tabrisrp changed the base branch from trunk to branch-3.11.0.3 April 8, 2022 19:32
Copy link

@Mai-Saad Mai-Saad left a comment

Choose a reason for hiding this comment

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

Working as expected with the following notes:

  • The error will be displayed on all pages except AS
  • The error will be displayed even if RUCSS is not enabled
  • Fatal error will exist in debug.log while RUCSS is enabled till we click that link in the msg

inc/Engine/Optimization/RUCSS/Admin/Settings.php Outdated Show resolved Hide resolved
inc/Engine/Optimization/RUCSS/Admin/Settings.php Outdated Show resolved Hide resolved
inc/Engine/Optimization/RUCSS/Admin/Subscriber.php Outdated Show resolved Hide resolved
inc/Engine/Optimization/RUCSS/Admin/Subscriber.php Outdated Show resolved Hide resolved
@Tabrisrp Tabrisrp merged commit 86260dd into branch-3.11.0.3 Apr 11, 2022
@Tabrisrp Tabrisrp deleted the enhancement/call_AS_cron_function_at_the_end branch April 11, 2022 13:56
@Tabrisrp Tabrisrp mentioned this pull request Apr 11, 2022
@umviajante
Copy link

Hello guys. I am a WP Rocket user and subscriber. I can't find a link to open a support ticket.

I had to restore a backup of my blog and now even in the current version of WP Rocket I see an alert:


WP Rocket: We detected missing database table related to Action Scheduler. Please visit the following URL to recreate it, as it is needed for WP Rocket to work correctly.


I don't know what to do... it looks like this table wasn't created or maybe it got lost when I restored my database. Now that WP Rocket is in the current version... I don't know what to do to solve the problem.

@umviajante
Copy link

Ps.: after leaving the plugin active in the latest version, in addition to the alert in the control panel, the site starts showing 504 errors and seems to be related to the database problem.

@engahmeds3ed
Copy link
Contributor Author

Hello guys. I am a WP Rocket user and subscriber. I can't find a link to open a support ticket.

I had to restore a backup of my blog and now even in the current version of WP Rocket I see an alert:

WP Rocket: We detected missing database table related to Action Scheduler. Please visit the following URL to recreate it, as it is needed for WP Rocket to work correctly.

I don't know what to do... it looks like this table wasn't created or maybe it got lost when I restored my database. Now that WP Rocket is in the current version... I don't know what to do to solve the problem.

You can reach support by sending an email to support@wp-rocket.me

What you want to do is to visit the url in this admin notice, which will redirect you to Action Scheduler page like the following:

https://example.org/wp-admin/tools.php?page=action-scheduler

Note: You need to replace example.org with your site domain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: remove unused css priority: high Issues which should be resolved as quickly as possible severity: critical Defect that prevents the testing/use of the software type: bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants