ChangelogController.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. use OCP\Util;
  18. #[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
  19. class ChangelogController extends Controller {
  20. public function __construct(
  21. string $appName,
  22. IRequest $request,
  23. private Manager $manager,
  24. private IAppManager $appManager,
  25. private IInitialState $initialState,
  26. ) {
  27. parent::__construct($appName, $request);
  28. }
  29. /**
  30. * 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.
  31. * @param string $app App to show the changelog for
  32. * @param string|null $version Version entry to show (defaults to latest installed)
  33. */
  34. #[NoAdminRequired]
  35. #[NoCSRFRequired]
  36. public function showChangelog(string $app, ?string $version = null): TemplateResponse {
  37. $version = $version ?? $this->appManager->getAppVersion($app);
  38. $appInfo = $this->appManager->getAppInfo($app) ?? [];
  39. $appName = $appInfo['name'] ?? $app;
  40. $changes = $this->manager->getChangelog($app, $version) ?? '';
  41. // Remove version headline
  42. /** @var string[] */
  43. $changes = explode("\n", $changes, 2);
  44. $changes = trim(end($changes));
  45. $this->initialState->provideInitialState('changelog', [
  46. 'appName' => $appName,
  47. 'appVersion' => $version,
  48. 'text' => $changes,
  49. ]);
  50. Util::addScript($this->appName, 'view-changelog-page');
  51. return new TemplateResponse($this->appName, 'empty');
  52. }
  53. }