mirror of
https://github.com/HDInnovations/UNIT3D-Community-Edition.git
synced 2026-04-23 03:34:22 -05:00
(Update) Rework Group Queries
- use select and not pluck
This commit is contained in:
@@ -43,13 +43,13 @@ class autoBan extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->pluck('id');
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->select('id')->first();
|
||||
$bans = Warning::with('warneduser')->select(DB::raw('user_id, count(*) as value'))->where('active', 1)->groupBy('user_id')->having('value', '>=', config('hitrun.max_warnings'))->get();
|
||||
|
||||
foreach ($bans as $ban) {
|
||||
if ($ban->warneduser->group_id != $bannedGroup && !$ban->warneduser->group->is_immune) {
|
||||
if ($ban->warneduser->group_id != $bannedGroup->id && !$ban->warneduser->group->is_immune) {
|
||||
// If User Has x or More Active Warnings Ban Set The Users Group To Banned
|
||||
$ban->warneduser->group_id = $bannedGroup;
|
||||
$ban->warneduser->group_id = $bannedGroup->id;
|
||||
$ban->warneduser->can_upload = 0;
|
||||
$ban->warneduser->can_download = 0;
|
||||
$ban->warneduser->can_comment = 0;
|
||||
|
||||
@@ -42,7 +42,7 @@ class disableInactiveUsers extends Command
|
||||
public function handle()
|
||||
{
|
||||
if (config('pruning.user_pruning') == true) {
|
||||
$disabledGroup = Group::where('slug', '=', 'disabled')->pluck('id');
|
||||
$disabledGroup = Group::where('slug', '=', 'disabled')->select('id')->first();
|
||||
$current = Carbon::now();
|
||||
|
||||
$matches = User::whereIn('group_id', [config('pruning.group_ids')]);
|
||||
@@ -53,7 +53,7 @@ class disableInactiveUsers extends Command
|
||||
|
||||
foreach ($users as $user) {
|
||||
if ($user->getSeeding() !== 0) {
|
||||
$user->group_id = $disabledGroup;
|
||||
$user->group_id = $disabledGroup->id;
|
||||
$user->can_upload = 0;
|
||||
$user->can_download = 0;
|
||||
$user->can_comment = 0;
|
||||
|
||||
@@ -42,14 +42,14 @@ class revokePermissions extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->pluck('id');
|
||||
$validatingGroup = Group::where('slug', '=', 'validating')->pluck('id');
|
||||
$leechGroup = Group::where('slug', '=', 'leech')->pluck('id');
|
||||
$disabledGroup = Group::where('slug', '=', 'disabled')->pluck('id');
|
||||
$prunedGroup = Group::where('slug', '=', 'pruned')->pluck('id');
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->select('id')->first();
|
||||
$validatingGroup = Group::where('slug', '=', 'validating')->select('id')->first();
|
||||
$leechGroup = Group::where('slug', '=', 'leech')->select('id')->first();
|
||||
$disabledGroup = Group::where('slug', '=', 'disabled')->select('id')->first();
|
||||
$prunedGroup = Group::where('slug', '=', 'pruned')->select('id')->first();
|
||||
|
||||
User::whereNotIn('group_id', [$bannedGroup,$validatingGroup,$leechGroup,$disabledGroup,$prunedGroup])->update(['can_download' => '1', 'can_request' => '1']);
|
||||
User::whereIn('group_id', [$bannedGroup,$validatingGroup,$leechGroup,$disabledGroup,$prunedGroup])->update(['can_download' => '0', 'can_request' => '0']);
|
||||
User::whereNotIn('group_id', [$bannedGroup->id,$validatingGroup->id,$leechGroup->id,$disabledGroup->id,$prunedGroup->id])->update(['can_download' => '1', 'can_request' => '1']);
|
||||
User::whereIn('group_id', [$bannedGroup->id,$validatingGroup->id,$leechGroup->id,$disabledGroup->id,$prunedGroup->id])->update(['can_download' => '0', 'can_request' => '0']);
|
||||
|
||||
$warning = Warning::with('warneduser')->select(DB::raw('user_id, count(*) as value'))->where('active', 1)->groupBy('user_id')->having('value', '>=', config('hitrun.revoke'))->get();
|
||||
|
||||
|
||||
@@ -42,11 +42,11 @@ class softDeleteDisabledUsers extends Command
|
||||
public function handle()
|
||||
{
|
||||
if (config('pruning.user_pruning') == true) {
|
||||
$disabledGroup = Group::where('slug', '=', 'disabled')->pluck('id');
|
||||
$prunedGroup = Group::where('slug', '=', 'pruned')->pluck('id');
|
||||
$disabledGroup = Group::where('slug', '=', 'disabled')->select('id')->first();
|
||||
$prunedGroup = Group::where('slug', '=', 'pruned')->select('id')->first();
|
||||
|
||||
$current = Carbon::now();
|
||||
$users = User::where('group_id', '=', $disabledGroup)
|
||||
$users = User::where('group_id', '=', $disabledGroup->id)
|
||||
->where('disabled_at', '<', $current->copy()->subDays(config('pruning.soft_delete'))->toDateTimeString())
|
||||
->get();
|
||||
|
||||
@@ -60,7 +60,7 @@ class softDeleteDisabledUsers extends Command
|
||||
$user->can_invite = 0;
|
||||
$user->can_request = 0;
|
||||
$user->can_chat = 0;
|
||||
$user->group = $prunedGroup;
|
||||
$user->group = $prunedGroup->id;
|
||||
$user->deleted_by = 1;
|
||||
$user->save();
|
||||
$user->delete();
|
||||
|
||||
@@ -22,18 +22,18 @@ class ActivationController extends Controller
|
||||
{
|
||||
public function activate($token)
|
||||
{
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->pluck('id');
|
||||
$memberGroup = Group::where('slug', '=', 'member')->pluck('id');
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->select('id')->first();
|
||||
$memberGroup = Group::where('slug', '=', 'member')->select('id')->first();
|
||||
|
||||
$activation = UserActivation::with('user')->where('token', $token)->firstOrFail();
|
||||
if ($activation->user->id && $activation->user->group->id != $bannedGroup) {
|
||||
if ($activation->user->id && $activation->user->group->id != $bannedGroup->id) {
|
||||
$activation->user->active = 1;
|
||||
$activation->user->can_upload = 1;
|
||||
$activation->user->can_download = 1;
|
||||
$activation->user->can_request = 1;
|
||||
$activation->user->can_comment = 1;
|
||||
$activation->user->can_invite = 1;
|
||||
$activation->user->group_id = $memberGroup;
|
||||
$activation->user->group_id = $memberGroup->id;
|
||||
$activation->user->save();
|
||||
|
||||
// Activity Log
|
||||
|
||||
@@ -66,27 +66,27 @@ class LoginController extends Controller
|
||||
|
||||
protected function authenticated(Request $request, $user)
|
||||
{
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->pluck('id');
|
||||
$validatingGroup = Group::where('slug', '=', 'validating')->pluck('id');
|
||||
$disabledGroup = Group::where('slug', '=', 'disabled')->pluck('id');
|
||||
$memberGroup = Group::where('slug', '=', 'member')->pluck('id');
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->select('id')->first();
|
||||
$validatingGroup = Group::where('slug', '=', 'validating')->select('id')->first();
|
||||
$disabledGroup = Group::where('slug', '=', 'disabled')->select('id')->first();
|
||||
$memberGroup = Group::where('slug', '=', 'member')->select('id')->first();
|
||||
|
||||
if ($user->active == 0 || $user->group_id == $validatingGroup) {
|
||||
if ($user->active == 0 || $user->group_id == $validatingGroup->id) {
|
||||
auth()->logout();
|
||||
$request->session()->flush();
|
||||
return redirect()->route('login')
|
||||
->with(Toastr::error('This account has not been activated and is still in validating group. Please check your email for activation link. If you did not receive the activation code, please click "forgot password" and complete the steps.', 'Whoops!', ['options']));
|
||||
}
|
||||
|
||||
if ($user->group_id == $bannedGroup) {
|
||||
if ($user->group_id == $bannedGroup->id) {
|
||||
auth()->logout();
|
||||
$request->session()->flush();
|
||||
return redirect()->route('login')
|
||||
->with(Toastr::error('This account is Banned!', 'Whoops!', ['options']));
|
||||
}
|
||||
|
||||
if ($user->group_id == $disabledGroup) {
|
||||
$user->group_id = $memberGroup;
|
||||
if ($user->group_id == $disabledGroup->id) {
|
||||
$user->group_id = $memberGroup->id;
|
||||
$user->can_upload = 1;
|
||||
$user->can_download = 1;
|
||||
$user->can_comment = 1;
|
||||
@@ -99,8 +99,8 @@ class LoginController extends Controller
|
||||
->with(Toastr::info('Welcome Back! Your Account Is No Longer Disabled!', $user->username, ['options']));
|
||||
}
|
||||
|
||||
if (auth()->viaRemember() && auth()->user()->group_id == $disabledGroup) {
|
||||
$user->group_id = $memberGroup;
|
||||
if (auth()->viaRemember() && auth()->user()->group_id == $disabledGroup->id) {
|
||||
$user->group_id = $memberGroup->id;
|
||||
$user->can_upload = 1;
|
||||
$user->can_download = 1;
|
||||
$user->can_comment = 1;
|
||||
|
||||
@@ -67,7 +67,7 @@ class RegisterController extends Controller
|
||||
->with(Toastr::error('Invalid or Expired Invite Key!', 'Whoops!', ['options']));
|
||||
}
|
||||
|
||||
$validatingGroup = Group::where('slug', '=', 'validating')->pluck('id');
|
||||
$validatingGroup = Group::where('slug', '=', 'validating')->select('id')->first();
|
||||
$user = new User();
|
||||
$user->username = $request->input('username');
|
||||
$user->email = $request->input('email');
|
||||
@@ -77,7 +77,7 @@ class RegisterController extends Controller
|
||||
$user->uploaded = config('other.default_upload');
|
||||
$user->downloaded = config('other.default_download');
|
||||
$user->style = config('other.default_style', 0);
|
||||
$user->group_id = $validatingGroup;
|
||||
$user->group_id = $validatingGroup->id;
|
||||
|
||||
if (config('email-white-blacklist.enabled') === 'allow' && config('captcha.enabled') == true) {
|
||||
$v = validator($request->all(), [
|
||||
|
||||
@@ -21,13 +21,13 @@ class ResetPasswordController extends Controller
|
||||
|
||||
protected function resetPassword($user, $password)
|
||||
{
|
||||
$validatingGroup = Group::where('slug', '=', 'validating')->pluck('id');
|
||||
$memberGroup = Group::where('slug', '=', 'member')->pluck('id');
|
||||
$validatingGroup = Group::where('slug', '=', 'validating')->select('id')->first();
|
||||
$memberGroup = Group::where('slug', '=', 'member')->select('id')->first();
|
||||
$user->password = bcrypt($password);
|
||||
$user->remember_token = Str::random(60);
|
||||
|
||||
if ($user->group_id === $validatingGroup) {
|
||||
$user->group_id = $memberGroup;
|
||||
if ($user->group_id === $validatingGroup->id) {
|
||||
$user->group_id = $memberGroup->id;
|
||||
}
|
||||
|
||||
$user->active = true;
|
||||
|
||||
@@ -49,13 +49,13 @@ class BanController extends Controller
|
||||
{
|
||||
$user = User::findOrFail($id);
|
||||
$staff = auth()->user();
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->pluck('id');
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->select('id')->first();
|
||||
|
||||
if ($user->group->is_modo || auth()->user()->id == $user->id) {
|
||||
return redirect()->route('profile', ['username' => $user->username, 'id' => $user->id])
|
||||
->with(Toastr::error('You Cannot Ban Yourself Or Other Staff!', 'Whoops!', ['options']));
|
||||
} else {
|
||||
$user->group_id = $bannedGroup;
|
||||
$user->group_id = $bannedGroup->id;
|
||||
$user->can_upload = 0;
|
||||
$user->can_download = 0;
|
||||
$user->can_comment = 0;
|
||||
|
||||
@@ -32,12 +32,12 @@ class HomeController extends Controller
|
||||
public function home()
|
||||
{
|
||||
// User Info
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->pluck('id');
|
||||
$validatingGroup = Group::where('slug', '=', 'validating')->pluck('id');
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->select('id')->first();
|
||||
$validatingGroup = Group::where('slug', '=', 'validating')->select('id')->first();
|
||||
|
||||
$num_user = User::count();
|
||||
$banned = User::where('group_id', $bannedGroup)->count();
|
||||
$validating = User::where('group_id', $validatingGroup)->count();
|
||||
$banned = User::where('group_id', $bannedGroup->id)->count();
|
||||
$validating = User::where('group_id', $validatingGroup->id)->count();
|
||||
|
||||
// Torrent Info
|
||||
$num_torrent = Torrent::count();
|
||||
|
||||
@@ -278,12 +278,12 @@ class UserController extends Controller
|
||||
*/
|
||||
public function massValidateUsers()
|
||||
{
|
||||
$validatingGroup = Group::where('slug', '=', 'validating')->pluck('id');
|
||||
$memberGroup = Group::where('slug', '=', 'member')->pluck('id');
|
||||
$users = User::where('active', '=', 0)->where('group_id', '=', $validatingGroup)->get();
|
||||
$validatingGroup = Group::where('slug', '=', 'validating')->select('id')->first();
|
||||
$memberGroup = Group::where('slug', '=', 'member')->select('id')->first();
|
||||
$users = User::where('active', '=', 0)->where('group_id', '=', $validatingGroup->id)->get();
|
||||
|
||||
foreach ($users as $user) {
|
||||
$user->group_id = $memberGroup;
|
||||
$user->group_id = $memberGroup->id;
|
||||
$user->active = 1;
|
||||
$user->can_upload = 1;
|
||||
$user->can_download = 1;
|
||||
|
||||
@@ -38,29 +38,29 @@ class StatsController extends Controller
|
||||
|
||||
// Total Active Members Count (Not Validating, Banned, Disabled, Pruned)
|
||||
$active_user = cache()->remember('active_user', 60, function () {
|
||||
$validatingGroup = Group::where('slug', '=', 'validating')->pluck('id');
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->pluck('id');
|
||||
$disabledGroup = Group::where('slug', '=', 'disabled')->pluck('id');
|
||||
$prunedGroup = Group::where('slug', '=', 'pruned')->pluck('id');
|
||||
return User::whereNotIn('group_id', [$validatingGroup, $bannedGroup, $disabledGroup, $prunedGroup])->count();
|
||||
$validatingGroup = Group::where('slug', '=', 'validating')->select('id')->first();
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->select('id')->first();
|
||||
$disabledGroup = Group::where('slug', '=', 'disabled')->select('id')->first();
|
||||
$prunedGroup = Group::where('slug', '=', 'pruned')->select('id')->first();
|
||||
return User::whereNotIn('group_id', [$validatingGroup->id, $bannedGroup->id, $disabledGroup->id, $prunedGroup->id])->count();
|
||||
});
|
||||
|
||||
// Total Disabled Members Count
|
||||
$disabled_user = cache()->remember('disabled_user', 60, function () {
|
||||
$disabledGroup = Group::where('slug', '=', 'disabled')->pluck('id');
|
||||
return User::where('group_id', '=', $disabledGroup)->count();
|
||||
$disabledGroup = Group::where('slug', '=', 'disabled')->select('id')->first();
|
||||
return User::where('group_id', '=', $disabledGroup->id)->count();
|
||||
});
|
||||
|
||||
// Total Pruned Members Count
|
||||
$pruned_user = cache()->remember('pruned_user', 60, function () {
|
||||
$prunedGroup = Group::where('slug', '=', 'pruned')->pluck('id');
|
||||
return User::onlyTrashed()->where('group_id', '=', $prunedGroup)->count();
|
||||
$prunedGroup = Group::where('slug', '=', 'pruned')->select('id')->first();
|
||||
return User::onlyTrashed()->where('group_id', '=', $prunedGroup->id)->count();
|
||||
});
|
||||
|
||||
// Total Banned Members Count
|
||||
$banned_user = cache()->remember('banned_user', 60, function () {
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->pluck('id');
|
||||
return User::where('group_id', '=', $bannedGroup)->count();
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->select('id')->first();
|
||||
return User::where('group_id', '=', $bannedGroup->id)->count();
|
||||
});
|
||||
|
||||
// Total Torrents Count
|
||||
@@ -151,13 +151,13 @@ class StatsController extends Controller
|
||||
*/
|
||||
public function uploaded()
|
||||
{
|
||||
$validatingGroup = Group::where('slug', '=', 'validating')->pluck('id');
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->pluck('id');
|
||||
$disabledGroup = Group::where('slug', '=', 'disabled')->pluck('id');
|
||||
$prunedGroup = Group::where('slug', '=', 'pruned')->pluck('id');
|
||||
$validatingGroup = Group::where('slug', '=', 'validating')->select('id')->first();
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->select('id')->first();
|
||||
$disabledGroup = Group::where('slug', '=', 'disabled')->select('id')->first();
|
||||
$prunedGroup = Group::where('slug', '=', 'pruned')->select('id')->first();
|
||||
|
||||
// Fetch Top Uploaders
|
||||
$uploaded = User::latest('uploaded')->whereNotIn('group_id', [$validatingGroup, $bannedGroup, $disabledGroup, $prunedGroup])->take(100)->get();
|
||||
$uploaded = User::latest('uploaded')->whereNotIn('group_id', [$validatingGroup->id, $bannedGroup->id, $disabledGroup->id, $prunedGroup->id])->take(100)->get();
|
||||
|
||||
return view('stats.users.uploaded', ['uploaded' => $uploaded]);
|
||||
}
|
||||
@@ -169,13 +169,13 @@ class StatsController extends Controller
|
||||
*/
|
||||
public function downloaded()
|
||||
{
|
||||
$validatingGroup = Group::where('slug', '=', 'validating')->pluck('id');
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->pluck('id');
|
||||
$disabledGroup = Group::where('slug', '=', 'disabled')->pluck('id');
|
||||
$prunedGroup = Group::where('slug', '=', 'pruned')->pluck('id');
|
||||
$validatingGroup = Group::where('slug', '=', 'validating')->select('id')->first();
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->select('id')->first();
|
||||
$disabledGroup = Group::where('slug', '=', 'disabled')->select('id')->first();
|
||||
$prunedGroup = Group::where('slug', '=', 'pruned')->select('id')->first();
|
||||
|
||||
// Fetch Top Downloaders
|
||||
$downloaded = User::latest('downloaded')->whereNotIn('group_id', [$validatingGroup, $bannedGroup, $disabledGroup, $prunedGroup])->take(100)->get();
|
||||
$downloaded = User::latest('downloaded')->whereNotIn('group_id', [$validatingGroup->id, $bannedGroup->id, $disabledGroup->id, $prunedGroup->id])->take(100)->get();
|
||||
|
||||
return view('stats.users.downloaded', ['downloaded' => $downloaded]);
|
||||
}
|
||||
@@ -226,13 +226,13 @@ class StatsController extends Controller
|
||||
*/
|
||||
public function bankers()
|
||||
{
|
||||
$validatingGroup = Group::where('slug', '=', 'validating')->pluck('id');
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->pluck('id');
|
||||
$disabledGroup = Group::where('slug', '=', 'disabled')->pluck('id');
|
||||
$prunedGroup = Group::where('slug', '=', 'pruned')->pluck('id');
|
||||
$validatingGroup = Group::where('slug', '=', 'validating')->select('id')->first();
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->select('id')->first();
|
||||
$disabledGroup = Group::where('slug', '=', 'disabled')->select('id')->first();
|
||||
$prunedGroup = Group::where('slug', '=', 'pruned')->select('id')->first();
|
||||
|
||||
// Fetch Top Bankers
|
||||
$bankers = User::latest('seedbonus')->whereNotIn('group_id', [$validatingGroup, $bannedGroup, $disabledGroup, $prunedGroup])->take(100)->get();
|
||||
$bankers = User::latest('seedbonus')->whereNotIn('group_id', [$validatingGroup->id, $bannedGroup->id, $disabledGroup->id, $prunedGroup->id])->take(100)->get();
|
||||
|
||||
return view('stats.users.bankers', ['bankers' => $bankers]);
|
||||
}
|
||||
|
||||
@@ -29,9 +29,9 @@ class CheckIfActive
|
||||
public function handle($request, Closure $next, $guard = null)
|
||||
{
|
||||
$user = auth()->user();
|
||||
$validatingGroup = Group::where('slug', '=', 'validating')->pluck('id');
|
||||
$validatingGroup = Group::where('slug', '=', 'validating')->select('id')->first();
|
||||
|
||||
if ($user && $user->group_id == $validatingGroup || $user->active == 0) {
|
||||
if ($user && $user->group_id == $validatingGroup->id || $user->active == 0) {
|
||||
auth()->logout();
|
||||
$request->session()->flush();
|
||||
return redirect('login')
|
||||
|
||||
@@ -29,9 +29,9 @@ class CheckIfBanned
|
||||
public function handle($request, Closure $next, $guard = null)
|
||||
{
|
||||
$user = auth()->user();
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->pluck('id');
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->select('id')->first();
|
||||
|
||||
if ($user && $user->group_id == $bannedGroup) {
|
||||
if ($user && $user->group_id == $bannedGroup->id) {
|
||||
auth()->logout();
|
||||
$request->session()->flush();
|
||||
return redirect('login')
|
||||
|
||||
Reference in New Issue
Block a user