ChangelogController.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2024 Ferdinand Thiessen <opensource@fthiessen.de>
  5. *
  6. * @author Ferdinand Thiessen <opensource@fthiessen.de>
  7. *
  8. * @license AGPL-3.0-or-later
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\UpdateNotification\Controller;
  25. use OCA\UpdateNotification\Manager;
  26. use OCP\App\IAppManager;
  27. use OCP\AppFramework\Controller;
  28. use OCP\AppFramework\Http\Attribute\OpenAPI;
  29. use OCP\AppFramework\Http\TemplateResponse;
  30. use OCP\AppFramework\Services\IInitialState;
  31. use OCP\IRequest;
  32. #[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
  33. class ChangelogController extends Controller {
  34. public function __construct(
  35. string $appName,
  36. IRequest $request,
  37. private Manager $manager,
  38. private IAppManager $appManager,
  39. private IInitialState $initialState,
  40. ) {
  41. parent::__construct($appName, $request);
  42. }
  43. /**
  44. * 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.
  45. * @param string $app App to show the changelog for
  46. * @param string|null $version Version entry to show (defaults to latest installed)
  47. * @NoCSRFRequired
  48. * @NoAdminRequired
  49. */
  50. public function showChangelog(string $app, ?string $version = null): TemplateResponse {
  51. $version = $version ?? $this->appManager->getAppVersion($app);
  52. $appInfo = $this->appManager->getAppInfo($app) ?? [];
  53. $appName = $appInfo['name'] ?? $app;
  54. $changes = $this->manager->getChangelog($app, $version) ?? '';
  55. // Remove version headline
  56. /** @var string[] */
  57. $changes = explode("\n", $changes, 2);
  58. $changes = trim(end($changes));
  59. $this->initialState->provideInitialState('changelog', [
  60. 'appName' => $appName,
  61. 'appVersion' => $version,
  62. 'text' => $changes,
  63. ]);
  64. \OCP\Util::addScript($this->appName, 'view-changelog-page');
  65. return new TemplateResponse($this->appName, 'empty');
  66. }
  67. }