mirror of
https://github.com/zoe-may/TDoG-Skin.git
synced 2025-01-19 06:57:24 +08:00
35 lines
863 B
PHP
35 lines
863 B
PHP
|
<?php
|
||
|
|
||
|
namespace App\Listeners;
|
||
|
|
||
|
use App\Models\Texture;
|
||
|
use App\Models\User;
|
||
|
|
||
|
class CleanUpCloset
|
||
|
{
|
||
|
public function handle(Texture $texture)
|
||
|
{
|
||
|
// no need to update users' closet
|
||
|
// if texture was switched from "private" to "public"
|
||
|
if ($texture->exists && $texture->public) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
$likers = $texture
|
||
|
->likers()
|
||
|
->where('user_uid', '!=', $texture->uploader)
|
||
|
->get();
|
||
|
$likers->each(function (User $user) use ($texture) {
|
||
|
$user->closet()->detach($texture->tid);
|
||
|
if (option('return_score')) {
|
||
|
$user->score += (int) option('score_per_closet_item');
|
||
|
$user->save();
|
||
|
}
|
||
|
});
|
||
|
|
||
|
if ($texture->exists) {
|
||
|
$texture->decrement('likes', $likers->count());
|
||
|
}
|
||
|
}
|
||
|
}
|