PopulateDefaultSettings   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 0
dl 0
loc 49
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A up() 0 6 2
A down() 0 6 2
A removeSettings() 0 6 2
A addSettings() 0 13 2
1
<?php
2
3
namespace GinoPane\BlogTimeToRead\Updates;
4
5
use DB;
6
use Schema;
7
use System\Classes\PluginManager;
8
use October\Rain\Database\Updates\Migration;
9
use GinoPane\BlogTimeToRead\Models\Settings;
10
11
/**
12
 * Class PopulateDefaultSettings
13
 *
14
 * @package GinoPane\BlogTimeToRead\Updates
15
 */
16
class PopulateDefaultSettings extends Migration
17
{
18
    /**
19
     * Execute migrations
20
     */
21
    public function up()
22
    {
23
        if (PluginManager::instance()->hasPlugin('RainLab.Blog')) {
24
            $this->addSettings();
25
        }
26
    }
27
28
    /**
29
     * Rollback migrations
30
     */
31
    public function down()
32
    {
33
        if (PluginManager::instance()->hasPlugin('RainLab.Blog')) {
34
            $this->removeSettings();
35
        }
36
    }
37
38
    /**
39
     * Rollback Tags migration
40
     */
41
    private function removeSettings()
42
    {
43
        if (Schema::hasTable('system_settings')) {
44
            DB::table('system_settings')->whereItem(Settings::SETTINGS_CODE)->delete();
45
        }
46
    }
47
48
    /**
49
     * Create Tags table
50
     */
51
    private function addSettings()
52
    {
53
        if (Schema::hasTable('system_settings')) {
54
            $settings = [
55
               'default_reading_speed' => Settings::DEFAULT_READING_SPEED,
56
               'rounding_up_enabled' => Settings::DEFAULT_ROUNDING_UP_ENABLED
57
            ];
58
59
            DB::table('system_settings')->insert(
60
                ['item' => Settings::SETTINGS_CODE, 'value' => json_encode($settings)]
61
            );
62
        }
63
    }
64
}
65