mirror of https://github.com/pixelfed/pixelfed
Merge pull request #4505 from pixelfed/staging
Update IG Import commands, fix stalled import queuepull/4516/head
commit
da90bf630a
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use App\User;
|
||||
use App\Models\ImportPost;
|
||||
use App\Services\ImportService;
|
||||
|
||||
class ImportRemoveDeletedAccounts extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'app:import-remove-deleted-accounts';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Command description';
|
||||
|
||||
const CACHE_KEY = 'pf:services:import:gc-accounts:skip_min_id';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$skipMinId = Cache::remember(self::CACHE_KEY, 864000, function() {
|
||||
return 1;
|
||||
});
|
||||
|
||||
$deletedIds = User::withTrashed()
|
||||
->whereNotNull('status')
|
||||
->whereIn('status', ['deleted', 'delete'])
|
||||
->where('id', '>', $skipMinId)
|
||||
->limit(500)
|
||||
->pluck('id');
|
||||
|
||||
if(!$deletedIds || !$deletedIds->count()) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach($deletedIds as $did) {
|
||||
if(Storage::exists('imports/' . $did)) {
|
||||
Storage::deleteDirectory('imports/' . $did);
|
||||
}
|
||||
|
||||
ImportPost::where('user_id', $did)->delete();
|
||||
$skipMinId = $did;
|
||||
}
|
||||
|
||||
Cache::put(self::CACHE_KEY, $skipMinId, 864000);
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\ImportPost;
|
||||
use Storage;
|
||||
use App\Services\ImportService;
|
||||
use App\User;
|
||||
|
||||
class ImportUploadCleanStorage extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'app:import-upload-clean-storage';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Command description';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$dirs = Storage::allDirectories('imports');
|
||||
|
||||
foreach($dirs as $dir) {
|
||||
$uid = last(explode('/', $dir));
|
||||
$skip = User::whereNull('status')->find($uid);
|
||||
if(!$skip) {
|
||||
Storage::deleteDirectory($dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue