ChangelogController.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\UpdateNotification\Controller;
  8. use OCA\UpdateNotification\Manager;
  9. use OCP\App\IAppManager;
  10. use OCP\AppFramework\Controller;
  11. use OCP\AppFramework\Http\Attribute\NoAdminRequired;
  12. use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
  13. use OCP\AppFramework\Http\Attribute\OpenAPI;
  14. use OCP\AppFramework\Http\TemplateResponse;
  15. use OCP\AppFramework\Services\IInitialState;
  16. use OCP\IRequest;
  17. #[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
  18. class ChangelogController extends Controller {
  19. public function __construct(
  20. string $appName,
  21. IRequest $request,
  22. private Manager $manager,
  23. private IAppManager $appManager,
  24. private IInitialState $initialState,
  25. ) {
  26. parent::__construct($appName, $request);
  27. }
  28. /**
  29. * This page is only used for clients not support showing the app changelog feature in-app and thus need to show it on a dedicated page.
  30. * @param string $app App to show the changelog for
  31. * @param string|null $version Version entry to show (defaults to latest installed)
  32. */
  33. #[NoAdminRequired]
  34. #[NoCSRFRequired]
  35. public function showChangelog(string $app, ?string $version = null): TemplateResponse {
  36. $version = $version ?? $this->appManager->getAppVersion($app);
  37. $appInfo = $this->appManager->getAppInfo($app) ?? [];
  38. $appName = $appInfo['name'] ?? $app;
  39. $changes = $this->manager->getChangelog($app, $version) ?? '';
  40. // Remove version headline
  41. /** @var string[] */
  42. $changes = explode("\n", $changes, 2);
  43. $changes = trim(end($changes));
  44. $this->initialState->provideInitialState('changelog', [
  45. 'appName' => $appName,
  46. 'appVersion' => $version,
  47. 'text' => $changes,
  48. ]);
  49. \OCP\Util::addScript($this->appName, 'view-changelog-page');
  50. return new TemplateResponse($this->appName, 'empty');
  51. }
  52. }