1
0

ImportUploadMediaToCloudStorage.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Models\ImportPost;
  5. use App\Jobs\ImportPipeline\ImportMediaToCloudPipeline;
  6. use function Laravel\Prompts\progress;
  7. class ImportUploadMediaToCloudStorage extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'app:import-upload-media-to-cloud-storage {--limit=500}';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = 'Migrate media imported from Instagram to S3 cloud storage.';
  21. /**
  22. * Execute the console command.
  23. */
  24. public function handle()
  25. {
  26. if(
  27. (bool) config('import.instagram.storage.cloud.enabled') === false ||
  28. (bool) config_cache('pixelfed.cloud_storage') === false
  29. ) {
  30. $this->error('Aborted. Cloud storage is not enabled for IG imports.');
  31. return;
  32. }
  33. $limit = $this->option('limit');
  34. $progress = progress(label: 'Migrating import media', steps: $limit);
  35. $progress->start();
  36. $posts = ImportPost::whereUploadedToS3(false)->take($limit)->get();
  37. foreach($posts as $post) {
  38. ImportMediaToCloudPipeline::dispatch($post)->onQueue('low');
  39. $progress->advance();
  40. }
  41. $progress->finish();
  42. }
  43. }