PushService.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\Settings\SetupChecks;
  8. use OCP\AppFramework\Utility\ITimeFactory;
  9. use OCP\IConfig;
  10. use OCP\IL10N;
  11. use OCP\Notification\IManager;
  12. use OCP\SetupCheck\ISetupCheck;
  13. use OCP\SetupCheck\SetupResult;
  14. use OCP\Support\Subscription\IRegistry;
  15. class PushService implements ISetupCheck {
  16. public function __construct(
  17. private IL10N $l10n,
  18. private IConfig $config,
  19. private IManager $notificationsManager,
  20. private IRegistry $subscriptionRegistry,
  21. private ITimeFactory $timeFactory,
  22. ) {
  23. }
  24. public function getName(): string {
  25. return $this->l10n->t('Push service');
  26. }
  27. public function getCategory(): string {
  28. return 'system';
  29. }
  30. /**
  31. * Check if is fair use of free push service
  32. */
  33. private function isFairUseOfFreePushService(): bool {
  34. $rateLimitReached = (int)$this->config->getAppValue('notifications', 'rate_limit_reached', '0');
  35. if ($rateLimitReached >= ($this->timeFactory->now()->getTimestamp() - 7 * 24 * 3600)) {
  36. // Notifications app is showing a message already
  37. return true;
  38. }
  39. return $this->notificationsManager->isFairUseOfFreePushService();
  40. }
  41. public function run(): SetupResult {
  42. if ($this->subscriptionRegistry->delegateHasValidSubscription()) {
  43. return SetupResult::success($this->l10n->t('Valid enterprise license'));
  44. }
  45. if ($this->isFairUseOfFreePushService()) {
  46. return SetupResult::success($this->l10n->t('Free push service'));
  47. }
  48. return SetupResult::error(
  49. $this->l10n->t('This is the unsupported community build of Nextcloud. Given the size of this instance, performance, reliability and scalability cannot be guaranteed. Push notifications are limited to avoid overloading our free service. Learn more about the benefits of Nextcloud Enterprise at {link}.'),
  50. descriptionParameters:[
  51. 'link' => [
  52. 'type' => 'highlight',
  53. 'id' => 'link',
  54. 'name' => 'https://nextcloud.com/enterprise',
  55. 'link' => 'https://nextcloud.com/enterprise',
  56. ],
  57. ],
  58. );
  59. }
  60. }