DemoSeederCommand   A
last analyzed

Complexity

Total Complexity 18

Size/Duplication

Total Lines 329
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 9

Importance

Changes 9
Bugs 4 Features 2
Metric Value
wmc 18
c 9
b 4
f 2
lcom 1
cbo 9
dl 0
loc 329
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A fire() 0 17 2
B seedOwners() 0 39 2
B seedProjects() 0 40 2
B seedIssues() 0 41 2
B seedComments() 0 46 2
B seedMoments() 0 27 2
B seedSettings() 0 31 2
A seedSubscribers() 0 4 1
A seedUsers() 0 18 2
A getOptions() 0 6 1
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\Moment;
17
use Gitamin\Models\Owner;
18
use Gitamin\Models\Project;
19
use Gitamin\Models\Setting;
20
use Gitamin\Models\Subscriber;
21
use Gitamin\Models\User;
22
use Illuminate\Console\Command;
23
use Illuminate\Console\ConfirmableTrait;
24
use Symfony\Component\Console\Input\InputOption;
25
26
/**
27
 * This is the demo seeder command.
28
 */
29
class DemoSeederCommand extends Command
30
{
31
    use ConfirmableTrait;
32
33
    /**
34
     * The console command name.
35
     *
36
     * @var string
37
     */
38
    protected $name = 'gitamin:seed';
39
40
    /**
41
     * The console command description.
42
     *
43
     * @var string
44
     */
45
    protected $description = 'Seeds Gitamin with demo data.';
46
47
    /**
48
     * Execute the console command.
49
     */
50
    public function fire()
51
    {
52
        if (! $this->confirmToProceed()) {
53
            return;
54
        }
55
56
        $this->seedOwners();
57
        $this->seedProjects();
58
        $this->seedIssues();
59
        $this->seedComments();
60
        $this->seedMoments();
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
    protected function seedOwners()
72
    {
73
        $defaultOwners = [
74
            [
75
                'name' => 'Baidu',
76
                'path' => 'Baidu',
77
                'user_id' => 1,
78
                'description' => 'www.baidu.com',
79
                'type' => 'Group',
80
            ],
81
            [
82
                'name' => 'Alibaba',
83
                'path' => 'Alibaba',
84
                'user_id' => 1,
85
                'description' => 'www.alibaba.com',
86
                'type' => 'Group',
87
            ],
88
            [
89
                'name' => 'Tencent',
90
                'path' => 'Tencent',
91
                'user_id' => 1,
92
                'description' => 'www.qq.com',
93
                'type' => 'Group',
94
            ],
95
            [
96
                'name' => 'demo',
97
                'path' => 'demo',
98
                'user_id' => 1,
99
                'description' => '',
100
                'type' => 'User',
101
            ],
102
        ];
103
104
        Owner::truncate();
105
106
        foreach ($defaultOwners as $owner) {
107
            Owner::create($owner);
108
        }
109
    }
110
111
    /**
112
     * Seed the projects table.
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
                'creator_id' => 1,
123
                'path' => 'api',
124
            ], [
125
                'name' => 'Documentation',
126
                'description' => 'Kindly powered by Readme.io',
127
                'visibility_level' => 1,
128
                'owner_id' => 2,
129
                'creator_id' => 1,
130
                'path' => 'doc',
131
            ], [
132
                'name' => 'Website',
133
                'description' => 'Tencent Holdings Limited is a Chinese investment holding company',
134
                'visibility_level' => 1,
135
                'owner_id' => 3,
136
                'creator_id' => 1,
137
                'path' => 'website',
138
            ], [
139
                'name' => 'Blog',
140
                'description' => 'The Gitamin Blog.',
141
                'visibility_level' => 1,
142
                'owner_id' => 4,
143
                'creator_id' => 1,
144
                'path' => 'blog',
145
            ],
146
        ];
147
148
        Project::truncate();
149
150
        foreach ($defaultProjects as $project) {
151
            Project::create($project);
152
        }
153
    }
154
155
    /**
156
     * Seed the issues table.
157
     */
158
    protected function seedIssues()
159
    {
160
        $defaultIssues = [
161
            [
162
                'title' => 'Awesome',
163
                'description' => ':+1: We totally nailed the fix.',
164
                'author_id' => 1,
165
                'project_id' => 1,
166
            ],
167
            [
168
                'title' => 'Monitoring the fix',
169
                'description' => ":ship: We've deployed a fix.",
170
                'author_id' => 3,
171
                'project_id' => 2,
172
            ],
173
            [
174
                'title' => 'Update',
175
                'description' => "We've identified the problem. Our engineers are currently looking at it.",
176
                'author_id' => 2,
177
                'project_id' => 1,
178
            ],
179
            [
180
                'title' => 'Test Issue',
181
                'description' => 'Something went wrong, with something or another.',
182
                'author_id' => 1,
183
                'project_id' => 2,
184
            ],
185
            [
186
                'title' => 'Investigating the API',
187
                'description' => ':zap: We\'ve seen high response times from our API. It looks to be fixing itself as time goes on.',
188
                'author_id' => 1,
189
                'project_id' => 3,
190
            ],
191
        ];
192
193
        Issue::truncate();
194
195
        foreach ($defaultIssues as $issue) {
196
            Issue::create($issue);
197
        }
198
    }
199
200
    /**
201
     * Seed the comments table.
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 comments table.
252
     */
253
    protected function seedMoments()
254
    {
255
        $defaultMoments = [
256
            [
257
                'message' => ':+1: We totally nailed the fix.',
258
                'target_type' => 'Issue',
259
                'target_id' => 3,
260
                'action' => Moment::COMMENTED,
261
                'author_id' => 1,
262
                'project_id' => 1,
263
            ],
264
            [
265
                'message' => ":ship: We've deployed a fix.",
266
                'target_type' => 'Issue',
267
                'target_id' => 2,
268
                'action' => Moment::CREATED,
269
                'author_id' => 1,
270
                'project_id' => 2,
271
            ],
272
        ];
273
274
        Moment::truncate();
275
276
        foreach ($defaultMoments as $moment) {
277
            Moment::create($moment);
278
        }
279
    }
280
281
    /**
282
     * Seed the settings table.
283
     */
284
    protected function seedSettings()
285
    {
286
        $defaultSettings = [
287
            [
288
                'name' => 'app_name',
289
                'value' => 'Gitamin Demo',
290
            ],
291
            [
292
                'name' => 'app_domain',
293
                'value' => 'https://demo.gitamin.com',
294
            ],
295
            [
296
                'name' => 'app_locale',
297
                'value' => 'en',
298
            ],
299
            [
300
                'name' => 'app_timezone',
301
                'value' => 'Asia/Shanghai',
302
            ],
303
            [
304
                'name' => 'app_issue_days',
305
                'value' => '7',
306
            ],
307
        ];
308
309
        Setting::truncate();
310
311
        foreach ($defaultSettings as $setting) {
312
            Setting::create($setting);
313
        }
314
    }
315
316
    /**
317
     * Seed the subscribers.
318
     */
319
    protected function seedSubscribers()
320
    {
321
        Subscriber::truncate();
322
    }
323
324
    /**
325
     * Seed the users table.
326
     */
327
    protected function seedUsers()
328
    {
329
        $users = [
330
            [
331
                'username' => 'demo',
332
                'password' => 'demo',
333
                'email' => '[email protected]',
334
                'level' => 1,
335
                'api_key' => '9yMHsdioQosnyVK4iCVR',
336
            ],
337
        ];
338
339
        User::truncate();
340
341
        foreach ($users as $user) {
342
            User::create($user);
343
        }
344
    }
345
346
    /**
347
     * Get the console command options.
348
     *
349
     * @return array
350
     */
351
    protected function getOptions()
352
    {
353
        return [
354
            ['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'],
355
        ];
356
    }
357
}
358