PushGatewayRefresh.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Services\NotificationAppGatewayService;
  4. use App\Services\PushNotificationService;
  5. use Illuminate\Console\Command;
  6. use function Laravel\Prompts\select;
  7. class PushGatewayRefresh extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'app:push-gateway-refresh';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = 'Refresh push notification gateway support';
  21. /**
  22. * Execute the console command.
  23. */
  24. public function handle()
  25. {
  26. $this->info('Checking Push Notification support...');
  27. $this->line(' ');
  28. $currentState = NotificationAppGatewayService::enabled();
  29. if ($currentState) {
  30. $this->info('Push Notification support is active!');
  31. return;
  32. } else {
  33. $this->error('Push notification support is NOT active');
  34. $action = select(
  35. label: 'Do you want to force re-check?',
  36. options: ['Yes', 'No'],
  37. required: true
  38. );
  39. if ($action === 'Yes') {
  40. $recheck = NotificationAppGatewayService::forceSupportRecheck();
  41. if ($recheck) {
  42. $this->info('Success! Push Notifications are now active!');
  43. return;
  44. } else {
  45. $this->error('Error, please ensure you have a valid API key.');
  46. $this->line(' ');
  47. $this->line('For more info, visit https://docs.pixelfed.org/running-pixelfed/push-notifications.html');
  48. $this->line(' ');
  49. return;
  50. }
  51. return;
  52. } else {
  53. exit;
  54. }
  55. return;
  56. }
  57. }
  58. }