Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Pull Request — master (#228)
by Cristian
03:04 queued 01:38
created

RemoveBackpackuserModel::replaceModels()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 9.52
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
use Illuminate\Database\Migrations\Migration;
4
use Illuminate\Support\Facades\DB;
5
use Illuminate\Support\Facades\Log;
6
7
class RemoveBackpackuserModel extends Migration
8
{
9
    /**
10
     * Run the migrations.
11
     *
12
     * @return void
13
     */
14
    public function up()
15
    {
16
        // establish the table names
17
        $model_has_roles = config('permission.table_names.model_has_roles');
18
        $model_has_permissions = config('permission.table_names.model_has_permissions');
19
20
        // replace the BackpackUser model with User
21
        $this->replaceModels($model_has_roles);
22
        $this->replaceModels($model_has_permissions);
23
    }
24
25
    public function replaceModels($table_name)
26
    {
27
        Log::info('Replacing BackpackUser model in '.$table_name);
28
29
        // if you've ended up with duplicate entries (both for App\User and App\Models\BackpackUser)
30
        // we can just delete them
31
        $userEntries = DB::table($table_name)
32
            ->where('model_type', "App\User")
33
            ->get();
34
35
        foreach ($userEntries as $entry) {
36
            DB::table($table_name)
37
                ->where('role_id', $entry->role_id)
38
                ->where('model_type', 'App\Models\BackpackUser')
39
                ->where('model_id', $entry->model_id)
40
                ->delete();
41
        }
42
43
        // for the rest of them, we can just replace the BackpackUser model with User
44
        DB::table($table_name)
45
            ->where('model_type', "App\Models\BackpackUser")
46
            ->update([
47
                'model_type' => "App\User",
48
            ]);
49
    }
50
}
51