cache api call object

This commit is contained in:
Marc Michalsky forumZFD 2021-01-18 10:46:13 +01:00
parent 36cfdd2a2d
commit 1d5c69f470
Signed by untrusted user who does not match committer: marc.koch
GPG key ID: 12406554CFB028B9
3 changed files with 14 additions and 1 deletions

View file

@ -41,6 +41,9 @@ class CRM_TwingleCampaign_BAO_TwingleApiCall {
curl_close($curl); curl_close($curl);
if (empty($response)) { if (empty($response)) {
// Delete api key from cache
Civi::cache()->delete('twinglecampaign_twingle_api');
// Throw exception
throw new API_Exception( throw new API_Exception(
"Twingle API call failed. Please check your api key."); "Twingle API call failed. Please check your api key.");
} }

View file

@ -53,6 +53,11 @@ class CRM_TwingleCampaign_Form_Settings extends CRM_Core_Form {
//TODO: validate Twingle API key //TODO: validate Twingle API key
public function postProcess() { public function postProcess() {
// Delete api key from cache
Civi::cache()->delete('twinglecampaign_twingle_api');
// Set configuration values
Configuration::set($this->exportValues()); Configuration::set($this->exportValues());
parent::postProcess(); parent::postProcess();
} }

View file

@ -77,7 +77,12 @@ function civicrm_api3_twingle_sync_Sync($params) {
: trim($params['twingle_api_key']); : trim($params['twingle_api_key']);
// If function call does not provide a limit, set a default value // If function call does not provide a limit, set a default value
$limit = ($params['limit']) ?? 20; $limit = ($params['limit']) ?? 20;
$twingleApi = new TwingleApiCall($apiKey, $limit);
// Try to retrieve twingleApi from cache
$twingleApi = Civi::cache()->get('twinglecampaign_twingle_api');
if (NULL === $twingleApi) {
$twingleApi = new TwingleApiCall($apiKey, $limit);
}
if ($params['id'] && !$params['project_id']) { if ($params['id'] && !$params['project_id']) {
// Get single TwingleProject // Get single TwingleProject