← All changes
|
Inc/Framework/Inc/Base/Integrations/ActiveCampaign.php
+34
-12
3.1.8
→
3.1.14
View file →
| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * @package FirePlugins Framework |
| 4 | - * @version 1.1.146 | |
| 4 | + * @version 1.2.6 | |
| 5 | 5 | * |
| 6 | 6 | * @author FirePlugins <[email protected]> |
| 7 | 7 | * @link https://www.fireplugins.com |
| 8 | 8 | * @copyright Copyright © 2026 FirePlugins All Rights Reserved |
| @@ -179,9 +179,9 @@ | ||
| 179 | 179 | |
| 180 | 180 | $body = isset($this->last_response['body']) ? $this->last_response['body'] : []; |
| 181 | 181 | if (!is_array($body)) |
| 182 | 182 | { |
| 183 | - return ''; | |
| 183 | + return $this->getHttpStatusError(); | |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | if (!empty($body['message'])) |
| 187 | 187 | { |
| @@ -214,9 +214,9 @@ | ||
| 214 | 214 | return trim((string) $body['errors']); |
| 215 | 215 | } |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | - return ''; | |
| 218 | + return $this->getHttpStatusError(); | |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | /** |
| 222 | 222 | * Parse raw credential value into endpoint + key. |
| @@ -332,26 +332,27 @@ | ||
| 332 | 332 | return false; |
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | /** |
| 336 | - * Sync custom fields by field title/perstag. | |
| 336 | + * Return the field title/perstag => id map for this account, cached in a transient | |
| 337 | + * to avoid re-fetching the entire field catalog on every submission. | |
| 337 | 338 | * |
| 338 | - * @param string $contact_id | |
| 339 | - * @param array $params | |
| 340 | - * | |
| 341 | - * @return void | |
| 339 | + * @return array | |
| 342 | 340 | */ |
| 343 | - private function syncContactFields($contact_id, $params = []) | |
| 341 | + private function getFieldMap() | |
| 344 | 342 | { |
| 345 | - if (!$contact_id || !is_array($params) || empty($params)) | |
| 343 | + $cache_key = 'fpf_ac_fields_' . md5($this->endpoint); | |
| 344 | + | |
| 345 | + $field_map = get_transient($cache_key); | |
| 346 | + if (is_array($field_map)) | |
| 346 | 347 | { |
| 347 | - return; | |
| 348 | + return $field_map; | |
| 348 | 349 | } |
| 349 | 350 | |
| 350 | 351 | $fields_response = $this->get('fields', ['limit' => 200, 'offset' => 0]); |
| 351 | 352 | if (!$this->success() || !is_array($fields_response) || empty($fields_response['fields']) || !is_array($fields_response['fields'])) |
| 352 | 353 | { |
| 353 | - return; | |
| 354 | + return []; | |
| 354 | 355 | } |
| 355 | 356 | |
| 356 | 357 | $field_map = []; |
| 357 | 358 | foreach ($fields_response['fields'] as $field) |
| @@ -379,8 +380,29 @@ | ||
| 379 | 380 | $field_map[$perstag] = $id; |
| 380 | 381 | } |
| 381 | 382 | } |
| 382 | 383 | |
| 384 | + set_transient($cache_key, $field_map, HOUR_IN_SECONDS); | |
| 385 | + | |
| 386 | + return $field_map; | |
| 387 | + } | |
| 388 | + | |
| 389 | + /** | |
| 390 | + * Sync custom fields by field title/perstag. | |
| 391 | + * | |
| 392 | + * @param string $contact_id | |
| 393 | + * @param array $params | |
| 394 | + * | |
| 395 | + * @return void | |
| 396 | + */ | |
| 397 | + private function syncContactFields($contact_id, $params = []) | |
| 398 | + { | |
| 399 | + if (!$contact_id || !is_array($params) || empty($params)) | |
| 400 | + { | |
| 401 | + return; | |
| 402 | + } | |
| 403 | + | |
| 404 | + $field_map = $this->getFieldMap(); | |
| 383 | 405 | if (empty($field_map)) |
| 384 | 406 | { |
| 385 | 407 | return; |
| 386 | 408 | } |