. */ namespace SP\Modules\Web\Controllers\ConfigBackup; use Exception; use SP\Core\Acl\ActionsInterface; use SP\Core\Acl\UnauthorizedPageException; use SP\Core\Application; use SP\Core\Context\SessionContext; use SP\Core\Events\Event; use SP\Core\Events\EventMessage; use SP\Domain\Export\Ports\FileBackupServiceInterface; use SP\Http\JsonResponse; use SP\Modules\Web\Controllers\SimpleControllerBase; use SP\Modules\Web\Controllers\Traits\ConfigTrait; use SP\Mvc\Controller\SimpleControllerHelper; /** * Class FileBackupController */ final class FileBackupController extends SimpleControllerBase { use ConfigTrait; private FileBackupServiceInterface $fileBackupService; public function __construct( Application $application, SimpleControllerHelper $simpleControllerHelper, FileBackupServiceInterface $fileBackupService ) { parent::__construct($application, $simpleControllerHelper); $this->fileBackupService = $fileBackupService; } /** * @return bool * @throws \SP\Core\Exceptions\SPException */ public function fileBackupAction(): bool { if ($this->config->getConfigData()->isDemoEnabled()) { return $this->returnJsonResponse(JsonResponse::JSON_WARNING, __u('Ey, this is a DEMO!!')); } try { SessionContext::close(); $this->fileBackupService->doBackup(BACKUP_PATH); $this->eventDispatcher->notify( 'run.backup.end', new Event( $this, EventMessage::factory()->addDescription( __u('Application and database backup completed successfully') ) ) ); return $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Backup process finished')); } catch (Exception $e) { processException($e); $this->eventDispatcher->notify('exception', new Event($e)); return $this->returnJsonResponseException($e); } } /** * initialize * * @throws \SP\Core\Exceptions\SPException * @throws \SP\Core\Exceptions\SessionTimeout */ protected function initialize(): void { try { $this->checks(); $this->checkAccess(ActionsInterface::CONFIG_BACKUP); } catch (UnauthorizedPageException $e) { $this->eventDispatcher->notify('exception', new Event($e)); $this->returnJsonResponseException($e); } } }