1
0
Fork 1
mirror of https://github.com/pixelfed/pixelfed.git synced 2024-12-25 09:17:03 +00:00
pixelfed/app/Jobs/DeletePipeline/DeleteAccountPipeline.php

183 lines
4.3 KiB
PHP
Raw Normal View History

2018-11-26 19:33:56 +00:00
<?php
namespace App\Jobs\DeletePipeline;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use App\{
AccountLog,
Activity,
Avatar,
Bookmark,
Collection,
DirectMessage,
EmailVerification,
Follower,
FollowRequest,
Hashtag,
Like,
Media,
Mention,
Notification,
Profile,
Report,
ReportComment,
ReportLog,
StatusHashtag,
Status,
User,
UserFilter,
UserSetting,
};
class DeleteAccountPipeline implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $user;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct(User $user)
{
$this->user = $user;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$user = $this->user;
$this->deleteAccountLogs($user);
$this->deleteActivities($user);
$this->deleteAvatar($user);
$this->deleteBookmarks($user);
$this->deleteEmailVerification($user);
$this->deleteFollowRequests($user);
$this->deleteFollowers($user);
$this->deleteLikes($user);
$this->deleteMedia($user);
$this->deleteMentions($user);
$this->deleteNotifications($user);
2018-12-21 05:03:01 +00:00
$this->deleteStatuses($user);
$this->deleteReports($user);
$this->deleteProfile($user);
$this->deleteUser($user);
2018-11-26 19:33:56 +00:00
2018-12-21 05:03:01 +00:00
// TODO: send Delete to every known instance sharedInbox
2018-11-26 19:33:56 +00:00
}
public function deleteAccountLogs($user)
{
AccountLog::chunk(200, function($logs) use ($user) {
foreach($logs as $log) {
if($log->user_id == $user->id) {
2018-12-21 05:03:01 +00:00
$log->forceDelete();
2018-11-26 19:33:56 +00:00
}
}
});
}
public function deleteActivities($user)
{
2018-12-21 05:03:01 +00:00
// deprecated, removed inbox activity logger
2018-11-26 19:33:56 +00:00
}
public function deleteAvatar($user)
{
$avatar = $user->profile->avatar;
if(is_file($avatar->media_path)) {
unlink($avatar->media_path);
}
if(is_file($avatar->thumb_path)) {
unlink($avatar->thumb_path);
}
2018-12-21 05:03:01 +00:00
$avatar->forceDelete();
2018-11-26 19:33:56 +00:00
}
public function deleteBookmarks($user)
{
2018-12-21 05:03:01 +00:00
Bookmark::whereProfileId($user->profile->id)->forceDelete();
2018-11-26 19:33:56 +00:00
}
public function deleteEmailVerification($user)
{
2018-12-21 05:03:01 +00:00
EmailVerification::whereUserId($user->id)->forceDelete();
2018-11-26 19:33:56 +00:00
}
public function deleteFollowRequests($user)
{
$id = $user->profile->id;
2018-12-21 05:03:01 +00:00
FollowRequest::whereFollowingId($id)->orWhere('follower_id', $id)->forceDelete();
2018-11-26 19:33:56 +00:00
}
public function deleteFollowers($user)
{
$id = $user->profile->id;
2018-12-21 05:03:01 +00:00
Follower::whereProfileId($id)->orWhere('following_id', $id)->forceDelete();
2018-11-26 19:33:56 +00:00
}
public function deleteLikes($user)
{
$id = $user->profile->id;
2018-12-21 05:03:01 +00:00
Like::whereProfileId($id)->forceDelete();
2018-11-26 19:33:56 +00:00
}
public function deleteMedia($user)
{
$medias = Media::whereUserId($user->id)->get();
foreach($medias as $media) {
$path = $media->media_path;
$thumb = $media->thumbnail_path;
if(is_file($path)) {
unlink($path);
}
if(is_file($thumb)) {
unlink($thumb);
}
2018-12-21 05:03:01 +00:00
$media->forceDelete();
2018-11-26 19:33:56 +00:00
}
}
public function deleteMentions($user)
{
2018-12-21 05:03:01 +00:00
Mention::whereProfileId($user->profile->id)->forceDelete();
2018-11-26 19:33:56 +00:00
}
public function deleteNotifications($user)
{
$id = $user->profile->id;
2018-12-21 05:03:01 +00:00
Notification::whereProfileId($id)->orWhere('actor_id', $id)->forceDelete();
2018-11-26 19:33:56 +00:00
}
2018-12-21 05:03:01 +00:00
public function deleteStatuses($user) {
Status::whereProfileId($user->profile->id)->forceDelete();
}
public function deleteProfile($user) {
Profile::whereUserId($user->id)->delete();
}
public function deleteReports($user) {
Report::whereUserId($user->id)->forceDelete();
}
public function deleteUser($user) {
UserFilter::find($user->id)->forceDelete();
UserSetting::find($user->id)->forceDelete();
User::find($user->id)->forceDelete();
}
2018-11-26 19:33:56 +00:00
}