Skip to content

Commit

Permalink
include path removed, default log location changed
Browse files Browse the repository at this point in the history
  • Loading branch information
pravesh-a committed Nov 26, 2019
1 parent b92c7ef commit 2c80249
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
5 changes: 2 additions & 3 deletions src/crm/utility/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ class Logger

public static function writeToFile($msg)
{
set_include_path(ZCRMConfigUtil::getConfigValue(APIConstants::APPLICATION_LOGFILE_PATH));
$path = get_include_path();
$path = trim(ZCRMConfigUtil::getConfigValue(APIConstants::APPLICATION_LOGFILE_PATH));
if (!ZCRMConfigUtil::getConfigValue(APIConstants::APPLICATION_LOGFILE_PATH)) {
$path=dirname(__FILE__) ."/../../..";
$path=posix_getpwuid(posix_getuid())["dir"];
}
$filePointer = fopen($path . APIConstants::APPLICATION_LOGFILE_NAME, "a");
if (! $filePointer) {
Expand Down
17 changes: 7 additions & 10 deletions src/oauth/persistence/ZohoOAuthPersistenceByFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,26 @@
class ZohoOAuthPersistenceByFile implements ZohoOAuthPersistenceInterface
{

public function setIncludePath()
public function getTokenPersistencePath()
{
$path = ZohoOAuth::getConfigValue('token_persistence_path');
$path = trim($path);
set_include_path($path);
return $path;
}

public function saveOAuthData($zohoOAuthTokens)
{
try {
self::deleteOAuthTokens($zohoOAuthTokens->getUserEmailId());
self::setIncludePath();
$content = file_get_contents("zcrm_oauthtokens.txt", FILE_USE_INCLUDE_PATH);
$content = file_get_contents(self::getTokenPersistencePath()."/zcrm_oauthtokens.txt" );
if ($content == "") {
$arr = array();
} else {
$arr = unserialize($content);
}
array_push($arr, $zohoOAuthTokens);
$serialized = serialize($arr);
file_put_contents("zcrm_oauthtokens.txt", $serialized, FILE_USE_INCLUDE_PATH);
file_put_contents(self::getTokenPersistencePath()."/zcrm_oauthtokens.txt",$serialized );
} catch (Exception $ex) {
Logger::severe("Exception occured while Saving OAuthTokens to file(file::ZohoOAuthPersistenceByFile)({$ex->getMessage()})\n{$ex}");
throw $ex;
Expand All @@ -40,8 +39,7 @@ public function saveOAuthData($zohoOAuthTokens)
public function getOAuthTokens($userEmailId)
{
try {
self::setIncludePath();
$serialized = file_get_contents("zcrm_oauthtokens.txt", FILE_USE_INCLUDE_PATH);
$serialized = file_get_contents(self::getTokenPersistencePath()."/zcrm_oauthtokens.txt" );
if (! isset($serialized) || $serialized == "") {
throw new ZohoOAuthException("No Tokens exist for the given user-identifier,Please generate and try again.");
}
Expand Down Expand Up @@ -71,8 +69,7 @@ public function getOAuthTokens($userEmailId)
public function deleteOAuthTokens($userEmailId)
{
try {
self::setIncludePath();
$serialized = file_get_contents("zcrm_oauthtokens.txt", FILE_USE_INCLUDE_PATH);
$serialized = file_get_contents(self::getTokenPersistencePath()."/zcrm_oauthtokens.txt" );
if (! isset($serialized) || $serialized == "") {
return;
}
Expand All @@ -90,7 +87,7 @@ public function deleteOAuthTokens($userEmailId)
$arr = array_values(array_filter($arr));
}
$serialized = serialize($arr);
file_put_contents("zcrm_oauthtokens.txt", $serialized, FILE_USE_INCLUDE_PATH);
file_put_contents(self::getTokenPersistencePath()."/zcrm_oauthtokens.txt",$serialized );
} catch (Exception $ex) {
Logger::severe("Exception occured while Saving OAuthTokens to file(file::ZohoOAuthPersistenceByFile)({$ex->getMessage()})\n{$ex}");
throw $ex;
Expand Down

0 comments on commit 2c80249

Please sign in to comment.