. */ namespace SP\Modules\Web\Controllers; use SP\Core\Acl\ActionsInterface; use SP\Core\Acl\UnauthorizedPageException; use SP\Core\Exceptions\SPException; use SP\Http\JsonResponse; use SP\Http\Request; use SP\Modules\Web\Controllers\Traits\ConfigTrait; use SP\Services\Backup\FileBackupService; use SP\Services\Export\XmlExportService; /** * Class ConfigBackupController * * @package SP\Modules\Web\Controllers */ class ConfigBackupController extends SimpleControllerBase { use ConfigTrait; /** * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ public function fileBackupAction() { if ($this->config->getConfigData()->isDemoEnabled()) { $this->returnJsonResponse(JsonResponse::JSON_WARNING, __u('Ey, esto es una DEMO!!')); } try { $backupService = new FileBackupService(); $backupService->doBackup(); $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Proceso de backup finalizado')); } catch (\Exception $e) { $this->returnJsonResponseException($e); } } /** * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ public function xmlExportAction() { $exportPassword = Request::analyzeEncrypted('exportPwd'); $exportPasswordR = Request::analyzeEncrypted('exportPwdR'); if (!empty($exportPassword) && $exportPassword !== $exportPasswordR) { $this->returnJsonResponse(JsonResponse::JSON_ERROR, __u('Las claves no coinciden')); } try { $exportService = $this->dic->get(XmlExportService::class); $exportService->doExport($exportPassword); $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Proceso de exportación finalizado')); } catch (\Exception $e) { $this->returnJsonResponseException($e); } } protected function initialize() { try { if (!$this->checkAccess(ActionsInterface::BACKUP_CONFIG)) { throw new UnauthorizedPageException(SPException::INFO); } } catch (UnauthorizedPageException $e) { $this->returnJsonResponse(JsonResponse::JSON_ERROR, $e->getMessage(), [$e->getHint()]); } } }