diff --git a/app/modules/api/Controllers/ConfigController.php b/app/modules/api/Controllers/ConfigController.php new file mode 100644 index 00000000..92db9e48 --- /dev/null +++ b/app/modules/api/Controllers/ConfigController.php @@ -0,0 +1,100 @@ +. + */ + +namespace SP\Modules\Api\Controllers; + +use SP\Core\Acl\ActionsInterface; +use SP\Core\Events\Event; +use SP\Core\Events\EventMessage; +use SP\Services\Api\ApiResponse; +use SP\Services\Backup\FileBackupService; +use SP\Services\Export\XmlExportService; + +/** + * Class ConfigController + * @package SP\Modules\Api\Controllers + */ +class ConfigController extends ControllerBase +{ + /** + * backupAction + * + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface + */ + public function backupAction() + { + try { + $this->setupApi(ActionsInterface::BACKUP_CONFIG); + + $this->dic->get(FileBackupService::class) + ->doBackup(); + + $this->eventDispatcher->notifyEvent('run.backup.end', + new Event($this, EventMessage::factory() + ->addDescription(__u('Copia de la aplicación y base de datos realizada correctamente'))) + ); + + $this->returnResponse(new ApiResponse(__u('Proceso de backup finalizado'))); + } catch (\Exception $e) { + $this->returnResponseException($e); + + processException($e); + } + } + + /** + * exportAction + * + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface + */ + public function exportAction() + { + try { + $this->setupApi(ActionsInterface::EXPORT_CONFIG); + + $password = $this->apiService->getParamString('password'); + + $this->eventDispatcher->notifyEvent('run.export.start', + new Event($this, EventMessage::factory() + ->addDescription(__u('Exportación de sysPass en XML'))) + ); + + $this->dic->get(XmlExportService::class) + ->doExport($password); + + $this->eventDispatcher->notifyEvent('run.export.end', + new Event($this, EventMessage::factory() + ->addDescription(__u('Proceso de exportación finalizado'))) + ); + + $this->returnResponse(new ApiResponse(__u('Proceso de exportación finalizado'))); + } catch (\Exception $e) { + $this->returnResponseException($e); + + processException($e); + } + } +} \ No newline at end of file