1<?php
2
3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
4// See the LICENCE file in the repository root for full licence text.
5
6namespace App\Jobs;
7
8use App\Models\ScorePin;
9use DB;
10use Illuminate\Bus\Queueable;
11use Illuminate\Contracts\Queue\ShouldQueue;
12use Illuminate\Queue\InteractsWithQueue;
13
14class RenumberUserScorePins implements ShouldQueue
15{
16 use InteractsWithQueue, Queueable;
17
18 public function __construct(private int $userId, private int $rulesetId)
19 {
20 }
21
22 public function handle()
23 {
24 DB::transaction(function () {
25 $pins = ScorePin
26 ::where([
27 'ruleset_id' => $this->rulesetId,
28 'user_id' => $this->userId,
29 ])->orderBy('display_order', 'asc')
30 ->lockForUpdate()
31 ->get();
32
33 $currentOrder = -1500;
34 $orderInterval = 200;
35
36 foreach ($pins as $pin) {
37 $pin->update(['display_order' => $currentOrder]);
38 $currentOrder += $orderInterval;
39 }
40 });
41 }
42}