[feature/oauth] Consolidate repeated query into one function

PHPBB3-11673
This commit is contained in:
Joseph Warner 2013-07-30 14:08:13 -04:00
parent e53ebb1b68
commit bf9d4e0cdf

View file

@ -141,14 +141,7 @@ class phpbb_auth_provider_oauth_token_storage implements TokenStorageInterface
$data['session_id'] = $this->user->data['session_id']; $data['session_id'] = $this->user->data['session_id'];
} }
$row = $this->_has_acess_token($data); return $this->_has_acess_token($data);
if (!$row)
{
return false;
}
return true;
} }
/** /**
@ -207,7 +200,18 @@ class phpbb_auth_provider_oauth_token_storage implements TokenStorageInterface
'provider' => $this->service_name, 'provider' => $this->service_name,
); );
$row = $this->_has_acess_token($data); return $this->_has_acess_token($data);
}
/**
* A helper function that performs the query for has access token functions
*
* @param array $data
* @return bool
*/
protected function _has_acess_token($data)
{
$row = $this->get_access_token_row($data);
if (!$row) if (!$row)
{ {
@ -217,23 +221,6 @@ class phpbb_auth_provider_oauth_token_storage implements TokenStorageInterface
return true; return true;
} }
/**
* A helper function that performs the query for has access token functions
*
* @param array $data
* @return mixed
*/
protected function _has_acess_token($data)
{
$sql = 'SELECT oauth_token FROM ' . $this->auth_provider_oauth_table . '
WHERE ' . $this->db->sql_build_array('SELECT', $data);
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
return $row;
}
public function retrieve_access_token_by_session() public function retrieve_access_token_by_session()
{ {
if( $this->cachedToken instanceOf TokenInterface ) { if( $this->cachedToken instanceOf TokenInterface ) {
@ -257,11 +244,7 @@ class phpbb_auth_provider_oauth_token_storage implements TokenStorageInterface
*/ */
protected function _retrieve_access_token($data) protected function _retrieve_access_token($data)
{ {
$sql = 'SELECT oauth_token FROM ' . $this->auth_provider_oauth_table . ' $row = $this->get_access_token_row($data);
WHERE ' . $this->db->sql_build_array('SELECT', $data);
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
if (!$row) if (!$row)
{ {
@ -282,4 +265,21 @@ class phpbb_auth_provider_oauth_token_storage implements TokenStorageInterface
$this->cachedToken = $token; $this->cachedToken = $token;
return $token; return $token;
} }
/**
* A helper function that performs the query for retrieving an access token
*
* @param array $data
* @return mixed
*/
protected function get_access_token_row($data)
{
$sql = 'SELECT oauth_token FROM ' . $this->auth_provider_oauth_table . '
WHERE ' . $this->db->sql_build_array('SELECT', $data);
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
return $row;
}
} }