Use $wpdb->replace instead of doing a select and then deciding to do an update or insert. Fixes #10389

This commit is contained in:
Gerhard Potgieter 2016-02-23 14:48:48 +02:00
parent a6cdabff7e
commit 62e19162e6
1 changed files with 13 additions and 33 deletions

View File

@ -173,39 +173,19 @@ class WC_Session_Handler extends WC_Session {
if ( $this->_dirty && $this->has_session() ) {
global $wpdb;
$session_id = $wpdb->get_var( $wpdb->prepare( "SELECT session_id FROM $this->_table WHERE session_key = %s;", $this->_customer_id ) );
if ( $session_id ) {
$wpdb->update(
$this->_table,
array(
'session_key' => $this->_customer_id,
'session_value' => maybe_serialize( $this->_data ),
'session_expiry' => $this->_session_expiration
),
array( 'session_id' => $session_id ),
array(
'%s',
'%s',
'%d'
),
array( '%d' )
);
} else {
$wpdb->insert(
$this->_table,
array(
'session_key' => $this->_customer_id,
'session_value' => maybe_serialize( $this->_data ),
'session_expiry' => $this->_session_expiration
),
array(
'%s',
'%s',
'%d'
)
);
}
$wpdb->replace(
$this->_table,
array(
'session_key' => $this->_customer_id,
'session_value' => maybe_serialize( $this->_data ),
'session_expiry' => $this->_session_expiration
),
array(
'%s',
'%s',
'%d'
)
);
// Set cache
wp_cache_set( $this->get_cache_prefix() . $this->_customer_id, $this->_data, WC_SESSION_CACHE_GROUP, $this->_session_expiration - time() );