Completed
Push — master ( 5de7bb...dc715b )
by Gino
05:11
created

PopulateDefaultSettings::up()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace GinoPane\AwesomeIconsList\Updates;
4
5
use DB;
6
use Schema;
7
use October\Rain\Database\Updates\Migration;
8
use GinoPane\AwesomeIconsList\Models\Settings;
9
10
/**
11
 * Class PopulateDefaultSettings
12
 *
13
 * @package GinoPane\AwesomeIconsList\Updates
14
 */
15
class PopulateDefaultSettings extends Migration
16
{
17
    /**
18
     * Execute migrations
19
     */
20
    public function up()
21
    {
22
        $this->addSettings();
23
    }
24
25
    /**
26
     * Rollback migrations
27
     */
28
    public function down()
29
    {
30
        $this->removeSettings();
31
    }
32
33
    /**
34
     * Rollback Tags migration
35
     */
36
    private function removeSettings()
37
    {
38
        if (Schema::hasTable('system_settings')) {
39
            DB::table('system_settings')->whereItem(Settings::SETTINGS_CODE)->delete();
40
        }
41
    }
42
43
    /**
44
     * Create Tags table
45
     */
46
    private function addSettings()
47
    {
48
        if (Schema::hasTable('system_settings')) {
49
            $settings = [
50
               Settings::FONTAWESOME_LINK_KEY => Settings::FONTAWESOME_LINK,
51
               Settings::FONTAWESOME_LINK_ATTRIBUTES_KEY => Settings::FONTAWESOME_LINK_ATTRIBUTES
52
            ];
53
54
            DB::table('system_settings')->insert(
55
                ['item' => Settings::SETTINGS_CODE, 'value' => json_encode($settings)]
56
            );
57
        }
58
    }
59
}
60