FeaturesIntegrations
6 months ago
GetSettingsCommand.php
1 year ago
GetSettingsCommandHandler.php
6 months ago
UpdateSettingsCategoriesCommand.php
6 months ago
UpdateSettingsCategoriesCommandHandler.php
6 months ago
UpdateSettingsCommand.php
1 year ago
UpdateSettingsCommandHandler.php
6 months ago
GetSettingsCommandHandler.php
76 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AmeliaBooking\Application\Commands\Settings; |
| 4 | |
| 5 | use AmeliaBooking\Application\Commands\CommandHandler; |
| 6 | use AmeliaBooking\Application\Commands\CommandResult; |
| 7 | use AmeliaBooking\Application\Common\Exceptions\AccessDeniedException; |
| 8 | use AmeliaBooking\Domain\Entity\Entities; |
| 9 | use AmeliaBooking\Domain\Services\Settings\SettingsService; |
| 10 | use AmeliaBooking\Infrastructure\Services\Mailchimp\AbstractMailchimpService; |
| 11 | use Interop\Container\Exception\ContainerException; |
| 12 | |
| 13 | /** |
| 14 | * Class GetSettingsCommandHandler |
| 15 | * |
| 16 | * @package AmeliaBooking\Application\Commands\Settings |
| 17 | */ |
| 18 | class GetSettingsCommandHandler extends CommandHandler |
| 19 | { |
| 20 | /** |
| 21 | * @return CommandResult |
| 22 | * @throws ContainerException |
| 23 | * @throws AccessDeniedException |
| 24 | */ |
| 25 | public function handle(GetSettingsCommand $command) |
| 26 | { |
| 27 | $result = new CommandResult(); |
| 28 | |
| 29 | if (!$command->getPermissionService()->currentUserCanRead(Entities::SETTINGS)) { |
| 30 | throw new AccessDeniedException('You are not allowed to read settings.'); |
| 31 | } |
| 32 | |
| 33 | /** @var SettingsService $settingsService */ |
| 34 | $settingsService = $this->getContainer()->get('domain.settings.service'); |
| 35 | |
| 36 | $settings = $settingsService->getAllSettingsCategorized(); |
| 37 | |
| 38 | if ($settings['activation']['purchaseCodeStore'] !== '' && $settings['activation']['active']) { |
| 39 | $settings['activation']['purchaseCodeStore'] = null; |
| 40 | } |
| 41 | |
| 42 | if (!empty($settings['payments']['square'])) { |
| 43 | $settings['payments']['square']['phpVersion'] = phpversion(); |
| 44 | } |
| 45 | |
| 46 | $mailchimpLists = []; |
| 47 | if ($settingsService->isFeatureEnabled('mailchimp') && !empty($settings['mailchimp']['accessToken'])) { |
| 48 | /** @var AbstractMailchimpService $mailchimpService */ |
| 49 | $mailchimpService = $this->getContainer()->get('infrastructure.mailchimp.service'); |
| 50 | $mailchimpLists = $mailchimpService->getLists(); |
| 51 | if (!empty($mailchimpLists)) { |
| 52 | if (!$settings['mailchimp']['list']) { |
| 53 | $settings['mailchimp']['list'] = $mailchimpLists[0]['id']; |
| 54 | $settingsService->setCategorySettings('mailchimp', $settings['mailchimp']); |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | $result->setResult(CommandResult::RESULT_SUCCESS); |
| 60 | $result->setMessage('Successfully retrieved settings.'); |
| 61 | |
| 62 | $settings = apply_filters('amelia_get_settings_filter', $settings); |
| 63 | |
| 64 | do_action('amelia_get_settings', $settings); |
| 65 | |
| 66 | $result->setData( |
| 67 | [ |
| 68 | 'settings' => $settings, |
| 69 | 'additionalData' => ['mailchimpLists' => $mailchimpLists] |
| 70 | ] |
| 71 | ); |
| 72 | |
| 73 | return $result; |
| 74 | } |
| 75 | } |
| 76 |