Refactor deleting texture
This commit is contained in:
parent
09eed5da43
commit
a4c9736dfa
13
app/Events/TextureDeleting.php
Normal file
13
app/Events/TextureDeleting.php
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
class TextureDeleting extends Event
|
||||
{
|
||||
public $texture;
|
||||
|
||||
public function __construct(\App\Models\Texture $texture)
|
||||
{
|
||||
$this->texture = $texture;
|
||||
}
|
||||
}
|
||||
|
|
@ -258,37 +258,10 @@ class SkinlibController extends Controller
|
|||
Storage::disk('textures')->delete($texture->hash);
|
||||
}
|
||||
|
||||
$texture->likers()->get()->each(function ($user) use ($texture) {
|
||||
$user->closet()->detach($texture->tid);
|
||||
if (option('return_score')) {
|
||||
$user->setScore(option('score_per_closet_item'), 'plus');
|
||||
}
|
||||
});
|
||||
|
||||
if ($u = User::find($texture->uploader)) {
|
||||
$ret = 0;
|
||||
if (option('return_score')) {
|
||||
$ret += $texture->size * (
|
||||
$texture->public
|
||||
? option('score_per_storage')
|
||||
: option('private_score_per_storage')
|
||||
);
|
||||
}
|
||||
|
||||
if ($texture->public && option('take_back_scores_after_deletion', true)) {
|
||||
$ret -= option('score_award_per_texture', 0);
|
||||
}
|
||||
|
||||
$u->setScore($ret, 'plus');
|
||||
}
|
||||
|
||||
if ($texture->delete()) {
|
||||
return json(trans('skinlib.delete.success'), 0);
|
||||
}
|
||||
$texture->delete();
|
||||
return json(trans('skinlib.delete.success'), 0);
|
||||
}
|
||||
|
||||
// @codeCoverageIgnore
|
||||
|
||||
public function privacy(Request $request)
|
||||
{
|
||||
$t = Texture::find($request->input('tid'));
|
||||
|
|
@ -335,8 +308,6 @@ class SkinlibController extends Controller
|
|||
);
|
||||
}
|
||||
|
||||
// @codeCoverageIgnore
|
||||
|
||||
public function rename(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
|
|
|
|||
35
app/Listeners/TextureRemoved.php
Normal file
35
app/Listeners/TextureRemoved.php
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
class TextureRemoved
|
||||
{
|
||||
public function handle(\App\Events\TextureDeleting $event)
|
||||
{
|
||||
$texture = $event->texture;
|
||||
|
||||
$texture->likers()->get()->each(function ($user) use ($texture) {
|
||||
$user->closet()->detach($texture->tid);
|
||||
if (option('return_score')) {
|
||||
$user->setScore(option('score_per_closet_item'), 'plus');
|
||||
}
|
||||
});
|
||||
|
||||
if ($uploader = \App\Models\User::find($texture->uploader)) {
|
||||
$ret = 0;
|
||||
if (option('return_score')) {
|
||||
$ret += $texture->size * (
|
||||
$texture->public
|
||||
? option('score_per_storage')
|
||||
: option('private_score_per_storage')
|
||||
);
|
||||
}
|
||||
|
||||
if ($texture->public && option('take_back_scores_after_deletion', true)) {
|
||||
$ret -= option('score_award_per_texture', 0);
|
||||
}
|
||||
|
||||
$uploader->setScore($ret, 'plus');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -18,6 +18,10 @@ class Texture extends Model
|
|||
'likes' => 'integer',
|
||||
];
|
||||
|
||||
protected $dispatchesEvents = [
|
||||
'deleting' => \App\Events\TextureDeleting::class,
|
||||
];
|
||||
|
||||
public function scopeLike($query, $field, $value)
|
||||
{
|
||||
return $query->where($field, 'LIKE', "%$value%");
|
||||
|
|
|
|||
|
|
@ -18,6 +18,9 @@ class EventServiceProvider extends ServiceProvider
|
|||
'App\Events\PlayerRetrieved' => [
|
||||
'App\Listeners\ResetInvalidTextureForPlayer',
|
||||
],
|
||||
'App\Events\TextureDeleting' => [
|
||||
'App\Listeners\TextureRemoved',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
## Added
|
||||
|
||||
- Chart at administration panel will show today's data.
|
||||
- New event for plugins: `TextureDeleting`.
|
||||
|
||||
## Fixed
|
||||
|
||||
- Fixed resetting options of "Customize" page.
|
||||
- Fixed that dashboard of user center cannot be centered. (Thanks @outtimes)
|
||||
- Fix data consistency when deleting texture.
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
## 新增
|
||||
|
||||
- 管理面板中的图表可显示当天的数据
|
||||
- 新的插件事件:`TextureDeleting`
|
||||
|
||||
## 修复
|
||||
|
||||
- 修复「个性化」页面不能重置选项的问题
|
||||
- 修复用户中心仪表盘不能居中的问题(感谢 @outtimes)
|
||||
- 修复删除材质时的数据一致性
|
||||
|
|
|
|||
|
|
@ -177,7 +177,11 @@ class ReportControllerTest extends TestCase
|
|||
$this->assertEquals($score - 5, $reporter->score);
|
||||
|
||||
// Delete texture
|
||||
option(['reporter_score_modification' => -7]);
|
||||
option([
|
||||
'reporter_score_modification' => -7,
|
||||
'return_score' => false,
|
||||
'take_back_scores_after_deletion' => false,
|
||||
]);
|
||||
$report->refresh();
|
||||
$report->status = Report::PENDING;
|
||||
$report->save();
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user