| 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 |
$returnData = $globalIntegrationService->get($this->request->all()); |
| 16 |
if (Arr::isTrue($returnData, 'status')) { |
| 17 |
return $this->sendSuccess($returnData); |
| 18 |
} |
| 19 |
return $this->sendError($returnData); |
| 20 |
} catch (Exception $e) { |
| 21 |
return $this->sendError([ |
| 22 |
'message' => $e->getMessage(), |
| 23 |
], 422); |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
public function updateIntegration() |
| 28 |
{ |
| 29 |
try { |
| 30 |
$settingsKey = sanitize_text_field($this->request->get('settings_key')); |
| 31 |
$integration = wp_unslash($this->request->get('integration')); |
| 32 |
|
| 33 |
do_action_deprecated( |
| 34 |
'fluentform_save_global_integration_settings_' . $settingsKey, |
| 35 |
[ |
| 36 |
$integration |
| 37 |
], |
| 38 |
FLUENTFORM_FRAMEWORK_UPGRADE, |
| 39 |
'fluentform/save_global_integration_settings_' . $settingsKey, |
| 40 |
'Use fluentform/save_global_integration_settings_' . $settingsKey . ' instead of fluentform_save_global_integration_settings_' . $settingsKey |
| 41 |
); |
| 42 |
|
| 43 |
do_action('fluentform/save_global_integration_settings_' . $settingsKey, $integration); |
| 44 |
|
| 45 |
// Someone should catch that above action and send response |
| 46 |
return $this->sendError([ |
| 47 |
'message' => __('Sorry, no Integration found. Please make sure that latest version of Fluent Forms pro installed', |
| 48 |
'fluentform'), |
| 49 |
]); |
| 50 |
} catch (Exception $e) { |
| 51 |
return $this->sendError([ |
| 52 |
'message' => $e->getMessage(), |
| 53 |
], 422); |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
public function updateModuleStatus(GlobalIntegrationService $globalIntegrationService) |
| 58 |
{ |
| 59 |
try { |
| 60 |
$globalIntegrationService->updateModuleStatus($this->request->get()); |
| 61 |
return $this->sendSuccess([ |
| 62 |
'message' => __('Status successfully updated', 'fluentform'), |
| 63 |
], 200); |
| 64 |
} catch (Exception $e) { |
| 65 |
return $this->sendError([ |
| 66 |
'message' => $e->getMessage(), |
| 67 |
], 422); |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
} |
| 74 |
|