Merge pull request #4002 from pixelfed/staging

Staging
pull/4009/head
daniel 2022-12-24 04:32:27 -07:00 zatwierdzone przez GitHub
commit 6b1e73ef99
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
8 zmienionych plików z 188 dodań i 214 usunięć

Wyświetl plik

@ -50,6 +50,10 @@ use App\{
UserFilter, UserFilter,
UserSetting, UserSetting,
}; };
use App\Models\Conversation;
use App\Models\Poll;
use App\Models\PollVote;
use App\Models\Portfolio;
use App\Models\UserPronoun; use App\Models\UserPronoun;
class DeleteAccountPipeline implements ShouldQueue class DeleteAccountPipeline implements ShouldQueue
@ -59,6 +63,9 @@ class DeleteAccountPipeline implements ShouldQueue
protected $user; protected $user;
public $timeout = 900; public $timeout = 900;
public $tries = 3;
public $maxExceptions = 1;
public $deleteWhenMissingModels = true;
public function __construct(User $user) public function __construct(User $user)
{ {
@ -68,160 +75,108 @@ class DeleteAccountPipeline implements ShouldQueue
public function handle() public function handle()
{ {
$user = $this->user; $user = $this->user;
$profile = $user->profile;
$id = $user->profile_id;
$this->deleteUserColumns($user); $this->deleteUserColumns($user);
AccountService::del($user->profile_id); AccountService::del($user->profile_id);
DB::transaction(function() use ($user) { AccountLog::whereItemType('App\User')->whereItemId($user->id)->forceDelete();
AccountLog::whereItemType('App\User')->whereItemId($user->id)->forceDelete();
});
DB::transaction(function() use ($user) { AccountInterstitial::whereUserId($user->id)->delete();
AccountInterstitial::whereUserId($user->id)->delete();
});
DB::transaction(function() use ($user) { // Delete Avatar
if($user->profile) { $profile->avatar->forceDelete();
$avatar = $user->profile->avatar;
$path = $avatar->media_path;
if(!in_array($path, [
'public/avatars/default.jpg',
'public/avatars/default.png'
])) {
if(config('pixelfed.cloud_storage')) {
$disk = Storage::disk(config('filesystems.cloud'));
if($disk->exists($path)) {
$disk->delete($path);
}
}
$disk = Storage::disk(config('filesystems.local'));
if($disk->exists($path)) {
$disk->delete($path);
}
}
$avatar->forceDelete(); // Delete Poll Votes
} PollVote::whereProfileId($id)->delete();
$id = $user->profile_id; // Delete Polls
Poll::whereProfileId($id)->delete();
ImportData::whereProfileId($id) // Delete Portfolio
->cursor() Portfolio::whereProfileId($id)->delete();
->each(function($data) {
$path = storage_path('app/'.$data->path);
if(is_file($path)) {
unlink($path);
}
$data->delete();
});
ImportJob::whereProfileId($id)
->cursor()
->each(function($data) {
$path = storage_path('app/'.$data->media_json);
if(is_file($path)) {
unlink($path);
}
$data->delete();
});
MediaTag::whereProfileId($id)->delete();
Bookmark::whereProfileId($id)->forceDelete();
EmailVerification::whereUserId($user->id)->forceDelete();
StatusHashtag::whereProfileId($id)->delete();
DirectMessage::whereFromId($id)->orWhere('to_id', $id)->delete();
StatusArchived::whereProfileId($id)->delete();
UserPronoun::whereProfileId($id)->delete();
FollowRequest::whereFollowingId($id)
->orWhere('follower_id', $id)
->forceDelete();
Follower::whereProfileId($id)
->orWhere('following_id', $id)
->each(function($follow) {
FollowerService::remove($follow->profile_id, $follow->following_id);
$follow->delete();
});
FollowerService::delCache($id);
Like::whereProfileId($id)->forceDelete();
});
DB::transaction(function() use ($user) { ImportData::whereProfileId($id)
$pid = $this->user->profile_id; ->cursor()
->each(function($data) {
StoryView::whereProfileId($pid)->delete(); $path = storage_path('app/'.$data->path);
$stories = Story::whereProfileId($pid)->get();
foreach($stories as $story) {
$path = storage_path('app/'.$story->path);
if(is_file($path)) { if(is_file($path)) {
unlink($path); unlink($path);
} }
$story->forceDelete(); $data->delete();
}
}); });
DB::transaction(function() use ($user) { ImportJob::whereProfileId($id)
$medias = Media::whereUserId($user->id)->get(); ->cursor()
foreach($medias as $media) { ->each(function($data) {
if(config('pixelfed.cloud_storage')) { $path = storage_path('app/'.$data->media_json);
$disk = Storage::disk(config('filesystems.cloud')); if(is_file($path)) {
if($disk->exists($media->media_path)) { unlink($path);
$disk->delete($media->media_path);
}
if($disk->exists($media->thumbnail_path)) {
$disk->delete($media->thumbnail_path);
}
} }
$disk = Storage::disk(config('filesystems.local')); $data->delete();
if($disk->exists($media->media_path)) { });
$disk->delete($media->media_path);
} MediaTag::whereProfileId($id)->delete();
if($disk->exists($media->thumbnail_path)) { Bookmark::whereProfileId($id)->forceDelete();
$disk->delete($media->thumbnail_path); EmailVerification::whereUserId($user->id)->forceDelete();
} StatusHashtag::whereProfileId($id)->delete();
$media->forceDelete(); DirectMessage::whereFromId($id)->orWhere('to_id', $id)->delete();
Conversation::whereFromId($id)->orWhere('to_id', $id)->delete();
StatusArchived::whereProfileId($id)->delete();
UserPronoun::whereProfileId($id)->delete();
FollowRequest::whereFollowingId($id)
->orWhere('follower_id', $id)
->forceDelete();
Follower::whereProfileId($id)
->orWhere('following_id', $id)
->each(function($follow) {
FollowerService::remove($follow->profile_id, $follow->following_id);
$follow->delete();
});
FollowerService::delCache($id);
Like::whereProfileId($id)->forceDelete();
Mention::whereProfileId($id)->forceDelete();
StoryView::whereProfileId($id)->delete();
$stories = Story::whereProfileId($id)->get();
foreach($stories as $story) {
$path = storage_path('app/'.$story->path);
if(is_file($path)) {
unlink($path);
} }
}); $story->forceDelete();
}
DB::transaction(function() use ($user) { UserDevice::whereUserId($user->id)->forceDelete();
Mention::whereProfileId($user->profile_id)->forceDelete(); UserFilter::whereUserId($user->id)->forceDelete();
Notification::whereProfileId($user->profile_id) UserSetting::whereUserId($user->id)->forceDelete();
->orWhere('actor_id', $user->profile_id)
->forceDelete();
});
DB::transaction(function() use ($user) { Mention::whereProfileId($id)->forceDelete();
$collections = Collection::whereProfileId($user->profile_id)->get(); Notification::whereProfileId($id)
foreach ($collections as $collection) { ->orWhere('actor_id', $id)
$collection->items()->delete(); ->forceDelete();
$collection->delete();
}
Contact::whereUserId($user->id)->delete();
HashtagFollow::whereUserId($user->id)->delete();
OauthClient::whereUserId($user->id)->delete();
DB::table('oauth_access_tokens')->whereUserId($user->id)->delete();
DB::table('oauth_auth_codes')->whereUserId($user->id)->delete();
ProfileSponsor::whereProfileId($user->profile_id)->delete();
});
DB::transaction(function() use ($user) { $collections = Collection::whereProfileId($id)->get();
Status::whereProfileId($user->profile_id)->forceDelete(); foreach ($collections as $collection) {
Report::whereUserId($user->id)->forceDelete(); $collection->items()->delete();
PublicTimelineService::warmCache(true, 400); $collection->delete();
$this->deleteProfile($user); }
}); Contact::whereUserId($user->id)->delete();
} HashtagFollow::whereUserId($user->id)->delete();
OauthClient::whereUserId($user->id)->delete();
DB::table('oauth_access_tokens')->whereUserId($user->id)->delete();
DB::table('oauth_auth_codes')->whereUserId($user->id)->delete();
ProfileSponsor::whereProfileId($id)->delete();
protected function deleteProfile($user) { Status::whereProfileId($id)->chunk(50, function($statuses) {
DB::transaction(function() use ($user) { foreach($statuses as $status) {
Profile::whereUserId($user->id)->delete(); StatusDelete::dispatch($status)->onQueue('high');
$this->deleteUserSettings($user); }
}); });
}
protected function deleteUserSettings($user) { Report::whereUserId($user->id)->forceDelete();
PublicTimelineService::warmCache(true, 400);
DB::transaction(function() use ($user) { Profile::whereUserId($user->id)->delete();
UserDevice::whereUserId($user->id)->forceDelete();
UserFilter::whereUserId($user->id)->forceDelete();
UserSetting::whereUserId($user->id)->forceDelete();
});
} }
protected function deleteUserColumns($user) protected function deleteUserColumns($user)

Wyświetl plik

@ -39,6 +39,7 @@ use App\{
ReportLog, ReportLog,
StatusHashtag, StatusHashtag,
Status, Status,
StatusView,
Story, Story,
StoryView, StoryView,
User, User,
@ -46,6 +47,10 @@ use App\{
UserFilter, UserFilter,
UserSetting, UserSetting,
}; };
use App\Models\Conversation;
use App\Models\Poll;
use App\Models\PollVote;
use App\Services\AccountService;
class DeleteRemoteProfilePipeline implements ShouldQueue class DeleteRemoteProfilePipeline implements ShouldQueue
{ {
@ -53,6 +58,11 @@ class DeleteRemoteProfilePipeline implements ShouldQueue
protected $profile; protected $profile;
public $timeout = 900;
public $tries = 3;
public $maxExceptions = 1;
public $deleteWhenMissingModels = true;
public function __construct(Profile $profile) public function __construct(Profile $profile)
{ {
$this->profile = $profile; $this->profile = $profile;
@ -61,80 +71,85 @@ class DeleteRemoteProfilePipeline implements ShouldQueue
public function handle() public function handle()
{ {
$profile = $this->profile; $profile = $this->profile;
$pid = $profile->id;
if($profile->domain == null || $profile->private_key) { if($profile->domain == null || $profile->private_key) {
return; return;
} }
DB::transaction(function() use ($profile) { $profile->status = 'delete';
$profile->avatar->forceDelete(); $profile->save();
$id = $profile->id; AccountService::del($pid);
MediaTag::whereProfileId($id)->delete(); // Delete statuses
StatusHashtag::whereProfileId($id)->delete(); Status::whereProfileId($pid)
DirectMessage::whereFromId($id)->delete(); ->chunk(50, function($statuses) {
FollowRequest::whereFollowingId($id) foreach($statuses as $status) {
->orWhere('follower_id', $id) DeleteRemoteStatusPipeline::dispatch($status)->onQueue('delete');
->forceDelete(); }
Follower::whereProfileId($id)
->orWhere('following_id', $id)
->forceDelete();
Like::whereProfileId($id)->forceDelete();
}); });
DB::transaction(function() use ($profile) { // Delete Poll Votes
$pid = $profile->id; PollVote::whereProfileId($pid)->delete();
StoryView::whereProfileId($pid)->delete();
$stories = Story::whereProfileId($pid)->get(); // Delete Polls
foreach($stories as $story) { Poll::whereProfileId($pid)->delete();
$path = storage_path('app/'.$story->path);
if(is_file($path)) { // Delete Avatar
unlink($path); $profile->avatar->forceDelete();
}
$story->forceDelete(); // Delete media tags
MediaTag::whereProfileId($pid)->delete();
// Delete DMs
DirectMessage::whereFromId($pid)->orWhere('to_id', $pid)->delete();
Conversation::whereFromId($pid)->orWhere('to_id', $pid)->delete();
// Delete FollowRequests
FollowRequest::whereFollowingId($pid)
->orWhere('follower_id', $pid)
->delete();
// Delete relationships
Follower::whereProfileId($pid)
->orWhere('following_id', $pid)
->delete();
// Delete likes
Like::whereProfileId($pid)->forceDelete();
// Delete Story Views + Stories
StoryView::whereProfileId($pid)->delete();
$stories = Story::whereProfileId($pid)->get();
foreach($stories as $story) {
$path = storage_path('app/'.$story->path);
if(is_file($path)) {
unlink($path);
} }
}); $story->forceDelete();
}
DB::transaction(function() use ($profile) { // Delete mutes/blocks
$medias = Media::whereProfileId($profile->id)->get(); UserFilter::whereFilterableType('App\Profile')->whereFilterableId($pid)->delete();
foreach($medias as $media) {
$path = storage_path('app/'.$media->media_path); // Delete mentions
$thumb = storage_path('app/'.$media->thumbnail_path); Mention::whereProfileId($pid)->forceDelete();
if(is_file($path)) {
unlink($path); // Delete notifications
Notification::whereProfileId($pid)
->orWhere('actor_id', $pid)
->chunk(50, function($notifications) {
foreach($notifications as $n) {
$n->forceDelete();
} }
if(is_file($thumb)) { });
unlink($thumb);
}
$media->forceDelete();
}
});
DB::transaction(function() use ($profile) { // Delete reports
Mention::whereProfileId($profile->id)->forceDelete(); Report::whereProfileId($profile->id)->orWhere('reported_profile_id')->forceDelete();
Notification::whereProfileId($profile->id)
->orWhere('actor_id', $profile->id)
->forceDelete();
});
DB::transaction(function() use ($profile) { // Delete profile
Status::whereProfileId($profile->id) Profile::findOrFail($profile->id)->delete();
->cursor() return;
->each(function($status) {
AccountInterstitial::where('item_type', 'App\Status')
->where('item_id', $status->id)
->delete();
$status->forceDelete();
});
Report::whereProfileId($profile->id)->forceDelete();
$this->deleteProfile($profile);
});
}
protected function deleteProfile($profile) {
DB::transaction(function() use ($profile) {
Profile::findOrFail($profile->id)->delete();
});
} }
} }

Wyświetl plik

@ -19,10 +19,12 @@ use App\Status;
use App\StatusHashtag; use App\StatusHashtag;
use App\StatusView; use App\StatusView;
use App\Notification; use App\Notification;
use App\Services\AccountService;
use App\Services\NetworkTimelineService; use App\Services\NetworkTimelineService;
use App\Services\StatusService; use App\Services\StatusService;
use App\Jobs\ProfilePipeline\DecrementPostCount; use App\Jobs\ProfilePipeline\DecrementPostCount;
use App\Jobs\MediaPipeline\MediaDeletePipeline; use App\Jobs\MediaPipeline\MediaDeletePipeline;
use Cache;
class DeleteRemoteStatusPipeline implements ShouldQueue class DeleteRemoteStatusPipeline implements ShouldQueue
{ {
@ -30,9 +32,10 @@ class DeleteRemoteStatusPipeline implements ShouldQueue
protected $status; protected $status;
public $timeout = 300; public $timeout = 30;
public $tries = 3; public $tries = 2;
public $maxExceptions = 1; public $maxExceptions = 1;
public $deleteWhenMissingModels = true;
/** /**
* Create a new job instance. * Create a new job instance.
@ -41,7 +44,7 @@ class DeleteRemoteStatusPipeline implements ShouldQueue
*/ */
public function __construct(Status $status) public function __construct(Status $status)
{ {
$this->status = $status->withoutRelations(); $this->status = $status;
} }
/** /**
@ -53,9 +56,12 @@ class DeleteRemoteStatusPipeline implements ShouldQueue
{ {
$status = $this->status; $status = $this->status;
if(AccountService::get($status->profile_id, true)) {
DecrementPostCount::dispatch($status->profile_id)->onQueue('feed');
}
NetworkTimelineService::del($status->id); NetworkTimelineService::del($status->id);
StatusService::del($status->id, true); Cache::forget(StatusService::key($status->id));
DecrementPostCount::dispatchNow($status->profile_id);
Bookmark::whereStatusId($status->id)->delete(); Bookmark::whereStatusId($status->id)->delete();
Notification::whereItemType('App\Status') Notification::whereItemType('App\Status')
->whereItemId($status->id) ->whereItemId($status->id)
@ -73,6 +79,7 @@ class DeleteRemoteStatusPipeline implements ShouldQueue
StatusHashtag::whereStatusId($status->id)->delete(); StatusHashtag::whereStatusId($status->id)->delete();
StatusView::whereStatusId($status->id)->delete(); StatusView::whereStatusId($status->id)->delete();
Status::whereReblogOfId($status->id)->forceDelete(); Status::whereReblogOfId($status->id)->forceDelete();
$status->delete(); $status->forceDelete();
return 1;
} }
} }

Wyświetl plik

@ -20,6 +20,7 @@ class MediaDeletePipeline implements ShouldQueue
public $timeout = 300; public $timeout = 300;
public $tries = 3; public $tries = 3;
public $maxExceptions = 1; public $maxExceptions = 1;
public $deleteWhenMissingModels = true;
public function __construct(Media $media) public function __construct(Media $media)
{ {
@ -40,32 +41,27 @@ class MediaDeletePipeline implements ShouldQueue
array_pop($e); array_pop($e);
$i = implode('/', $e); $i = implode('/', $e);
if(config_cache('pixelfed.cloud_storage') == true) { if(config('pixelfed.cloud_storage') == true) {
$disk = Storage::disk(config('filesystems.cloud')); $disk = Storage::disk(config('filesystems.cloud'));
if($path) { if($path && $disk->exists($path)) {
$disk->delete($path); $disk->delete($path);
} }
if($thumb) { if($thumb && $disk->exists($thumb)) {
$disk->delete($thumb); $disk->delete($thumb);
} }
if(count($e) > 4 && count($disk->files($i)) == 0) {
$disk->deleteDirectory($i);
}
} }
$disk = Storage::disk(config('filesystems.local')); $disk = Storage::disk(config('filesystems.local'));
if($path && $disk->exists($path)) { if($path && $disk->exists($path)) {
$disk->delete($path); $disk->delete($path);
} }
if($thumb && $disk->exists($thumb)) { if($thumb && $disk->exists($thumb)) {
$disk->delete($thumb); $disk->delete($thumb);
} }
if(count($e) > 4 && count($disk->files($i)) == 0) {
$disk->deleteDirectory($i);
}
$media->forceDelete(); $media->forceDelete();

Wyświetl plik

@ -17,6 +17,7 @@ class MediaStoragePipeline implements ShouldQueue
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $media; protected $media;
public $deleteWhenMissingModels = true;
public function __construct(Media $media) public function __construct(Media $media)
{ {
@ -28,4 +29,4 @@ class MediaStoragePipeline implements ShouldQueue
MediaStorageService::store($this->media); MediaStorageService::store($this->media);
} }
} }

Wyświetl plik

@ -89,7 +89,7 @@ class StatusDelete implements ShouldQueue
Media::whereStatusId($status->id) Media::whereStatusId($status->id)
->get() ->get()
->each(function($media) { ->each(function($media) {
MediaDeletePipeline::dispatchNow($media); MediaDeletePipeline::dispatch($media)->onQueue('mmo');
}); });
if($status->in_reply_to_id) { if($status->in_reply_to_id) {

Wyświetl plik

@ -65,7 +65,7 @@ class AvatarObserver
@unlink($path); @unlink($path);
} }
if($avatar->cdn_url && config_cache('pixelfed.cloud_storage')) { if(config_cache('pixelfed.cloud_storage')) {
$disk = Storage::disk(config('filesystems.cloud')); $disk = Storage::disk(config('filesystems.cloud'));
$base = Str::startsWith($avatar->media_path, 'cache/avatars/'); $base = Str::startsWith($avatar->media_path, 'cache/avatars/');
if($base && $disk->exists($avatar->media_path)) { if($base && $disk->exists($avatar->media_path)) {

Wyświetl plik

@ -274,6 +274,6 @@ class MediaStorageService {
if(!$confirm) { if(!$confirm) {
return; return;
} }
MediaDeletePipeline::dispatch($media); MediaDeletePipeline::dispatch($media)->onQueue('mmo');
} }
} }