← All changes
|
backend/src/Controllers/Settings/UpdateSettingController.php
+19
-7
0.5
→
1.5
View file →
| @@ -1,18 +1,13 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | - * @copyright © TMS-Plugins. All rights reserved. | |
| 4 | + * @copyright © Melograno Venture Studio. All rights reserved. | |
| 5 | 5 | * @licence See COPYING.md for license details. |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | namespace IvyForms\Controllers\Settings; |
| 9 | 9 | |
| 10 | -// phpcs:disable PSR1.Files.SideEffects | |
| 11 | -if (!defined('ABSPATH')) { | |
| 12 | - exit; // Exit if accessed directly | |
| 13 | -} | |
| 14 | - | |
| 15 | 10 | use IvyForms\Common\Exceptions\ForbiddenException; |
| 16 | 11 | use IvyForms\Common\Exceptions\InvalidArgumentException; |
| 17 | 12 | use IvyForms\Common\Sanitizer\Sanitizer; |
| 18 | 13 | use IvyForms\Controllers\Controller; |
| @@ -17,8 +12,9 @@ | ||
| 17 | 12 | use IvyForms\Common\Sanitizer\Sanitizer; |
| 18 | 13 | use IvyForms\Controllers\Controller; |
| 19 | 14 | use IvyForms\Services\Settings\SettingsService; |
| 20 | 15 | use IvyForms\Services\Translations\BackendStrings; |
| 16 | +use IvyForms\Services\Usage\UsageTrackingService; | |
| 21 | 17 | use WP_REST_Request; |
| 22 | 18 | use WP_REST_Response; |
| 23 | 19 | |
| 24 | 20 | /** |
| @@ -28,13 +24,16 @@ | ||
| 28 | 24 | */ |
| 29 | 25 | class UpdateSettingController extends Controller |
| 30 | 26 | { |
| 31 | 27 | private SettingsService $settingsService; |
| 28 | + private UsageTrackingService $usageTrackingService; | |
| 32 | 29 | |
| 33 | 30 | public function __construct( |
| 34 | - SettingsService $settingsService | |
| 31 | + SettingsService $settingsService, | |
| 32 | + UsageTrackingService $usageTrackingService | |
| 35 | 33 | ) { |
| 36 | 34 | $this->settingsService = $settingsService; |
| 35 | + $this->usageTrackingService = $usageTrackingService; | |
| 37 | 36 | } |
| 38 | 37 | |
| 39 | 38 | /** |
| 40 | 39 | * @param WP_REST_Request $data |
| @@ -63,8 +62,21 @@ | ||
| 63 | 62 | if (empty($settingsCategory) || empty($settingsOption)) { |
| 64 | 63 | throw new InvalidArgumentException( |
| 65 | 64 | BackendStrings::getSettingsStrings()['settings_category_or_option_missing'] |
| 66 | 65 | ); |
| 66 | + } | |
| 67 | + | |
| 68 | + if ($settingsCategory === 'general' && $settingsOption === 'usageTrackingEnabled') { | |
| 69 | + $updatedSettings = $this->usageTrackingService->updateSettings([ | |
| 70 | + 'usageTrackingEnabled' => (bool) $settingsValue, | |
| 71 | + ]); | |
| 72 | + | |
| 73 | + return new WP_REST_Response([ | |
| 74 | + 'message' => BackendStrings::getSettingsStrings()['settings_option_updated'], | |
| 75 | + 'data' => [ | |
| 76 | + 'value' => $updatedSettings['usageTrackingEnabled'], | |
| 77 | + ], | |
| 78 | + ], 200); | |
| 67 | 79 | } |
| 68 | 80 | |
| 69 | 81 | // Update the setting |
| 70 | 82 | $this->settingsService->setSetting($settingsCategory, $settingsOption, $settingsValue); |