ChangelogController.php 1.8 KB

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