diff --git a/src/oauth/persistence/ZohoOAuthPersistenceByFile.php b/src/oauth/persistence/ZohoOAuthPersistenceByFile.php index bfcb6b99..64472823 100644 --- a/src/oauth/persistence/ZohoOAuthPersistenceByFile.php +++ b/src/oauth/persistence/ZohoOAuthPersistenceByFile.php @@ -22,6 +22,11 @@ public function saveOAuthData($zohoOAuthTokens) try { self::deleteOAuthTokens($zohoOAuthTokens->getUserEmailId()); $content = file_get_contents(self::getTokenPersistencePath()."/zcrm_oauthtokens.txt" ); + + if ($content === false) { + throw new ZohoOAuthException("Can not read tokens file, please check permissions: " . self::getTokenPersistencePath()."/zcrm_oauthtokens.txt"); + } + if ($content == "") { $arr = array(); } else { @@ -29,7 +34,11 @@ public function saveOAuthData($zohoOAuthTokens) } array_push($arr, $zohoOAuthTokens); $serialized = serialize($arr); - file_put_contents(self::getTokenPersistencePath()."/zcrm_oauthtokens.txt",$serialized ); + $result = file_put_contents(self::getTokenPersistencePath()."/zcrm_oauthtokens.txt",$serialized ); + + if ($result === false) { + throw new ZohoOAuthException("Can not write to tokens file, please check permissions: " . self::getTokenPersistencePath()."/zcrm_oauthtokens.txt"); + } } catch (Exception $ex) { Logger::severe("Exception occured while Saving OAuthTokens to file(file::ZohoOAuthPersistenceByFile)({$ex->getMessage()})\n{$ex}"); throw $ex; @@ -40,6 +49,11 @@ public function getOAuthTokens($userEmailId) { try { $serialized = file_get_contents(self::getTokenPersistencePath()."/zcrm_oauthtokens.txt" ); + + if ($serialized === false) { + throw new ZohoOAuthException("Can not read tokens file, please check permissions: " . 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."); }