FeaturesIntegrations
1 month ago
ExportDataTransferCommand.php
3 weeks ago
ExportDataTransferCommandHandler.php
3 weeks ago
GetSettingsCommand.php
1 year ago
GetSettingsCommandHandler.php
1 month ago
ProcessImportDataTransferCommand.php
3 weeks ago
ProcessImportDataTransferCommandHandler.php
3 weeks ago
StartImportDataTransferCommand.php
3 weeks ago
StartImportDataTransferCommandHandler.php
3 weeks ago
UpdateSettingsCategoriesCommand.php
7 months ago
UpdateSettingsCategoriesCommandHandler.php
1 month ago
UpdateSettingsCommand.php
1 year ago
UpdateSettingsCommandHandler.php
1 month ago
StartImportDataTransferCommandHandler.php
38 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\Infrastructure\Services\DataTransfer\DataTransferService; |
| 10 | |
| 11 | class StartImportDataTransferCommandHandler extends CommandHandler |
| 12 | { |
| 13 | protected $mandatoryFields = [ |
| 14 | 'file', |
| 15 | ]; |
| 16 | |
| 17 | public function handle(StartImportDataTransferCommand $command): CommandResult |
| 18 | { |
| 19 | if (!$command->getPermissionService()->currentUserCanWrite(Entities::SETTINGS)) { |
| 20 | throw new AccessDeniedException('You are not allowed to import Amelia settings and data.'); |
| 21 | } |
| 22 | |
| 23 | $this->checkMandatoryFields($command); |
| 24 | |
| 25 | /** @var DataTransferService $dataTransferService */ |
| 26 | $dataTransferService = $this->container->get('infrastructure.dataTransfer.service'); |
| 27 | |
| 28 | $result = new CommandResult(); |
| 29 | $result->setResult(CommandResult::RESULT_SUCCESS); |
| 30 | $result->setMessage('Successfully initialized the Amelia import.'); |
| 31 | $result->setData([ |
| 32 | 'importData' => $dataTransferService->startImportJob($command->getField('file')) |
| 33 | ]); |
| 34 | |
| 35 | return $result; |
| 36 | } |
| 37 | } |
| 38 |