Fix setting existing texture to be private

This commit is contained in:
gplane 2017-04-21 18:11:17 +08:00
parent 8b002ab157
commit 98ff895d3b
2 changed files with 28 additions and 0 deletions

View File

@ -8,6 +8,8 @@ use Option;
use Storage;
use Session;
use App\Models\User;
use App\Models\Closet;
use App\Models\Player;
use App\Models\Texture;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
@ -205,6 +207,8 @@ class SkinlibController extends Controller
public function privacy(Request $request)
{
$t = Texture::find($request->input('tid'));
$type = $t->type;
$uid = session('uid');
if (!$t)
return json(trans('skinlib.non-existent'), 1);
@ -212,6 +216,16 @@ class SkinlibController extends Controller
if ($t->uploader != $this->user->uid && !$this->user->isAdmin())
return json(trans('skinlib.no-permission'), 1);
foreach (Player::where("tid_$type", $t->tid)->where('uid', '<>', $uid)->get() as $player) {
$player->setTexture(["tid_$type" => 0]);
}
foreach (Closet::all() as $closet) {
if ($closet->uid != $uid && $closet->has($t->tid)) {
$closet->remove($t->tid);
}
}
if ($t->setPrivacy(!$t->public)) {
return json([
'errno' => 0,

View File

@ -238,4 +238,18 @@ class Closet
$this->save();
}
/**
* Get all closets.
*
* @return array
*/
public static function all()
{
$result = [];
foreach (DB::table('closets')->lists('uid') as $uid) {
$result[] = new Closet($uid);
}
return $result;
}
}