Skip to content
Snippets Groups Projects
Commit ed18a41b authored by Rosemary Reilman's avatar Rosemary Reilman
Browse files

Issue #3432136 by fractile81: Delay getConfig() Calls in ConstantContact.php

parent 94535f04
No related branches found
No related tags found
No related merge requests found
......@@ -340,8 +340,6 @@ class ConstantContact {
* @see https://v3.developer.constantcontact.com/api_reference/index.html#!/Contacts/createContact
*/
private function createContact(array $data, $listIDs) {
$config = $this->getConfig();
$body = (object) [
'email_address' => (object) [
'address' => NULL,
......@@ -364,6 +362,10 @@ class ConstantContact {
$this->moduleHandler->invokeAll('ik_constant_contact_contact_data_alter', [$data, &$body]);
$this->moduleHandler->invokeAll('ik_constant_contact_contact_create_data_alter', [$data, &$body]);
// Waiting to pull the configuration until now in case the refreshToken()
// call changes the active tokens.
$config = $this->getConfig();
try {
$response = $this->httpClient->request('POST', $config['contact_url'], [
'headers' => [
......@@ -604,7 +606,6 @@ class ConstantContact {
*
*/
public function getContactLists($cached = true) {
$config = $this->getConfig();
$cid = 'ik_constant_contact.lists';
$cache = ($cached === true ? $this->cache->get($cid) : null);
......@@ -615,6 +616,10 @@ class ConstantContact {
// Update access tokens.
$this->refreshToken(false);
// Waiting to pull the configuration until now in case the refreshToken()
// call changes the active tokens.
$config = $this->getConfig();
if (isset($config['access_token'])) {
try {
$response = $this->httpClient->request('GET', $config['contact_lists_url'], [
......@@ -999,8 +1004,6 @@ class ConstantContact {
* an array here and an object in updateContact.
*/
private function putContact(array $contact, array $data, $listIDs) {
$config = $this->getConfig();
$body = (object) $contact;
$body = $this->buildResponseBody($data, $body);
......@@ -1014,6 +1017,10 @@ class ConstantContact {
$this->moduleHandler->invokeAll('ik_constant_contact_contact_data_alter', [$data, &$body]);
$this->moduleHandler->invokeAll('ik_constant_contact_contact_update_data_alter', [$data, &$body]);
// Waiting to pull the config until now so that any config changes can take
// immediate effect.
$config = $this->getConfig();
try {
$response = $this->httpClient->request('PUT', $config['contact_url'] . '/' . $contact['contact_id'], [
'headers' => [
......@@ -1225,6 +1232,10 @@ class ConstantContact {
$this->moduleHandler->invokeAll('ik_constant_contact_contact_data_alter', [$data, &$body]);
$this->moduleHandler->invokeAll('ik_constant_contact_contact_form_submission_alter', [$data, &$body]);
// Pulling the config again so that any config changes can take immediate
// effect.
$config = $this->getConfig();
try {
$response = $this->httpClient->request('POST', $config['contact_url'] . '/sign_up_form', [
'headers' => [
......@@ -1267,7 +1278,6 @@ class ConstantContact {
*
*/
public function unsubscribeContact(array $data) {
$config = $this->getConfig();
// Check if contact already exists.
$exists = (array) $this->getContact($data);
$body = null;
......@@ -1291,6 +1301,10 @@ class ConstantContact {
$this->moduleHandler->invokeAll('ik_constant_contact_contact_data_alter', [$data, &$body]);
$this->moduleHandler->invokeAll('ik_constant_contact_contact_unsubscribe_data_alter', [$data, &$body]);
// Waiting to pull the config until now so that any config changes can take
// immediate effect.
$config = $this->getConfig();
try {
$response = $this->httpClient->request('PUT', $config['contact_url'] . '/' . $exists->contact_id, [
'headers' => [
......@@ -1335,8 +1349,6 @@ class ConstantContact {
* @see https://v3.developer.constantcontact.com/api_reference/index.html#!/Contacts/putContact
*/
private function updateContact(array $data, $contact, $listIDs) {
$config = $this->getConfig();
if ($contact && property_exists($contact, 'contact_id')) {
$body = $contact;
......@@ -1351,6 +1363,10 @@ class ConstantContact {
$this->moduleHandler->invokeAll('ik_constant_contact_contact_data_alter', [$data, &$body]);
$this->moduleHandler->invokeAll('ik_constant_contact_contact_update_data_alter', [$data, &$body]);
// Waiting to pull the config until now so that any config changes can take
// immediate effect.
$config = $this->getConfig();
try {
$response = $this->httpClient->request('PUT', $config['contact_url'] . '/' . $contact->contact_id, [
'headers' => [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment