| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentForm\App\Http\Controllers; |
| 4 |
|
| 5 |
use FluentForm\App\Services\Integrations\GlobalIntegrationService; |
| 6 |
use FluentForm\Framework\Helpers\ArrayHelper as Arr; |
| 7 |
use Exception; |
| 8 |
|
| 9 |
class GlobalIntegrationController extends Controller |
| 10 |
{ |
| 11 |
|
| 12 |
public function index(GlobalIntegrationService $globalIntegrationService) |
| 13 |
{ |
| 14 |
try { |
| 15 |
$attributes = $this->request->all(); |
| 16 |
$returnData = $globalIntegrationService->get($attributes); |
| 17 |
if (Arr::isTrue($returnData, 'status')) { |
| 18 |
return $this->sendSuccess($returnData); |
| 19 |
} |
| 20 |
// No settings_key provided is a list-style call, not an error; return 200 with empty payload. |
| 21 |
if (!Arr::get($attributes, 'settings_key')) { |
| 22 |
return $this->sendSuccess([ |
| 23 |
'status' => false, |
| 24 |
'integration' => [], |
| 25 |
'settings' => [], |
| 26 |
]); |
| 27 |
} |
| 28 |
return $this->sendError($returnData); |
| 29 |
} catch (Exception $e) { |
| 30 |
return $this->sendError([ |
| 31 |
'message' => $e->getMessage(), |
| 32 |
], 422); |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
public function updateIntegration() |
| 37 |
{ |
| 38 |
try { |
| 39 |
$settingsKey = sanitize_text_field($this->request->get('settings_key')); |
| 40 |
$integration = wp_unslash($this->request->get('integration')); |
| 41 |
|
| 42 |
do_action_deprecated( |
| 43 |
'fluentform_save_global_integration_settings_' . $settingsKey, |
| 44 |
[ |
| 45 |
$integration |
| 46 |
], |
| 47 |
FLUENTFORM_FRAMEWORK_UPGRADE, |
| 48 |
'fluentform/save_global_integration_settings_' . $settingsKey, |
| 49 |
'Use fluentform/save_global_integration_settings_' . $settingsKey . ' instead of fluentform_save_global_integration_settings_' . $settingsKey |
| 50 |
); |
| 51 |
|
| 52 |
do_action('fluentform/save_global_integration_settings_' . $settingsKey, $integration); |
| 53 |
|
| 54 |
// Someone should catch that above action and send response |
| 55 |
return $this->sendError([ |
| 56 |
'message' => __('Sorry, no Integration found. Please make sure that latest version of Fluent Forms pro installed', |
| 57 |
'fluentform'), |
| 58 |
]); |
| 59 |
} catch (Exception $e) { |
| 60 |
return $this->sendError([ |
| 61 |
'message' => $e->getMessage(), |
| 62 |
], 422); |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
public function updateModuleStatus(GlobalIntegrationService $globalIntegrationService) |
| 67 |
{ |
| 68 |
try { |
| 69 |
$globalIntegrationService->updateModuleStatus($this->request->get()); |
| 70 |
return $this->sendSuccess([ |
| 71 |
'message' => __('Status successfully updated', 'fluentform'), |
| 72 |
], 200); |
| 73 |
} catch (Exception $e) { |
| 74 |
return $this->sendError([ |
| 75 |
'message' => $e->getMessage(), |
| 76 |
], 422); |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
} |
| 83 |
|