mirror of
https://github.com/pixelfed/pixelfed.git
synced 2025-02-01 12:08:30 +00:00
Update TransformImports command, improve handling of imported posts that already exist or are from deleted accounts
This commit is contained in:
parent
b18f3fba8b
commit
892907d5d1
4 changed files with 26 additions and 15 deletions
|
@ -32,7 +32,7 @@ class ImportUploadGarbageCollection extends Command
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$ips = ImportPost::whereNull('status_id')->whereSkipMissingMedia(true)->take(100)->get();
|
$ips = ImportPost::whereNull('status_id')->where('skip_missing_media', true)->take(100)->get();
|
||||||
|
|
||||||
if(!$ips->count()) {
|
if(!$ips->count()) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -54,22 +54,22 @@ class TransformImports extends Command
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$idk = ImportService::getId($ip->user_id, $ip->creation_year, $ip->creation_month, $ip->creation_day);
|
$exists = ImportPost::whereUserId($id)
|
||||||
$exists = ImportPost::whereUserId($id)->where('filename', $ip->filename)->first();
|
->whereNotNull('status_id')
|
||||||
if($exists) {
|
->where('filename', $ip->filename)
|
||||||
$cYear = str_pad($exists->creation_year, 2, 0, STR_PAD_LEFT);
|
->where('creation_year', $ip->creation_year)
|
||||||
$cMonth = str_pad($exists->creation_month, 2, 0, STR_PAD_LEFT);
|
->where('creation_month', $ip->creation_month)
|
||||||
$cDay = str_pad($exists->creation_day, 2, 0, STR_PAD_LEFT);
|
->where('creation_day', $ip->creation_day)
|
||||||
if( $cYear == $idk['year'] &&
|
->exists();
|
||||||
$cMonth == $idk['month'] &&
|
|
||||||
$cDay == $idk['day']
|
if($exists == true) {
|
||||||
) {
|
$ip->skip_missing_media = true;
|
||||||
$ip->skip_missing_media = true;
|
$ip->save();
|
||||||
$ip->save();
|
continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$idk = ImportService::getId($ip->user_id, $ip->creation_year, $ip->creation_month, $ip->creation_day);
|
||||||
|
|
||||||
if(Storage::exists('imports/' . $id . '/' . $ip->filename) === false) {
|
if(Storage::exists('imports/' . $id . '/' . $ip->filename) === false) {
|
||||||
ImportService::clearAttempts($profile->id);
|
ImportService::clearAttempts($profile->id);
|
||||||
ImportService::getPostCount($profile->id, true);
|
ImportService::getPostCount($profile->id, true);
|
||||||
|
|
|
@ -5,6 +5,7 @@ namespace App\Observers;
|
||||||
use App\Status;
|
use App\Status;
|
||||||
use App\Services\ProfileStatusService;
|
use App\Services\ProfileStatusService;
|
||||||
use Cache;
|
use Cache;
|
||||||
|
use App\Services\ImportService;
|
||||||
|
|
||||||
class StatusObserver
|
class StatusObserver
|
||||||
{
|
{
|
||||||
|
@ -56,6 +57,10 @@ class StatusObserver
|
||||||
}
|
}
|
||||||
|
|
||||||
ProfileStatusService::delete($status->profile_id, $status->id);
|
ProfileStatusService::delete($status->profile_id, $status->id);
|
||||||
|
|
||||||
|
if($status->uri == null) {
|
||||||
|
ImportService::clearImportedFiles($status->profile_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -102,4 +102,10 @@ class ImportService
|
||||||
})->flatten();
|
})->flatten();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function clearImportedFiles($profileId)
|
||||||
|
{
|
||||||
|
$key = self::CACHE_KEY . 'importedPostsByProfileId:' . $profileId;
|
||||||
|
return Cache::forget($key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue