diff --git "a/C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\TortoiseGit\\tokA1D1.tmp\\token_storage-c58bf86-left.php" "b/D:\\work\\freyad-forum-rhcloud\\public\\phpbb\\auth\\provider\\oauth\\token_storage.php" index 9b6afae2..cda9316 100644 --- "a/C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\TortoiseGit\\tokA1D1.tmp\\token_storage-c58bf86-left.php" +++ "b/D:\\work\\freyad-forum-rhcloud\\public\\phpbb\\auth\\provider\\oauth\\token_storage.php" @@ -98,15 +98,34 @@ class token_storage implements TokenStorageInterface $this->cachedToken = $token; $data = array( - 'user_id' => (int) $this->user->data['user_id'], - 'provider' => $service, 'oauth_token' => $this->json_encode_token($token), - 'session_id' => $this->user->data['session_id'], ); - $sql = 'INSERT INTO ' . $this->auth_provider_oauth_table . ' - ' . $this->db->sql_build_array('INSERT', $data); + $updated = false; + $sql = 'UPDATE ' . $this->auth_provider_oauth_table . ' + SET ' . $this->db->sql_build_array('UPDATE', $data) . ' + WHERE user_id = ' . (int) $this->user->data['user_id'] . ' + ' . ((int) $this->user->data['user_id'] === ANONYMOUS ? "AND session_id = '" . $this->db->sql_escape($this->user->data['session_id']) . "'" : '') . " + AND provider = '" . $this->db->sql_escape($service) . "'"; + $this->db->sql_query($sql); + + $updated = $this->db->sql_affectedrows() > 0; + + if (!$updated) + { + $data = array( + 'user_id' => (int) $this->user->data['user_id'], + 'provider' => $service, + 'oauth_token' => $this->json_encode_token($token), + 'session_id' => $this->user->data['session_id'], + ); + + $sql = 'INSERT INTO ' . $this->auth_provider_oauth_table . ' + ' . $this->db->sql_build_array('INSERT', $data); + + $this->db->sql_query($sql); + } } /**