Prevent update notice appearing twice

@claudiosmweb
This commit is contained in:
Mike Jolley 2016-06-13 12:44:16 +01:00
parent 81994720f0
commit 34f2bd683e
4 changed files with 16 additions and 14 deletions

View File

@ -30,7 +30,6 @@ class WC_Admin_Notices {
private static $core_notices = array( private static $core_notices = array(
'install' => 'install_notice', 'install' => 'install_notice',
'update' => 'update_notice', 'update' => 'update_notice',
'updating' => 'updating_notice',
'template_files' => 'template_file_check_notice', 'template_files' => 'template_file_check_notice',
'theme_support' => 'theme_check_notice', 'theme_support' => 'theme_check_notice',
'legacy_shipping' => 'legacy_shipping_notice', 'legacy_shipping' => 'legacy_shipping_notice',
@ -190,15 +189,13 @@ class WC_Admin_Notices {
* If we need to update, include a message with the update button. * If we need to update, include a message with the update button.
*/ */
public static function update_notice() { public static function update_notice() {
include( 'views/html-notice-update.php' );
}
/**
* If we are updating, show progress.
*/
public static function updating_notice() {
if ( version_compare( get_option( 'woocommerce_db_version' ), WC_VERSION, '<' ) ) { if ( version_compare( get_option( 'woocommerce_db_version' ), WC_VERSION, '<' ) ) {
$updater = new WC_Background_Updater();
if ( ! $updater->is_updating() ) {
include( 'views/html-notice-update.php' );
} else {
include( 'views/html-notice-updating.php' ); include( 'views/html-notice-updating.php' );
}
} else { } else {
include( 'views/html-notice-updated.php' ); include( 'views/html-notice-updated.php' );
} }

View File

@ -9,7 +9,7 @@ if ( ! defined( 'ABSPATH' ) ) {
?> ?>
<div id="message" class="updated woocommerce-message wc-connect"> <div id="message" class="updated woocommerce-message wc-connect">
<a class="woocommerce-message-close notice-dismiss" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wc-hide-notice', 'updating' ), 'woocommerce_hide_notices_nonce', '_wc_notice_nonce' ) ); ?>"><?php _e( 'Dismiss', 'woocommerce' ); ?></a> <a class="woocommerce-message-close notice-dismiss" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wc-hide-notice', 'update', remove_query_arg( 'do_update_woocommerce' ) ), 'woocommerce_hide_notices_nonce', '_wc_notice_nonce' ) ); ?>"><?php _e( 'Dismiss', 'woocommerce' ); ?></a>
<p><?php _e( 'WooCommerce data update complete. Thank you for updating to the latest version!', 'woocommerce' ); ?></p> <p><?php _e( 'WooCommerce data update complete. Thank you for updating to the latest version!', 'woocommerce' ); ?></p>
</div> </div>

View File

@ -40,8 +40,6 @@ class WC_Background_Updater extends WP_Background_Process {
* Updater will still run via cron job if this fails for any reason. * Updater will still run via cron job if this fails for any reason.
*/ */
public function dispatch() { public function dispatch() {
WC_Admin_Notices::add_notice( 'updating' );
$dispatched = parent::dispatch(); $dispatched = parent::dispatch();
if ( is_wp_error( $dispatched ) ) { if ( is_wp_error( $dispatched ) ) {
@ -66,6 +64,14 @@ class WC_Background_Updater extends WP_Background_Process {
echo '<div class="error"><p>' . __( 'Unable to dispatch WooCommerce updater:', 'woocommerce' ) . ' ' . esc_html( $this->error ) . '</p></div>'; echo '<div class="error"><p>' . __( 'Unable to dispatch WooCommerce updater:', 'woocommerce' ) . ' ' . esc_html( $this->error ) . '</p></div>';
} }
/**
* Is the updater running?
* @return boolean
*/
public function is_updating() {
return false === $this->is_queue_empty();
}
/** /**
* Task * Task
* *
@ -105,7 +111,6 @@ class WC_Background_Updater extends WP_Background_Process {
*/ */
protected function complete() { protected function complete() {
$logger = new WC_Logger(); $logger = new WC_Logger();
$logger->add( 'wc_db_updates', 'Data update complete' ); $logger->add( 'wc_db_updates', 'Data update complete' );
WC_Install::update_db_version(); WC_Install::update_db_version();
parent::complete(); parent::complete();

View File

@ -114,7 +114,7 @@ class WC_Install {
public static function install_actions() { public static function install_actions() {
if ( ! empty( $_GET['do_update_woocommerce'] ) ) { if ( ! empty( $_GET['do_update_woocommerce'] ) ) {
self::update(); self::update();
WC_Admin_Notices::remove_notice( 'update' ); WC_Admin_Notices::add_notice( 'update' );
} }
} }