Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept table name parameter on DBStore #12

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
@@ -1,7 +1,7 @@
{
"name" : "zohocrm/php-sdk",
"description" : "Zoho CRM API SDK for PHP",
"type" : "SDK",
"type" : "sdk",
"homepage": "https://github.com/zoho/zohocrm-php-sdk",
"authors" : [
{
Expand All @@ -24,4 +24,4 @@
"" : "src/"
}
}
}
}
32 changes: 18 additions & 14 deletions src/com/zoho/api/authenticator/store/DBStore.php
Expand Up @@ -28,7 +28,9 @@ class DBStore implements TokenStore
private $host = null;

private $databaseName = null;


private $tableName = null;

/**
* Create an DBStore class instance with the specified parameters.
* @param string $host A string containing the DataBase host name.
Expand All @@ -37,7 +39,7 @@ class DBStore implements TokenStore
* @param string $password A String containing the DataBase password.
* @param string $portNumber A String containing the DataBase port number.
*/
public function __construct($host = null, $databaseName = null, $userName = null, $password = null, $portNumber = null)
public function __construct($host = null, $databaseName = null, $userName = null, $password = null, $portNumber = null, $tableName = null)
{
$this->host = $host != null ? $host : Constants::MYSQL_HOST;

Expand All @@ -48,6 +50,8 @@ public function __construct($host = null, $databaseName = null, $userName = null
$this->password = $password != null ? $password : "";

$this->portNumber = $portNumber != null ? $portNumber : Constants::MYSQL_PORT_NUMBER;

$this->tableName = $tableName != null ? $tableName : Constants::MYSQL_TABLE_NAME;
}

public function getToken($user, $token)
Expand Down Expand Up @@ -107,9 +111,9 @@ public function saveToken($user, $token)
$this->deleteToken($token);

$connection = $this->getMysqlConnection();
$query = "INSERT INTO oauthtoken(user_mail,client_id,refresh_token,access_token,grant_token,expiry_time) VALUES(?,?,?,?,?,?)";

$query = "INSERT INTO " . $this->tableName . "(user_mail,client_id,refresh_token,access_token,grant_token,expiry_time) VALUES(?,?,?,?,?,?)";

$stmt = mysqli_prepare($connection, $query);

$email = $user->getEmail();
Expand Down Expand Up @@ -209,8 +213,8 @@ public function getTokens()
$connection = $this->getMysqlConnection();

{
$query = "select * from oauthtoken;";
$query = "select * from " . $this->tableName . ";";

$result = mysqli_query($connection, $query);

if ($result)
Expand Down Expand Up @@ -260,9 +264,9 @@ public function deleteTokens()
try
{
$connection = $this->getMysqlConnection();
$query = "delete from oauthtoken";

$query = "delete from " . $this->tableName;

mysqli_query($connection, $query);

}
Expand All @@ -287,8 +291,8 @@ private function constructDBQuery($email, $token, $is_delete=true)

}
$query = $is_delete ? "delete from " : "select * from ";
$query .= "oauthtoken where user_mail='" . $email. "' and client_id='" . $token->getClientId() . "' and ";

$query .= $this->tableName . " where user_mail='" . $email. "' and client_id='" . $token->getClientId() . "' and ";

if ($token->getGrantToken() != null)
{
Expand All @@ -298,7 +302,7 @@ private function constructDBQuery($email, $token, $is_delete=true)
{
$query .= "refresh_token='" . $token->getRefreshToken() . "'";
}

return $query;
}
}
}
4 changes: 3 additions & 1 deletion src/com/zoho/crm/api/util/Constants.php
Expand Up @@ -210,6 +210,8 @@ class Constants

const MYSQL_DATABASE_NAME = "zohooauth";

const MYSQL_TABLE_NAME = 'oauthtoken';

const MYSQL_USER_NAME = "root";

const MYSQL_PORT_NUMBER = "3306";
Expand Down Expand Up @@ -636,4 +638,4 @@ class Constants

const INVALID_MODULE = "INVALID_MODULE";
}
?>
?>