PushGatewayRefresh.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. PushNotificationService::warmList('like');
  44. return;
  45. } else {
  46. $this->error('Error, please ensure you have a valid API key.');
  47. $this->line(' ');
  48. $this->line('For more info, visit https://docs.pixelfed.org/running-pixelfed/push-notifications.html');
  49. $this->line(' ');
  50. return;
  51. }
  52. return;
  53. } else {
  54. exit;
  55. }
  56. return;
  57. }
  58. }
  59. }