|
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 Corp', |
|
78
|
|
|
'path' => 'Baidu', |
|
79
|
|
|
'description' => 'www.baidu.com', |
|
80
|
|
|
'type' => 'Group', |
|
81
|
|
|
], |
|
82
|
|
|
]; |
|
83
|
|
|
|
|
84
|
|
|
Owner::truncate(); |
|
85
|
|
|
|
|
86
|
|
|
foreach ($defaultOwners as $owner) { |
|
87
|
|
|
Owner::create($owner); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Seed the projects table. |
|
93
|
|
|
* |
|
94
|
|
|
* @return void |
|
95
|
|
|
*/ |
|
96
|
|
|
protected function seedProjects() |
|
97
|
|
|
{ |
|
98
|
|
|
$defaultProjects = [ |
|
99
|
|
|
[ |
|
100
|
|
|
'name' => 'API', |
|
101
|
|
|
'description' => 'Used by third-parties to connect to us', |
|
102
|
|
|
'visibility_level' => 0, |
|
103
|
|
|
'owner_id' => 1, |
|
104
|
|
|
'path' => 'Gitamin', |
|
105
|
|
|
], [ |
|
106
|
|
|
'name' => 'Documentation', |
|
107
|
|
|
'description' => 'Kindly powered by Readme.io', |
|
108
|
|
|
'visibility_level' => 1, |
|
109
|
|
|
'owner_id' => 1, |
|
110
|
|
|
'path' => 'Baidu', |
|
111
|
|
|
], [ |
|
112
|
|
|
'name' => 'Website', |
|
113
|
|
|
'description' => '', |
|
114
|
|
|
'visibility_level' => 1, |
|
115
|
|
|
'owner_id' => 1, |
|
116
|
|
|
'path' => 'Alibaba', |
|
117
|
|
|
], [ |
|
118
|
|
|
'name' => 'Blog', |
|
119
|
|
|
'description' => 'The Gitamin Blog.', |
|
120
|
|
|
'visibility_level' => 1, |
|
121
|
|
|
'owner_id' => 1, |
|
122
|
|
|
'path' => '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
|
|
|
'title' => 'Awesome', |
|
143
|
|
|
'description' => ':+1: We totally nailed the fix.', |
|
144
|
|
|
'author_id' => 1, |
|
145
|
|
|
'project_id' => 1, |
|
146
|
|
|
], |
|
147
|
|
|
[ |
|
148
|
|
|
'title' => 'Monitoring the fix', |
|
149
|
|
|
'description' => ":ship: We've deployed a fix.", |
|
150
|
|
|
'author_id' => 3, |
|
151
|
|
|
'project_id' => 2, |
|
152
|
|
|
], |
|
153
|
|
|
[ |
|
154
|
|
|
'title' => 'Update', |
|
155
|
|
|
'description' => "We've identified the problem. Our engineers are currently looking at it.", |
|
156
|
|
|
'author_id' => 2, |
|
157
|
|
|
'project_id' => 1, |
|
158
|
|
|
], |
|
159
|
|
|
[ |
|
160
|
|
|
'title' => 'Test Issue', |
|
161
|
|
|
'description' => 'Something went wrong, with something or another.', |
|
162
|
|
|
'author_id' => 1, |
|
163
|
|
|
'project_id' => 2, |
|
164
|
|
|
], |
|
165
|
|
|
[ |
|
166
|
|
|
'title' => 'Investigating the API', |
|
167
|
|
|
'description' => ':zap: We\'ve seen high response times from our API. It looks to be fixing itself as time goes on.', |
|
168
|
|
|
'author_id' => 1, |
|
169
|
|
|
'project_id' => 3, |
|
170
|
|
|
], |
|
171
|
|
|
]; |
|
172
|
|
|
|
|
173
|
|
|
Issue::truncate(); |
|
174
|
|
|
|
|
175
|
|
|
foreach ($defaultIssues as $issue) { |
|
176
|
|
|
Issue::create($issue); |
|
177
|
|
|
} |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* Seed the comments table. |
|
182
|
|
|
* |
|
183
|
|
|
* @return void |
|
184
|
|
|
*/ |
|
185
|
|
|
protected function seedComments() |
|
186
|
|
|
{ |
|
187
|
|
|
$defaultComments = [ |
|
188
|
|
|
[ |
|
189
|
|
|
'message' => ':+1: We totally nailed the fix.', |
|
190
|
|
|
'target_type' => 'Issue', |
|
191
|
|
|
'target_id' => 3, |
|
192
|
|
|
'author_id' => 1, |
|
193
|
|
|
'project_id' => 1, |
|
194
|
|
|
], |
|
195
|
|
|
[ |
|
196
|
|
|
'message' => ":ship: We've deployed a fix.", |
|
197
|
|
|
'target_type' => 'MergeRequest', |
|
198
|
|
|
'target_id' => 1, |
|
199
|
|
|
'author_id' => 3, |
|
200
|
|
|
'project_id' => 2, |
|
201
|
|
|
], |
|
202
|
|
|
[ |
|
203
|
|
|
'message' => "We've identified the problem. Our engineers are currently looking at it.", |
|
204
|
|
|
'target_type' => 'Issue', |
|
205
|
|
|
'target_id' => 1, |
|
206
|
|
|
'author_id' => 2, |
|
207
|
|
|
'project_id' => 1, |
|
208
|
|
|
], |
|
209
|
|
|
[ |
|
210
|
|
|
'message' => 'Something went wrong, with something or another.', |
|
211
|
|
|
'target_type' => 'Issue', |
|
212
|
|
|
'target_id' => 1, |
|
213
|
|
|
'author_id' => 1, |
|
214
|
|
|
'project_id' => 2, |
|
215
|
|
|
], |
|
216
|
|
|
[ |
|
217
|
|
|
'message' => ':zap: We\'ve seen high response times from our API. It looks to be fixing itself as time goes on.', |
|
218
|
|
|
'target_type' => 'MergeRequest', |
|
219
|
|
|
'target_id' => 1, |
|
220
|
|
|
'author_id' => 1, |
|
221
|
|
|
'project_id' => 3, |
|
222
|
|
|
], |
|
223
|
|
|
]; |
|
224
|
|
|
|
|
225
|
|
|
Comment::truncate(); |
|
226
|
|
|
|
|
227
|
|
|
foreach ($defaultComments as $comment) { |
|
228
|
|
|
Comment::create($comment); |
|
229
|
|
|
} |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
|
/** |
|
233
|
|
|
* Seed the settings table. |
|
234
|
|
|
* |
|
235
|
|
|
* @return void |
|
236
|
|
|
*/ |
|
237
|
|
|
protected function seedSettings() |
|
238
|
|
|
{ |
|
239
|
|
|
$defaultSettings = [ |
|
240
|
|
|
[ |
|
241
|
|
|
'name' => 'app_name', |
|
242
|
|
|
'value' => 'Gitamin Demo', |
|
243
|
|
|
], |
|
244
|
|
|
[ |
|
245
|
|
|
'name' => 'app_domain', |
|
246
|
|
|
'value' => 'https://demo.gitamin.com', |
|
247
|
|
|
], |
|
248
|
|
|
[ |
|
249
|
|
|
'name' => 'app_locale', |
|
250
|
|
|
'value' => 'en', |
|
251
|
|
|
], |
|
252
|
|
|
[ |
|
253
|
|
|
'name' => 'app_timezone', |
|
254
|
|
|
'value' => 'Asia/Shanghai', |
|
255
|
|
|
], |
|
256
|
|
|
[ |
|
257
|
|
|
'name' => 'app_issue_days', |
|
258
|
|
|
'value' => '7', |
|
259
|
|
|
], |
|
260
|
|
|
]; |
|
261
|
|
|
|
|
262
|
|
|
Setting::truncate(); |
|
263
|
|
|
|
|
264
|
|
|
foreach ($defaultSettings as $setting) { |
|
265
|
|
|
Setting::create($setting); |
|
266
|
|
|
} |
|
267
|
|
|
} |
|
268
|
|
|
|
|
269
|
|
|
/** |
|
270
|
|
|
* Seed the subscribers. |
|
271
|
|
|
* |
|
272
|
|
|
* @return void |
|
273
|
|
|
*/ |
|
274
|
|
|
protected function seedSubscribers() |
|
275
|
|
|
{ |
|
276
|
|
|
Subscriber::truncate(); |
|
277
|
|
|
} |
|
278
|
|
|
|
|
279
|
|
|
/** |
|
280
|
|
|
* Seed the users table. |
|
281
|
|
|
* |
|
282
|
|
|
* @return void |
|
283
|
|
|
*/ |
|
284
|
|
|
protected function seedUsers() |
|
285
|
|
|
{ |
|
286
|
|
|
$users = [ |
|
287
|
|
|
[ |
|
288
|
|
|
'username' => 'demo', |
|
289
|
|
|
'password' => 'demo', |
|
290
|
|
|
'email' => '[email protected]', |
|
291
|
|
|
'level' => 1, |
|
292
|
|
|
'api_key' => '9yMHsdioQosnyVK4iCVR', |
|
293
|
|
|
], |
|
294
|
|
|
]; |
|
295
|
|
|
|
|
296
|
|
|
User::truncate(); |
|
297
|
|
|
|
|
298
|
|
|
foreach ($users as $user) { |
|
299
|
|
|
User::create($user); |
|
300
|
|
|
} |
|
301
|
|
|
} |
|
302
|
|
|
|
|
303
|
|
|
/** |
|
304
|
|
|
* Get the console command options. |
|
305
|
|
|
* |
|
306
|
|
|
* @return array |
|
307
|
|
|
*/ |
|
308
|
|
|
protected function getOptions() |
|
309
|
|
|
{ |
|
310
|
|
|
return [ |
|
311
|
|
|
['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'], |
|
312
|
|
|
]; |
|
313
|
|
|
} |
|
314
|
|
|
} |
|
315
|
|
|
|