. */ namespace SP\Modules\Api\Controllers; use Exception; use SP\Core\Acl\ActionsInterface; use SP\Core\Events\Event; use SP\Core\Events\EventMessage; use SP\Core\Exceptions\InvalidClassException; use SP\Modules\Api\Controllers\Help\ConfigHelp; use SP\Services\Api\ApiResponse; use SP\Services\Backup\FileBackupService; use SP\Services\Export\XmlExportService; /** * Class ConfigController * * @package SP\Modules\Api\Controllers */ final class ConfigController extends ControllerBase { /** * backupAction */ public function backupAction() { try { $this->setupApi(ActionsInterface::CONFIG_BACKUP_RUN); $path = $this->apiService->getParamString('path', false, BACKUP_PATH); $this->dic->get(FileBackupService::class) ->doBackup($path); $this->eventDispatcher->notifyEvent('run.backup.end', new Event($this, EventMessage::factory() ->addDescription(__u('Application and database backup completed successfully')) ->addDetail(__u('Path'), $path)) ); $this->returnResponse(ApiResponse::makeSuccess($path, null, __('Backup process finished'))); } catch (Exception $e) { processException($e); $this->returnResponseException($e); } } /** * exportAction */ public function exportAction() { try { $this->setupApi(ActionsInterface::CONFIG_EXPORT_RUN); $password = $this->apiService->getParamString('password'); $path = $this->apiService->getParamString('path', false, BACKUP_PATH); $this->eventDispatcher->notifyEvent('run.export.start', new Event($this, EventMessage::factory() ->addDescription(__u('sysPass XML export')) ->addDetail(__u('Path'), $path)) ); $this->dic->get(XmlExportService::class) ->doExport($path, $password); $this->eventDispatcher->notifyEvent('run.export.end', new Event($this, EventMessage::factory() ->addDescription(__u('Export process finished'))) ); $this->returnResponse(ApiResponse::makeSuccess($path, null, __('Export process finished'))); } catch (Exception $e) { processException($e); $this->returnResponseException($e); } } /** * @throws InvalidClassException */ protected function initialize() { $this->apiService->setHelpClass(ConfigHelp::class); } }