userFolder = $rootFolder->getUserFolder($this->userId); } #[AuthorizedAdminSetting(settings: Admin::class)] public function setSubscriptionKey(string $subscriptionKey): RedirectResponse { $this->subscriptionService->setSubscriptionKey(trim($subscriptionKey)); return new RedirectResponse($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute('settings.AdminSettings.index', ['section' => 'support']))); } #[AuthorizedAdminSetting(settings: Admin::class)] public function generateSystemReport(): DataResponse { try { $directory = $this->userFolder->get('System information'); } catch (NotFoundException $e) { try { $directory = $this->userFolder->newFolder('System information'); } catch (\Exception $ex) { $this->logger->warning('Could not create folder "System information" to store generated report.', [ 'app' => 'support', 'exception' => $e, ]); $response = new DataResponse(['message' => $this->l10n->t('Could not create folder "System information" to store generated report.')]); $response->setStatus(Http::STATUS_INTERNAL_SERVER_ERROR); return $response; } } if (!($directory instanceof Folder)) { $this->logger->warning('Could not create folder "System information" to store generated report, a file exists with this name.', [ 'app' => 'support', ]); $response = new DataResponse(['message' => $this->l10n->t('Could not create folder "System information" to store generated report, a file exists with this name.')]); $response->setStatus(Http::STATUS_INTERNAL_SERVER_ERROR); return $response; } $date = $this->timeFactory->getDateTime()->format('Y-m-d'); $filename = $date . '.md'; $filename = $directory->getNonExistingName($filename); try { $file = $directory->newFile($filename); $details = $this->detailManager->getRenderedDetails(); $file->putContent($details); } catch (\Exception $e) { $this->logger->warning('Could not create file "' . $filename . '" to store generated report.', [ 'app' => 'support', 'exception' => $e, ]); $response = new DataResponse(['message' => $this->l10n->t('Could not create file "%s" to store generated report.', [ $filename ])]); $response->setStatus(Http::STATUS_INTERNAL_SERVER_ERROR); return $response; } try { $passwordEvent = new GenerateSecurePasswordEvent(); $this->eventDispatcher->dispatchTyped($passwordEvent); $password = $passwordEvent->getPassword() ?? $this->random->generate(20); $share = $this->shareManager->newShare(); $share->setNode($file); $share->setPermissions(Constants::PERMISSION_READ); $share->setShareType(IShare::TYPE_LINK); $share->setSharedBy($this->userId); $share->setPassword($password); if ($this->shareManager->shareApiLinkDefaultExpireDateEnforced()) { $expiry = $this->timeFactory->getDateTime(); $expiry->add(new \DateInterval('P' . $this->shareManager->shareApiLinkDefaultExpireDays() . 'D')); } else { $expiry = $this->timeFactory->getDateTime(); $expiry->add(new \DateInterval('P2W')); } $share->setExpirationDate($expiry); $share = $this->shareManager->createShare($share); } catch (\Exception $e) { $this->logger->warning('Could not share file "' . $filename . '".', [ 'app' => 'support', 'exception' => $e, ]); $response = new DataResponse(['message' => $this->l10n->t('Could not share file "%s". Nevertheless, you can find it in the folder "System information".', [$filename])]); $response->setStatus(Http::STATUS_INTERNAL_SERVER_ERROR); return $response; } return new DataResponse( [ 'link' => $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $share->getToken()]), 'password' => $password, ], Http::STATUS_CREATED ); } }