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\Comment; |
15
|
|
|
use Gitamin\Models\Issue; |
16
|
|
|
use Gitamin\Models\Owner; |
17
|
|
|
use Gitamin\Models\Project; |
18
|
|
|
use Gitamin\Models\Setting; |
19
|
|
|
use Gitamin\Models\Subscriber; |
20
|
|
|
use Gitamin\Models\User; |
21
|
|
|
use Illuminate\Console\Command; |
22
|
|
|
use Illuminate\Console\ConfirmableTrait; |
23
|
|
|
use Symfony\Component\Console\Input\InputOption; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* This is the demo seeder command. |
27
|
|
|
*/ |
28
|
|
|
class DemoSeederCommand extends Command |
29
|
|
|
{ |
30
|
|
|
use ConfirmableTrait; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* The console command name. |
34
|
|
|
* |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
protected $name = 'gitamin:seed'; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* The console command description. |
41
|
|
|
* |
42
|
|
|
* @var string |
43
|
|
|
*/ |
44
|
|
|
protected $description = 'Seeds Gitamin with demo data.'; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Execute the console command. |
48
|
|
|
* |
49
|
|
|
* @return void |
50
|
|
|
*/ |
51
|
|
|
public function fire() |
52
|
|
|
{ |
53
|
|
|
if (!$this->confirmToProceed()) { |
54
|
|
|
return; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$this->seedOwners(); |
58
|
|
|
$this->seedProjects(); |
59
|
|
|
$this->seedIssues(); |
60
|
|
|
$this->seedComments(); |
61
|
|
|
$this->seedSettings(); |
62
|
|
|
$this->seedSubscribers(); |
63
|
|
|
$this->seedUsers(); |
64
|
|
|
|
65
|
|
|
$this->info('Database seeded with demo data successfully!'); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Seed the project teams table. |
70
|
|
|
* |
71
|
|
|
* @return void |
72
|
|
|
*/ |
73
|
|
|
protected function seedOwners() |
74
|
|
|
{ |
75
|
|
|
$defaultOwners = [ |
76
|
|
|
[ |
77
|
|
|
'name' => 'Baidu', |
78
|
|
|
'path' => 'Baidu', |
79
|
|
|
'description' => 'www.baidu.com', |
80
|
|
|
'type' => 'Group', |
81
|
|
|
], |
82
|
|
|
[ |
83
|
|
|
'name' => 'Alibaba', |
84
|
|
|
'path' => 'Alibaba', |
85
|
|
|
'description' => 'www.alibaba.com', |
86
|
|
|
'type' => 'Group', |
87
|
|
|
], |
88
|
|
|
[ |
89
|
|
|
'name' => 'Tencent', |
90
|
|
|
'path' => 'Tencent', |
91
|
|
|
'description' => 'www.qq.com', |
92
|
|
|
'type' => 'Group', |
93
|
|
|
], |
94
|
|
|
[ |
95
|
|
|
'name' => 'demo', |
96
|
|
|
'path' => 'demo', |
97
|
|
|
'description' => '', |
98
|
|
|
'type' => 'User', |
99
|
|
|
], |
100
|
|
|
]; |
101
|
|
|
|
102
|
|
|
Owner::truncate(); |
103
|
|
|
|
104
|
|
|
foreach ($defaultOwners as $owner) { |
105
|
|
|
Owner::create($owner); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Seed the projects table. |
111
|
|
|
* |
112
|
|
|
* @return void |
113
|
|
|
*/ |
114
|
|
|
protected function seedProjects() |
115
|
|
|
{ |
116
|
|
|
$defaultProjects = [ |
117
|
|
|
[ |
118
|
|
|
'name' => 'API', |
119
|
|
|
'description' => 'Used by third-parties to connect to us', |
120
|
|
|
'visibility_level' => 0, |
121
|
|
|
'owner_id' => 1, |
122
|
|
|
'path' => 'api', |
123
|
|
|
], [ |
124
|
|
|
'name' => 'Documentation', |
125
|
|
|
'description' => 'Kindly powered by Readme.io', |
126
|
|
|
'visibility_level' => 1, |
127
|
|
|
'owner_id' => 2, |
128
|
|
|
'path' => 'doc', |
129
|
|
|
], [ |
130
|
|
|
'name' => 'Website', |
131
|
|
|
'description' => 'Tencent Holdings Limited is a Chinese investment holding company', |
132
|
|
|
'visibility_level' => 1, |
133
|
|
|
'owner_id' => 3, |
134
|
|
|
'path' => 'website', |
135
|
|
|
], [ |
136
|
|
|
'name' => 'Blog', |
137
|
|
|
'description' => 'The Gitamin Blog.', |
138
|
|
|
'visibility_level' => 1, |
139
|
|
|
'owner_id' => 4, |
140
|
|
|
'path' => 'blog', |
141
|
|
|
], |
142
|
|
|
]; |
143
|
|
|
|
144
|
|
|
Project::truncate(); |
145
|
|
|
|
146
|
|
|
foreach ($defaultProjects as $project) { |
147
|
|
|
Project::create($project); |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Seed the issues table. |
153
|
|
|
* |
154
|
|
|
* @return void |
155
|
|
|
*/ |
156
|
|
|
protected function seedIssues() |
157
|
|
|
{ |
158
|
|
|
$defaultIssues = [ |
159
|
|
|
[ |
160
|
|
|
'title' => 'Awesome', |
161
|
|
|
'description' => ':+1: We totally nailed the fix.', |
162
|
|
|
'author_id' => 1, |
163
|
|
|
'project_id' => 1, |
164
|
|
|
], |
165
|
|
|
[ |
166
|
|
|
'title' => 'Monitoring the fix', |
167
|
|
|
'description' => ":ship: We've deployed a fix.", |
168
|
|
|
'author_id' => 3, |
169
|
|
|
'project_id' => 2, |
170
|
|
|
], |
171
|
|
|
[ |
172
|
|
|
'title' => 'Update', |
173
|
|
|
'description' => "We've identified the problem. Our engineers are currently looking at it.", |
174
|
|
|
'author_id' => 2, |
175
|
|
|
'project_id' => 1, |
176
|
|
|
], |
177
|
|
|
[ |
178
|
|
|
'title' => 'Test Issue', |
179
|
|
|
'description' => 'Something went wrong, with something or another.', |
180
|
|
|
'author_id' => 1, |
181
|
|
|
'project_id' => 2, |
182
|
|
|
], |
183
|
|
|
[ |
184
|
|
|
'title' => 'Investigating the API', |
185
|
|
|
'description' => ':zap: We\'ve seen high response times from our API. It looks to be fixing itself as time goes on.', |
186
|
|
|
'author_id' => 1, |
187
|
|
|
'project_id' => 3, |
188
|
|
|
], |
189
|
|
|
]; |
190
|
|
|
|
191
|
|
|
Issue::truncate(); |
192
|
|
|
|
193
|
|
|
foreach ($defaultIssues as $issue) { |
194
|
|
|
Issue::create($issue); |
195
|
|
|
} |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* Seed the comments table. |
200
|
|
|
* |
201
|
|
|
* @return void |
202
|
|
|
*/ |
203
|
|
|
protected function seedComments() |
204
|
|
|
{ |
205
|
|
|
$defaultComments = [ |
206
|
|
|
[ |
207
|
|
|
'message' => ':+1: We totally nailed the fix.', |
208
|
|
|
'target_type' => 'Issue', |
209
|
|
|
'target_id' => 3, |
210
|
|
|
'author_id' => 1, |
211
|
|
|
'project_id' => 1, |
212
|
|
|
], |
213
|
|
|
[ |
214
|
|
|
'message' => ":ship: We've deployed a fix.", |
215
|
|
|
'target_type' => 'MergeRequest', |
216
|
|
|
'target_id' => 1, |
217
|
|
|
'author_id' => 3, |
218
|
|
|
'project_id' => 2, |
219
|
|
|
], |
220
|
|
|
[ |
221
|
|
|
'message' => "We've identified the problem. Our engineers are currently looking at it.", |
222
|
|
|
'target_type' => 'Issue', |
223
|
|
|
'target_id' => 1, |
224
|
|
|
'author_id' => 2, |
225
|
|
|
'project_id' => 1, |
226
|
|
|
], |
227
|
|
|
[ |
228
|
|
|
'message' => 'Something went wrong, with something or another.', |
229
|
|
|
'target_type' => 'Issue', |
230
|
|
|
'target_id' => 1, |
231
|
|
|
'author_id' => 1, |
232
|
|
|
'project_id' => 2, |
233
|
|
|
], |
234
|
|
|
[ |
235
|
|
|
'message' => ':zap: We\'ve seen high response times from our API. It looks to be fixing itself as time goes on.', |
236
|
|
|
'target_type' => 'MergeRequest', |
237
|
|
|
'target_id' => 1, |
238
|
|
|
'author_id' => 1, |
239
|
|
|
'project_id' => 3, |
240
|
|
|
], |
241
|
|
|
]; |
242
|
|
|
|
243
|
|
|
Comment::truncate(); |
244
|
|
|
|
245
|
|
|
foreach ($defaultComments as $comment) { |
246
|
|
|
Comment::create($comment); |
247
|
|
|
} |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* Seed the settings table. |
252
|
|
|
* |
253
|
|
|
* @return void |
254
|
|
|
*/ |
255
|
|
|
protected function seedSettings() |
256
|
|
|
{ |
257
|
|
|
$defaultSettings = [ |
258
|
|
|
[ |
259
|
|
|
'name' => 'app_name', |
260
|
|
|
'value' => 'Gitamin Demo', |
261
|
|
|
], |
262
|
|
|
[ |
263
|
|
|
'name' => 'app_domain', |
264
|
|
|
'value' => 'https://demo.gitamin.com', |
265
|
|
|
], |
266
|
|
|
[ |
267
|
|
|
'name' => 'app_locale', |
268
|
|
|
'value' => 'en', |
269
|
|
|
], |
270
|
|
|
[ |
271
|
|
|
'name' => 'app_timezone', |
272
|
|
|
'value' => 'Asia/Shanghai', |
273
|
|
|
], |
274
|
|
|
[ |
275
|
|
|
'name' => 'app_issue_days', |
276
|
|
|
'value' => '7', |
277
|
|
|
], |
278
|
|
|
]; |
279
|
|
|
|
280
|
|
|
Setting::truncate(); |
281
|
|
|
|
282
|
|
|
foreach ($defaultSettings as $setting) { |
283
|
|
|
Setting::create($setting); |
284
|
|
|
} |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* Seed the subscribers. |
289
|
|
|
* |
290
|
|
|
* @return void |
291
|
|
|
*/ |
292
|
|
|
protected function seedSubscribers() |
293
|
|
|
{ |
294
|
|
|
Subscriber::truncate(); |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
/** |
298
|
|
|
* Seed the users table. |
299
|
|
|
* |
300
|
|
|
* @return void |
301
|
|
|
*/ |
302
|
|
|
protected function seedUsers() |
303
|
|
|
{ |
304
|
|
|
$users = [ |
305
|
|
|
[ |
306
|
|
|
'username' => 'demo', |
307
|
|
|
'password' => 'demo', |
308
|
|
|
'email' => '[email protected]', |
309
|
|
|
'level' => 1, |
310
|
|
|
'api_key' => '9yMHsdioQosnyVK4iCVR', |
311
|
|
|
], |
312
|
|
|
]; |
313
|
|
|
|
314
|
|
|
User::truncate(); |
315
|
|
|
|
316
|
|
|
foreach ($users as $user) { |
317
|
|
|
User::create($user); |
318
|
|
|
} |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
/** |
322
|
|
|
* Get the console command options. |
323
|
|
|
* |
324
|
|
|
* @return array |
325
|
|
|
*/ |
326
|
|
|
protected function getOptions() |
327
|
|
|
{ |
328
|
|
|
return [ |
329
|
|
|
['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'], |
330
|
|
|
]; |
331
|
|
|
} |
332
|
|
|
} |
333
|
|
|
|