Show notice when regeneration is taking place with link to AS

This commit is contained in:
Mike Jolley 2019-03-13 12:25:20 +00:00
parent b4cfef95a2
commit e6c60dd6c2
4 changed files with 74 additions and 11 deletions

View File

@ -26,13 +26,14 @@ class WC_Admin_Notices {
* @var array
*/
private static $core_notices = array(
'install' => 'install_notice',
'update' => 'update_notice',
'template_files' => 'template_file_check_notice',
'legacy_shipping' => 'legacy_shipping_notice',
'no_shipping_methods' => 'no_shipping_methods_notice',
'regenerating_thumbnails' => 'regenerating_thumbnails_notice',
'no_secure_connection' => 'secure_connection_notice',
'install' => 'install_notice',
'update' => 'update_notice',
'template_files' => 'template_file_check_notice',
'legacy_shipping' => 'legacy_shipping_notice',
'no_shipping_methods' => 'no_shipping_methods_notice',
'regenerating_thumbnails' => 'regenerating_thumbnails_notice',
'regenerating_lookup_table' => 'regenerating_lookup_table_notice',
'no_secure_connection' => 'secure_connection_notice',
);
/**
@ -323,6 +324,21 @@ class WC_Admin_Notices {
include dirname( __FILE__ ) . '/views/html-notice-secure-connection.php';
}
/**
* Notice shown when regenerating thumbnails background process is running.
*
* @since 3.6.0
*/
public static function regenerating_lookup_table_notice() {
// See if this is still relevent.
if ( ! wc_update_product_lookup_tables_is_running() ) {
self::remove_notice( 'regenerating_lookup_table' );
return;
}
include dirname( __FILE__ ) . '/views/html-notice-regenerating-lookup-table.php';
}
/**
* Determine if the store is running SSL.
*

View File

@ -0,0 +1,27 @@
<?php
/**
* Admin View: Notice - Regenerating thumbnails.
*
* @package WooCommerce/admin
*/
defined( 'ABSPATH' ) || exit;
?>
<div id="message" class="updated woocommerce-message">
<a class="woocommerce-message-close notice-dismiss" href="<?php echo esc_url( admin_url( 'admin.php?page=wc-status&tab=action-scheduler&s=wc_update_product_lookup_tables&status=pending' ) ); ?>"><?php esc_html_e( 'View progress', 'woocommerce' ); ?></a>
<p>
<string><?php esc_html_e( 'WooCommerce is updating product data in the background. ', 'woocommerce' ); ?></strong>
<?php
echo wp_kses_post(
sprintf(
/* Translators: 1: Link, 2: link close. */
__( 'Some queries and reports may not show accurate results until this finishes. It will take a few minutes and this notice will disappear when complete.', 'woocommerce' ),
'<a href="' . esc_url( admin_url( 'admin.php?page=wc-status&tab=action-scheduler&s=wc_update_product_lookup_tables' ) ) . '">',
'</a>'
)
);
?>
</p>
</div>

View File

@ -493,10 +493,9 @@ class WC_REST_System_Status_Tools_V2_Controller extends WC_REST_Controller {
break;
case 'regenerate_product_lookup_tables':
// Clear existing data.
$wpdb->query( "TRUNCATE TABLE {$wpdb->wc_product_meta_lookup};" );
// Run generation.
wc_update_product_lookup_tables();
if ( ! wc_update_product_lookup_tables_is_running() ) {
wc_update_product_lookup_tables();
}
$message = __( 'Lookup tables are regenerating', 'woocommerce' );
break;
case 'reset_roles':

View File

@ -1270,6 +1270,24 @@ function wc_deferred_product_sync( $product_id ) {
$wc_deferred_product_sync[] = $product_id;
}
/**
* See if the lookup table is being generated already.
*
* @since 3.6.0
* @return bool
*/
function wc_update_product_lookup_tables_is_running() {
$table_updates_pending = WC()->queue()->search(
array(
'status' => 'pending',
'group' => 'wc_update_product_lookup_tables',
'per_page' => 1,
)
);
return (bool) count( $table_updates_pending );
}
/**
* Populate lookup table data for products.
*
@ -1340,6 +1358,9 @@ function wc_update_product_lookup_tables() {
);
}
}
// Add notice.
WC_Admin_Notices::add_notice( 'regenerating_lookup_table' );
}
/**