fix player isn't updated

after closet item was removed
This commit is contained in:
Pig Fang 2020-06-07 11:10:04 +08:00
parent 88e3ed7a07
commit 30e25cf0a8
5 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,16 @@
<?php
namespace App\Listeners;
use App\Models\Texture;
use App\Models\User;
class ResetPlayerForRemovedClosetItem
{
public function handle(Texture $texture, User $user)
{
$type = $texture->type === 'cape' ? 'tid_cape' : 'tid_skin';
$user->players()->where($type, $texture->tid)->update([$type => 0]);
}
}

View File

@ -38,5 +38,8 @@ class EventServiceProvider extends ServiceProvider
Listeners\ResetPlayers::class,
Listeners\CleanUpCloset::class,
],
'closet.removed' => [
Listeners\ResetPlayerForRemovedClosetItem::class,
],
];
}

View File

@ -77,6 +77,7 @@
- Fixed that texture file won't be deleted when deleting texture in reports management.
- Fixed that score calculation at upload page isn't consistent with that at back-end.
- Fixed that new texture name isn't checked when texture is renamed.
- Fixed that player isn't updated after closet item was removed.
## Removed

View File

@ -77,6 +77,7 @@
- 修复处理举报中删除材质时不删除材质文件的问题
- 修复「材质上传」页面的积分计算与后端不一致的问题
- 修复重命名材质时不对新名称进行检查的问题
- 修复移除衣柜物品后不更新角色的问题
## 移除

View File

@ -0,0 +1,22 @@
<?php
namespace Tests;
use App\Models\Player;
use App\Models\Texture;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class ResetPlayerForRemovedClosetItemTest extends TestCase
{
use DatabaseTransactions;
public function testHandle()
{
$texture = factory(Texture::class)->create();
$player = factory(Player::class)->create(['tid_skin' => $texture->tid]);
event('closet.removed', [$texture, $player->user]);
$player->refresh();
$this->assertEquals(0, $player->tid_skin);
}
}