-
Notifications
You must be signed in to change notification settings - Fork 2
/
OctoInstallCommand.php
146 lines (101 loc) · 4.12 KB
/
OctoInstallCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
namespace Octo\Console;
use BezhanSalleh\FilamentShield\Support\Utils;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Hash;
use Octo\Octo;
class OctoInstallCommand extends Command
{
protected $signature = 'octo:install';
protected $description = 'Install aplication';
public const DEFAULT_USER_NAME = 'user';
public const DEFAULT_USER_EMAIL = 'user@octo.dev';
public const DEFAULT_USER_PASSWORD = '123456';
public const DEFAULT_ADMIN_NAME = 'admin';
public const DEFAULT_ADMIN_EMAIL = 'admin@octo.dev';
public const DEFAULT_ADMIN_PASSWORD = '123456';
public const DEFAULT_SUPER_ADMIN_NAME = 'super_admin';
public const DEFAULT_SUPER_ADMIN_EMAIL = 'super_admin@octo.dev';
public const DEFAULT_SUPER_ADMIN_PASSWORD = '123456';
public function handle()
{
$this->info('Optimizing');
$this->call('optimize');
Config::set('app.timezone', 'America/Sao_Paulo');
date_default_timezone_set('America/Sao_Paulo');
$this->call('migrate:fresh', ['--force' => true]);
$this->info('Installing Shield');
$this->call('shield:install', ['--fresh' => true, '--minimal' => true, '--only' => true]);
$this->call('shield:generate', [
'--all' => true,
'--minimal' => true,
]);
$this->call('vendor:publish', [
'--tag' => 'themes-assets',
]);
$this->info('Creating super admin account');
$superAdmin = $this->setUpSuperAdminAccount();
$this->info('Creating admin account');
$admin = $this->setUpAdminAccount();
$this->info('Creating user account');
$user = $this->setUpUserAccount();
$this->info('Installing LogViewer');
$this->call('log-viewer:publish');
$this->info('Seeding');
$this->call('db:seed');
}
private function setUpSuperAdminAccount()
{
$user = Octo::getUserModel()::forceCreate([
'name' => self::DEFAULT_SUPER_ADMIN_NAME,
'email' => self::DEFAULT_SUPER_ADMIN_EMAIL,
'password' => Hash::make(self::DEFAULT_SUPER_ADMIN_PASSWORD),
]);
$user->markEmailAsVerified();
$superAdminRole = Utils::getRoleModel()::firstOrCreate(
['name' => Utils::getSuperAdminName()],
['guard_name' => Utils::getFilamentAuthGuard()]
);
$user->assignRole(Utils::getSuperAdminName());
$this->comment(sprintf('Log in user with email %s and password %s', self::DEFAULT_SUPER_ADMIN_EMAIL, self::DEFAULT_SUPER_ADMIN_PASSWORD));
return $user;
}
private function setUpAdminAccount()
{
$user = Octo::getUserModel()::forceCreate([
'name' => self::DEFAULT_ADMIN_NAME,
'email' => self::DEFAULT_ADMIN_EMAIL,
'password' => Hash::make(self::DEFAULT_ADMIN_PASSWORD),
]);
$user->markEmailAsVerified();
$adminRole = Utils::getRoleModel()::firstOrCreate(
['name' => 'admin'],
['guard_name' => Utils::getFilamentAuthGuard()]
);
$adminRole->syncPermissions([]);
$user->assignRole('admin');
$this->comment(sprintf('Log in user with email %s and password %s', self::DEFAULT_ADMIN_EMAIL, self::DEFAULT_ADMIN_PASSWORD));
return $user;
}
private function setUpUserAccount()
{
$user = Octo::getUserModel()::forceCreate([
'name' => self::DEFAULT_USER_NAME,
'email' => self::DEFAULT_USER_EMAIL,
'password' => Hash::make(self::DEFAULT_USER_PASSWORD),
]);
$user->markEmailAsVerified();
$userRole = Utils::getRoleModel()::firstOrCreate(
['name' => Utils::getPanelUserRoleName()],
['guard_name' => Utils::getFilamentAuthGuard()]
);
$userRole->syncPermissions([]);
$user->assignRole(Utils::getPanelUserRoleName());
$this->comment(sprintf('Log in user with email %s and password %s', self::DEFAULT_USER_EMAIL, self::DEFAULT_USER_PASSWORD));
return $user;
}
public function factoryData()
{
}
}