Fix a bug in the notes updater; better handle test case where
note expiration/expired date changes at woocommerce.com causing an expired note to become an expiring note (corner case)
This commit is contained in:
parent
8851a8cfe7
commit
24c80427fc
|
@ -437,6 +437,13 @@ class WC_Admin_Note extends WC_Data {
|
|||
$this->set_date_prop( 'date_reminder', $date );
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear actions from a note.
|
||||
*/
|
||||
public function clear_actions() {
|
||||
$this->set_prop( 'actions', array() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an action to the note
|
||||
*
|
||||
|
|
|
@ -303,18 +303,20 @@ class WC_Admin_Notes_Woo_Subscriptions_Notes {
|
|||
|
||||
if ( ! $note ) {
|
||||
$note = new WC_Admin_Note();
|
||||
}
|
||||
|
||||
// Reset everything in case we are repurposing an expired note as an expiring note.
|
||||
$note->set_title( $note_title );
|
||||
$note->set_type( WC_Admin_Note::E_WC_ADMIN_NOTE_WARNING );
|
||||
$note->set_icon( 'notice' );
|
||||
$note->set_name( self::SUBSCRIPTION_NOTE_NAME );
|
||||
$note->set_source( 'wc-admin' );
|
||||
$note->clear_actions();
|
||||
$note->add_action(
|
||||
'enable-autorenew',
|
||||
__( 'Enable Autorenew', 'wc-admin' ),
|
||||
'https://woocommerce.com/my-account/my-subscriptions/'
|
||||
);
|
||||
}
|
||||
|
||||
$note->set_content( $note_content );
|
||||
$note->set_content_data( $note_content_data );
|
||||
$note->save();
|
||||
|
@ -337,7 +339,7 @@ class WC_Admin_Notes_Woo_Subscriptions_Notes {
|
|||
$note_content_data = $note->get_content_data();
|
||||
if ( $note_content_data->expired ) {
|
||||
// We've already got a full fledged expired note for this. Bail.
|
||||
// These notes' content doesn't change with time.
|
||||
// Expired notes' content don't change with time.
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -373,6 +375,7 @@ class WC_Admin_Notes_Woo_Subscriptions_Notes {
|
|||
$note->set_icon( 'notice' );
|
||||
$note->set_name( self::SUBSCRIPTION_NOTE_NAME );
|
||||
$note->set_source( 'wc-admin' );
|
||||
$note->clear_actions();
|
||||
$note->add_action(
|
||||
'renew-subscription',
|
||||
__( 'Renew Subscription', 'wc-admin' ),
|
||||
|
|
|
@ -104,6 +104,18 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Object_Da
|
|||
global $wpdb;
|
||||
|
||||
if ( $note->get_id() ) {
|
||||
$date_created = $note->get_date_created();
|
||||
$date_created_timestamp = $date_created->getTimestamp();
|
||||
$date_created_to_db = gmdate( 'Y-m-d H:i:s', $date_created_timestamp );
|
||||
|
||||
$date_reminder = $note->get_date_reminder();
|
||||
if ( is_null( $date_reminder ) ) {
|
||||
$date_reminder_to_db = null;
|
||||
} else {
|
||||
$date_reminder_timestamp = $date_reminder->getTimestamp();
|
||||
$date_reminder_to_db = gmdate( 'Y-m-d H:i:s', $date_reminder_timestamp );
|
||||
}
|
||||
|
||||
$wpdb->update(
|
||||
$wpdb->prefix . 'woocommerce_admin_notes',
|
||||
array(
|
||||
|
@ -116,8 +128,8 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Object_Da
|
|||
'content_data' => wp_json_encode( $note->get_content_data() ),
|
||||
'status' => $note->get_status(),
|
||||
'source' => $note->get_source(),
|
||||
'date_created' => $note->get_date_created(),
|
||||
'date_reminder' => $note->get_date_reminder(),
|
||||
'date_created' => $date_created_to_db,
|
||||
'date_reminder' => $date_reminder_to_db,
|
||||
),
|
||||
array( 'note_id' => $note->get_id() )
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue