|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* NOTICE OF LICENSE |
|
5
|
|
|
* |
|
6
|
|
|
* Part of the Rinvex Fort Package. |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to The MIT License (MIT) |
|
9
|
|
|
* that is bundled with this package in the LICENSE file. |
|
10
|
|
|
* |
|
11
|
|
|
* Package: Rinvex Fort Package |
|
12
|
|
|
* License: The MIT License (MIT) |
|
13
|
|
|
* Link: https://rinvex.com |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
declare(strict_types=1); |
|
17
|
|
|
|
|
18
|
|
|
namespace Rinvex\Fort\Seeds; |
|
19
|
|
|
|
|
20
|
|
|
use Rinvex\Fort\Models\Role; |
|
21
|
|
|
use Rinvex\Fort\Models\User; |
|
22
|
|
|
use Illuminate\Database\Seeder; |
|
23
|
|
|
use Rinvex\Fort\Models\Ability; |
|
24
|
|
|
use Illuminate\Support\Facades\DB; |
|
25
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
26
|
|
|
|
|
27
|
|
|
class DatabaseSeeder extends Seeder |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* {@inheritdoc} |
|
31
|
|
|
*/ |
|
32
|
|
|
public function run() |
|
33
|
|
|
{ |
|
34
|
|
|
Model::unguard(); |
|
35
|
|
|
|
|
36
|
|
|
// WARNING: This action will delete all users/roles/abilities data (Can NOT be UNDONE!) |
|
37
|
|
|
if ($this->isFirstRun() || $this->command->confirm('WARNING! Your database already have data, this action will delete all users/roles/abilities (Can NOT be UNDONE!). Are you sure you want to continue?')) { |
|
|
|
|
|
|
38
|
|
|
DB::statement('SET FOREIGN_KEY_CHECKS=0;'); |
|
39
|
|
|
DB::table(config('rinvex.fort.tables.abilities'))->truncate(); |
|
40
|
|
|
DB::table(config('rinvex.fort.tables.roles'))->truncate(); |
|
41
|
|
|
DB::table(config('rinvex.fort.tables.users'))->truncate(); |
|
42
|
|
|
DB::table(config('rinvex.fort.tables.ability_user'))->truncate(); |
|
43
|
|
|
DB::table(config('rinvex.fort.tables.role_user'))->truncate(); |
|
44
|
|
|
DB::table(config('rinvex.fort.tables.ability_role'))->truncate(); |
|
45
|
|
|
DB::table(config('rinvex.fort.tables.email_verifications'))->truncate(); |
|
46
|
|
|
DB::table(config('auth.passwords.'.config('auth.defaults.passwords').'.table'))->truncate(); |
|
47
|
|
|
DB::table(config('rinvex.fort.tables.persistences'))->truncate(); |
|
48
|
|
|
DB::table(config('rinvex.fort.tables.socialites'))->truncate(); |
|
49
|
|
|
DB::statement('SET FOREIGN_KEY_CHECKS=1;'); |
|
50
|
|
|
|
|
51
|
|
|
// Insert new data |
|
52
|
|
|
$this->call(AbilitiesSeeder::class); |
|
53
|
|
|
$this->call(RolesSeeder::class); |
|
54
|
|
|
$this->call(UsersSeeder::class); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
Model::reguard(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
protected function isFirstRun() |
|
61
|
|
|
{ |
|
62
|
|
|
$userCount = User::count(); |
|
63
|
|
|
$roleCount = Role::count(); |
|
64
|
|
|
$abilityCount = Ability::count(); |
|
65
|
|
|
|
|
66
|
|
|
return ! $userCount && ! $roleCount && ! $abilityCount; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.