ImportUploadGarbageCollection.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Models\ImportPost;
  5. use Storage;
  6. use App\Services\ImportService;
  7. class ImportUploadGarbageCollection extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'app:import-upload-garbage-collection';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = 'Command description';
  21. /**
  22. * Execute the console command.
  23. */
  24. public function handle()
  25. {
  26. if(!config('import.instagram.enabled')) {
  27. return;
  28. }
  29. $ips = ImportPost::whereNull('status_id')->where('skip_missing_media', true)->take(100)->get();
  30. if(!$ips->count()) {
  31. return;
  32. }
  33. foreach($ips as $ip) {
  34. $pid = $ip->profile_id;
  35. $ip->delete();
  36. ImportService::getPostCount($pid, true);
  37. ImportService::clearAttempts($pid);
  38. ImportService::getImportedFiles($pid, true);
  39. }
  40. }
  41. }