2019-02-12 08:05:17 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Observers;
|
|
|
|
|
|
|
|
use App\Avatar;
|
2021-01-26 04:37:44 +00:00
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
use Illuminate\Support\Str;
|
2021-02-01 07:47:54 +00:00
|
|
|
use App\Services\AccountService;
|
2019-02-12 08:05:17 +00:00
|
|
|
|
|
|
|
class AvatarObserver
|
|
|
|
{
|
2022-09-27 05:58:15 +00:00
|
|
|
/**
|
|
|
|
* Handle events after all transactions are committed.
|
|
|
|
*
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
public $afterCommit = true;
|
|
|
|
|
2019-02-12 08:05:17 +00:00
|
|
|
/**
|
|
|
|
* Handle the avatar "created" event.
|
|
|
|
*
|
|
|
|
* @param \App\Avatar $avatar
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function created(Avatar $avatar)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the avatar "updated" event.
|
|
|
|
*
|
|
|
|
* @param \App\Avatar $avatar
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function updated(Avatar $avatar)
|
|
|
|
{
|
2021-02-01 07:47:54 +00:00
|
|
|
AccountService::del($avatar->profile_id);
|
2019-02-12 08:05:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the avatar "deleted" event.
|
|
|
|
*
|
|
|
|
* @param \App\Avatar $avatar
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function deleted(Avatar $avatar)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the avatar "deleting" event.
|
|
|
|
*
|
|
|
|
* @param \App\Avatar $avatar
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function deleting(Avatar $avatar)
|
|
|
|
{
|
|
|
|
$path = storage_path('app/'.$avatar->media_path);
|
2020-12-15 06:54:22 +00:00
|
|
|
if( is_file($path) &&
|
|
|
|
$avatar->media_path != 'public/avatars/default.png' &&
|
|
|
|
$avatar->media_path != 'public/avatars/default.jpg'
|
|
|
|
) {
|
2019-05-28 02:03:19 +00:00
|
|
|
@unlink($path);
|
|
|
|
}
|
2021-01-26 04:37:44 +00:00
|
|
|
|
2022-12-24 11:28:52 +00:00
|
|
|
if(config_cache('pixelfed.cloud_storage')) {
|
2021-01-26 04:37:44 +00:00
|
|
|
$disk = Storage::disk(config('filesystems.cloud'));
|
|
|
|
$base = Str::startsWith($avatar->media_path, 'cache/avatars/');
|
|
|
|
if($base && $disk->exists($avatar->media_path)) {
|
|
|
|
$disk->delete($avatar->media_path);
|
|
|
|
}
|
|
|
|
}
|
2021-02-01 07:47:54 +00:00
|
|
|
AccountService::del($avatar->profile_id);
|
2019-02-12 08:05:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the avatar "restored" event.
|
|
|
|
*
|
|
|
|
* @param \App\Avatar $avatar
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function restored(Avatar $avatar)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the avatar "force deleted" event.
|
|
|
|
*
|
|
|
|
* @param \App\Avatar $avatar
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function forceDeleted(Avatar $avatar)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
}
|