1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Gitamin. |
5
|
|
|
* |
6
|
|
|
* Copyright (C) 2015-2016 The Gitamin Team |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Gitamin\Console\Commands; |
13
|
|
|
|
14
|
|
|
use Gitamin\Models\Issue; |
15
|
|
|
use Gitamin\Models\Project; |
16
|
|
|
use Gitamin\Models\ProjectNamespace; |
17
|
|
|
use Gitamin\Models\Setting; |
18
|
|
|
use Gitamin\Models\Subscriber; |
19
|
|
|
use Gitamin\Models\User; |
20
|
|
|
use Illuminate\Console\Command; |
21
|
|
|
use Illuminate\Console\ConfirmableTrait; |
22
|
|
|
use Symfony\Component\Console\Input\InputOption; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* This is the demo seeder command. |
26
|
|
|
*/ |
27
|
|
|
class DemoSeederCommand extends Command |
28
|
|
|
{ |
29
|
|
|
use ConfirmableTrait; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* The console command name. |
33
|
|
|
* |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
protected $name = 'gitamin:seed'; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* The console command description. |
40
|
|
|
* |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
protected $description = 'Seeds Gitamin with demo data.'; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Execute the console command. |
47
|
|
|
* |
48
|
|
|
* @return void |
49
|
|
|
*/ |
50
|
|
|
public function fire() |
51
|
|
|
{ |
52
|
|
|
if (!$this->confirmToProceed()) { |
53
|
|
|
return; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
$this->seedProjectNamespaces(); |
57
|
|
|
$this->seedProjects(); |
58
|
|
|
$this->seedIssues(); |
59
|
|
|
$this->seedSettings(); |
60
|
|
|
$this->seedSubscribers(); |
61
|
|
|
$this->seedUsers(); |
62
|
|
|
|
63
|
|
|
$this->info('Database seeded with demo data successfully!'); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Seed the project teams table. |
68
|
|
|
* |
69
|
|
|
* @return void |
70
|
|
|
*/ |
71
|
|
|
protected function seedProjectNamespaces() |
72
|
|
|
{ |
73
|
|
|
$defaultNamespaces = [ |
74
|
|
|
[ |
75
|
|
|
'name' => 'Baidu Corp', |
76
|
|
|
'path' => 'Baidu', |
77
|
|
|
], |
78
|
|
|
]; |
79
|
|
|
|
80
|
|
|
ProjectNamespace::truncate(); |
81
|
|
|
|
82
|
|
|
foreach ($defaultNamespaces as $projectNamespace) { |
83
|
|
|
ProjectNamespace::create($projectNamespace); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Seed the projects table. |
89
|
|
|
* |
90
|
|
|
* @return void |
91
|
|
|
*/ |
92
|
|
|
protected function seedProjects() |
93
|
|
|
{ |
94
|
|
|
$defaultProjects = [ |
95
|
|
|
[ |
96
|
|
|
'name' => 'API', |
97
|
|
|
'description' => 'Used by third-parties to connect to us', |
98
|
|
|
'status' => 1, |
99
|
|
|
'order' => 0, |
100
|
|
|
'team_id' => 0, |
101
|
|
|
'slug' => 'Gitamin', |
102
|
|
|
], [ |
103
|
|
|
'name' => 'Documentation', |
104
|
|
|
'description' => 'Kindly powered by Readme.io', |
105
|
|
|
'status' => 1, |
106
|
|
|
'order' => 0, |
107
|
|
|
'team_id' => 1, |
108
|
|
|
'slug' => 'Baidu', |
109
|
|
|
], [ |
110
|
|
|
'name' => 'Website', |
111
|
|
|
'description' => '', |
112
|
|
|
'status' => 1, |
113
|
|
|
'order' => 0, |
114
|
|
|
'team_id' => 1, |
115
|
|
|
'slug' => 'Alibaba', |
116
|
|
|
], [ |
117
|
|
|
'name' => 'Blog', |
118
|
|
|
'description' => 'The Gitamin Blog.', |
119
|
|
|
'status' => 1, |
120
|
|
|
'order' => 0, |
121
|
|
|
'team_id' => 1, |
122
|
|
|
'slug' => 'Tencent', |
123
|
|
|
], |
124
|
|
|
]; |
125
|
|
|
|
126
|
|
|
Project::truncate(); |
127
|
|
|
|
128
|
|
|
foreach ($defaultProjects as $project) { |
129
|
|
|
Project::create($project); |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Seed the issues table. |
135
|
|
|
* |
136
|
|
|
* @return void |
137
|
|
|
*/ |
138
|
|
|
protected function seedIssues() |
139
|
|
|
{ |
140
|
|
|
$defaultIssues = [ |
141
|
|
|
[ |
142
|
|
|
'name' => 'Awesome', |
143
|
|
|
'message' => ':+1: We totally nailed the fix.', |
144
|
|
|
'status' => 4, |
145
|
|
|
'project_id' => 0, |
146
|
|
|
'scheduled_at' => null, |
147
|
|
|
'visible' => 1, |
148
|
|
|
], |
149
|
|
|
[ |
150
|
|
|
'name' => 'Monitoring the fix', |
151
|
|
|
'message' => ":ship: We've deployed a fix.", |
152
|
|
|
'status' => 3, |
153
|
|
|
'project_id' => 0, |
154
|
|
|
'scheduled_at' => null, |
155
|
|
|
'visible' => 1, |
156
|
|
|
], |
157
|
|
|
[ |
158
|
|
|
'name' => 'Update', |
159
|
|
|
'message' => "We've identified the problem. Our engineers are currently looking at it.", |
160
|
|
|
'status' => 2, |
161
|
|
|
'project_id' => 0, |
162
|
|
|
'scheduled_at' => null, |
163
|
|
|
'visible' => 1, |
164
|
|
|
], |
165
|
|
|
[ |
166
|
|
|
'name' => 'Test Issue', |
167
|
|
|
'message' => 'Something went wrong, with something or another.', |
168
|
|
|
'status' => 1, |
169
|
|
|
'project_id' => 0, |
170
|
|
|
'scheduled_at' => null, |
171
|
|
|
'visible' => 1, |
172
|
|
|
], |
173
|
|
|
[ |
174
|
|
|
'name' => 'Investigating the API', |
175
|
|
|
'message' => ':zap: We\'ve seen high response times from our API. It looks to be fixing itself as time goes on.', |
176
|
|
|
'status' => 1, |
177
|
|
|
'project_id' => 1, |
178
|
|
|
'scheduled_at' => null, |
179
|
|
|
'visible' => 1, |
180
|
|
|
], |
181
|
|
|
]; |
182
|
|
|
|
183
|
|
|
Issue::truncate(); |
184
|
|
|
|
185
|
|
|
foreach ($defaultIssues as $issue) { |
186
|
|
|
Issue::create($issue); |
187
|
|
|
} |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Seed the settings table. |
192
|
|
|
* |
193
|
|
|
* @return void |
194
|
|
|
*/ |
195
|
|
|
protected function seedSettings() |
196
|
|
|
{ |
197
|
|
|
$defaultSettings = [ |
198
|
|
|
[ |
199
|
|
|
'name' => 'app_name', |
200
|
|
|
'value' => 'Gitamin Demo', |
201
|
|
|
], |
202
|
|
|
[ |
203
|
|
|
'name' => 'app_domain', |
204
|
|
|
'value' => 'https://demo.gitaminhq.io', |
205
|
|
|
], |
206
|
|
|
[ |
207
|
|
|
'name' => 'app_locale', |
208
|
|
|
'value' => 'en', |
209
|
|
|
], |
210
|
|
|
[ |
211
|
|
|
'name' => 'app_timezone', |
212
|
|
|
'value' => 'Europe/London', |
213
|
|
|
], |
214
|
|
|
[ |
215
|
|
|
'name' => 'app_issue_days', |
216
|
|
|
'value' => '7', |
217
|
|
|
], |
218
|
|
|
]; |
219
|
|
|
|
220
|
|
|
Setting::truncate(); |
221
|
|
|
|
222
|
|
|
foreach ($defaultSettings as $setting) { |
223
|
|
|
Setting::create($setting); |
224
|
|
|
} |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* Seed the subscribers. |
229
|
|
|
* |
230
|
|
|
* @return void |
231
|
|
|
*/ |
232
|
|
|
protected function seedSubscribers() |
233
|
|
|
{ |
234
|
|
|
Subscriber::truncate(); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* Seed the users table. |
239
|
|
|
* |
240
|
|
|
* @return void |
241
|
|
|
*/ |
242
|
|
|
protected function seedUsers() |
243
|
|
|
{ |
244
|
|
|
$users = [ |
245
|
|
|
[ |
246
|
|
|
'username' => 'test', |
247
|
|
|
'password' => 'test123', |
248
|
|
|
'email' => '[email protected]', |
249
|
|
|
'level' => 1, |
250
|
|
|
'api_key' => '9yMHsdioQosnyVK4iCVR', |
251
|
|
|
], |
252
|
|
|
]; |
253
|
|
|
|
254
|
|
|
User::truncate(); |
255
|
|
|
|
256
|
|
|
foreach ($users as $user) { |
257
|
|
|
User::create($user); |
258
|
|
|
} |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
/** |
262
|
|
|
* Get the console command options. |
263
|
|
|
* |
264
|
|
|
* @return array |
265
|
|
|
*/ |
266
|
|
|
protected function getOptions() |
267
|
|
|
{ |
268
|
|
|
return [ |
269
|
|
|
['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'], |
270
|
|
|
]; |
271
|
|
|
} |
272
|
|
|
} |
273
|
|
|
|