. */ namespace SP\Modules\Api\Controllers\Config; use Exception; use Klein\Klein; use SP\Core\Application; use SP\Core\Events\Event; use SP\Core\Events\EventMessage; use SP\Domain\Api\Dtos\ApiResponse; use SP\Domain\Api\Ports\ApiService; use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Acl\AclInterface; use SP\Domain\Core\Exceptions\InvalidClassException; use SP\Domain\Export\Ports\XmlExportService; use SP\Infrastructure\File\DirectoryHandler; use SP\Modules\Api\Controllers\ControllerBase; use SP\Modules\Api\Controllers\Help\ConfigHelp; /** * Class ExportController */ final class ExportController extends ControllerBase { private XmlExportService $xmlExportService; /** * @throws InvalidClassException */ public function __construct( Application $application, Klein $router, ApiService $apiService, AclInterface $acl, XmlExportService $xmlExportService ) { parent::__construct($application, $router, $apiService, $acl); $this->xmlExportService = $xmlExportService; $this->apiService->setHelpClass(ConfigHelp::class); } /** * exportAction */ public function exportAction(): void { try { $this->setupApi(AclActionsInterface::CONFIG_EXPORT_RUN); $password = $this->apiService->getParamString('password'); $path = $this->apiService->getParamString('path', false, BACKUP_PATH); $this->eventDispatcher->notify( 'run.export.start', new Event( $this, EventMessage::factory() ->addDescription(__u('sysPass XML export')) ->addDetail(__u('Path'), $path) ) ); $file = $this->xmlExportService->export(new DirectoryHandler($path), $password); $this->eventDispatcher->notify( 'run.export.end', new Event($this, EventMessage::factory()->addDescription(__u('Export process finished'))) ); $exportFiles = ['files' => ['xml' => $file]]; $this->returnResponse(ApiResponse::makeSuccess($exportFiles, null, __('Export process finished'))); } catch (Exception $e) { processException($e); $this->returnResponseException($e); } } }