From 3617c2d1f85bf9bedefa5fe881c81d1fc9570afc Mon Sep 17 00:00:00 2001 From: Denis Oliveira Date: Mon, 9 Dec 2019 15:52:31 -0300 Subject: [PATCH] Add capability to set host address and data base name - small fix on search records to prevent null on param attribute --- src/crm/api/handler/MassEntityAPIHandler.php | 69 ++++++++++---------- src/oauth/ZohoOAuth.php | 42 ++++++------ 2 files changed, 57 insertions(+), 54 deletions(-) diff --git a/src/crm/api/handler/MassEntityAPIHandler.php b/src/crm/api/handler/MassEntityAPIHandler.php index 74288279..998a31e2 100644 --- a/src/crm/api/handler/MassEntityAPIHandler.php +++ b/src/crm/api/handler/MassEntityAPIHandler.php @@ -11,19 +11,19 @@ class MassEntityAPIHandler extends APIHandler { - + private $module = null; - + public function __construct($moduleInstance) { $this->module = $moduleInstance; } - + public static function getInstance($moduleInstance) { return new MassEntityAPIHandler($moduleInstance); } - + public function createRecords($records, $trigger,$lar_id) { if (sizeof($records) > 100) { @@ -49,9 +49,9 @@ public function createRecords($records, $trigger,$lar_id) if ($lar_id !== null) { $requestBodyObj["lar_id"] = $lar_id; } - + $this->requestBody = $requestBodyObj; - + // Fire Request $bulkAPIResponse = APIRequest::getInstance($this)->getBulkAPIResponse(); $createdRecords = array(); @@ -76,7 +76,7 @@ public function createRecords($records, $trigger,$lar_id) throw $e; } } - + public function upsertRecords($records, $trigger,$lar_id,$duplicate_check_fields) { if (sizeof($records) > 100) { @@ -107,7 +107,7 @@ public function upsertRecords($records, $trigger,$lar_id,$duplicate_check_fields $requestBodyObj["lar_id"] = $lar_id; } $this->requestBody = $requestBodyObj; - + // Fire Request $bulkAPIResponse = APIRequest::getInstance($this)->getBulkAPIResponse(); $upsertRecords = array(); @@ -132,7 +132,7 @@ public function upsertRecords($records, $trigger,$lar_id,$duplicate_check_fields throw $e; } } - + public function updateRecords($records, $trigger) { if (sizeof($records) > 100) { @@ -155,9 +155,9 @@ public function updateRecords($records, $trigger) if ($trigger !== null && is_array($trigger)) { $requestBodyObj["trigger"] = $trigger; } - + $this->requestBody = $requestBodyObj; - + // Fire Request $bulkAPIResponse = APIRequest::getInstance($this)->getBulkAPIResponse(); $upsertRecords = array(); @@ -182,7 +182,7 @@ public function updateRecords($records, $trigger) throw $e; } } - + public function deleteRecords($entityIds) { if (sizeof($entityIds) > 100) { @@ -193,11 +193,11 @@ public function deleteRecords($entityIds) $this->requestMethod = APIConstants::REQUEST_METHOD_DELETE; $this->addHeader("Content-Type", "application/json"); $this->addParam("ids", implode(",", $entityIds)); // converts array to string with specified seperator - + // Fire Request $bulkAPIResponse = APIRequest::getInstance($this)->getBulkAPIResponse(); $responses = $bulkAPIResponse->getEntityResponses(); - + foreach ($responses as $entityResIns) { $responseData = $entityResIns->getResponseJSON(); $responseJSON = $responseData["details"]; @@ -210,22 +210,22 @@ public function deleteRecords($entityIds) throw $exception; } } - + public function getAllDeletedRecords($param_map,$header_map) { return self::getDeletedRecords($param_map,$header_map,"all"); } - + public function getRecycleBinRecords($param_map,$header_map) { return self::getDeletedRecords($param_map,$header_map,"recycle"); } - + public function getPermanentlyDeletedRecords($param_map,$header_map) { return self::getDeletedRecords($param_map,$header_map,"permanent"); } - + private function getDeletedRecords($param_map,$header_map,$type) { try { @@ -248,16 +248,16 @@ private function getDeletedRecords($param_map,$header_map,$type) self::setTrashRecordProperties($trashRecordInstance, $trashRecord); array_push($trashRecordList, $trashRecordInstance); } - + $responseInstance->setData($trashRecordList); - + return $responseInstance; } catch (ZCRMException $exception) { APIExceptionHandler::logException($exception); throw $exception; } } - + public function setTrashRecordProperties($trashRecordInstance, $recordProperties) { if ($recordProperties['display_name'] != null) { @@ -275,7 +275,7 @@ public function setTrashRecordProperties($trashRecordInstance, $recordProperties } $trashRecordInstance->setDeletedTime($recordProperties['deleted_time']); } - + public function getRecords($param_map,$header_map) { try { @@ -297,24 +297,25 @@ public function getRecords($param_map,$header_map) EntityAPIHandler::getInstance($recordInstance)->setRecordProperties($record); array_push($recordsList, $recordInstance); } - + $responseInstance->setData($recordsList); - + return $responseInstance; } catch (ZCRMException $exception) { APIExceptionHandler::logException($exception); throw $exception; } } - + public function searchRecords($param_map,$type,$search_value) { try { $this->urlPath = $this->module->getAPIName() . "/search"; $this->requestMethod = APIConstants::REQUEST_METHOD_GET; + $exclusion_array = ["word","phone","email","criteria"]; foreach($exclusion_array as $exclusion){ - if(array_key_exists($exclusion, $param_map)){ + if(!empty($param_map[$exclusion]) && array_key_exists($exclusion, $param_map)){ unset($param_map[$exclusion]); } } @@ -332,16 +333,16 @@ public function searchRecords($param_map,$type,$search_value) EntityAPIHandler::getInstance($recordInstance)->setRecordProperties($record); array_push($recordsList, $recordInstance); } - + $responseInstance->setData($recordsList); - + return $responseInstance; } catch (ZCRMException $exception) { APIExceptionHandler::logException($exception); throw $exception; } } - + public function massUpdateRecords($idList, $apiName, $value) { if (sizeof($idList) > 100) { @@ -355,7 +356,7 @@ public function massUpdateRecords($idList, $apiName, $value) $this->requestBody = $inputJSON; $this->apiKey = 'data'; $bulkAPIResponse = APIRequest::getInstance($this)->getBulkAPIResponse(); - + $updatedRecords = array(); $responses = $bulkAPIResponse->getEntityResponses(); $size = sizeof($responses); @@ -364,7 +365,7 @@ public function massUpdateRecords($idList, $apiName, $value) if (APIConstants::STATUS_SUCCESS === $entityResIns->getStatus()) { $responseData = $entityResIns->getResponseJSON(); $recordJSON = $responseData["details"]; - + $updatedRecord = ZCRMRecord::getInstance($this->module->getAPIName(), $recordJSON["id"]); EntityAPIHandler::getInstance($updatedRecord)->setRecordProperties($recordJSON); array_push($updatedRecords, $updatedRecord); @@ -374,14 +375,14 @@ public function massUpdateRecords($idList, $apiName, $value) } } $bulkAPIResponse->setData($updatedRecords); - + return $bulkAPIResponse; } catch (ZCRMException $exception) { APIExceptionHandler::logException($exception); throw $exception; } } - + public function constructJSONForMassUpdate($idList, $apiName, $value) { $massUpdateArray = array(); @@ -391,7 +392,7 @@ public function constructJSONForMassUpdate($idList, $apiName, $value) $updateJson[$apiName] = $value; array_push($massUpdateArray, $updateJson); } - + return array( "data" => $massUpdateArray ); diff --git a/src/oauth/ZohoOAuth.php b/src/oauth/ZohoOAuth.php index 64652fc7..41fb3416 100644 --- a/src/oauth/ZohoOAuth.php +++ b/src/oauth/ZohoOAuth.php @@ -10,9 +10,9 @@ class ZohoOAuth { - + private static $configProperties = array(); - + public static function initialize($configuration) { self::setConfigValues($configuration); @@ -40,7 +40,7 @@ public static function initialize($configuration) $oAuthParams->setRedirectURL(self::getConfigValue(ZohoOAuthConstants::REDIRECT_URL)); ZohoOAuthClient::getInstance($oAuthParams); } - + private static function setConfigValues($configuration) { $config_keys = array( @@ -51,12 +51,14 @@ private static function setConfigValues($configuration) ZohoOAuthConstants::PERSISTENCE_HANDLER_CLASS, ZohoOAuthConstants::IAM_URL, ZohoOAuthConstants::TOKEN_PERSISTENCE_PATH, + ZohoOAuthConstants::HOST_ADDRESS, + ZohoOAuthConstants::DATABASE_NAME, ZohoOAuthConstants::DATABASE_PORT, ZohoOAuthConstants::DATABASE_PASSWORD, ZohoOAuthConstants::DATABASE_USERNAME, ZohoOAuthConstants::PERSISTENCE_HANDLER_CLASS_NAME ); - + if (! array_key_exists(ZohoOAuthConstants::ACCESS_TYPE, $configuration) || $configuration[ZohoOAuthConstants::ACCESS_TYPE] == "") { self::$configProperties[ZohoOAuthConstants::ACCESS_TYPE] = "offline"; } @@ -66,73 +68,73 @@ private static function setConfigValues($configuration) if (! array_key_exists(ZohoOAuthConstants::IAM_URL, $configuration) || $configuration[ZohoOAuthConstants::IAM_URL] == "") { self::$configProperties[ZohoOAuthConstants::IAM_URL] = "https://accounts.zoho.com"; } - + foreach ($config_keys as $key) { if (array_key_exists($key, $configuration)) self::$configProperties[$key] = $configuration[$key]; } } - + public static function getConfigValue($key) { return isset(self::$configProperties[$key])?self::$configProperties[$key]:""; } - + public static function getAllConfigs() { return self::$configProperties; } - + public static function getIAMUrl() { return self::getConfigValue(ZohoOAuthConstants::IAM_URL); } - + public static function getGrantURL() { return self::getIAMUrl() . "/oauth/v2/auth"; } - + public static function getTokenURL() { return self::getIAMUrl() . "/oauth/v2/token"; } - + public static function getRefreshTokenURL() { return self::getIAMUrl() . "/oauth/v2/token"; } - + public static function getRevokeTokenURL() { return self::getIAMUrl() . "/oauth/v2/token/revoke"; } - + public static function getUserInfoURL() { return self::getIAMUrl() . "/oauth/user/info"; } - + public static function getClientID() { return self::getConfigValue(ZohoOAuthConstants::CLIENT_ID); } - + public static function getClientSecret() { return self::getConfigValue(ZohoOAuthConstants::CLIENT_SECRET); } - + public static function getRedirectURL() { return self::getConfigValue(ZohoOAuthConstants::REDIRECT_URL); } - + public static function getAccessType() { return self::getConfigValue(ZohoOAuthConstants::ACCESS_TYPE); } - + public static function getPersistenceHandlerInstance() { try { @@ -151,12 +153,12 @@ public static function getPersistenceHandlerInstance() throw new ZohoOAuthException($ex); } } - + public static function getClientInstance() { if (ZohoOAuthClient::getInstanceWithOutParam() == null) { throw new ZohoOAuthException("ZCRMRestClient::initialize(\$configMap) must be called before this."); - + } return ZohoOAuthClient::getInstanceWithOutParam(); }