aboutsummaryrefslogtreecommitdiff
path: root/db/migrations/1.300_tiled_courses_2.php
blob: 5d9b038990ed6afc37a976e8dd6632ececfb7757 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
class TiledCourses2 extends Migration
{
    public function description()
    {
        return 'Changes user config for open groups';
    }

    public function up()
    {
        ConfigValue::findEachByField(
            function ($value) {
                $open_groups = json_decode($value->value, true);
                $open_groups = array_keys($open_groups);
                $value->value = json_encode($open_groups);
                $value->store();
            },
            'MY_COURSES_OPEN_GROUPS'
        );
    }

    public function down()
    {
        ConfigValue::findEachByField(
            function ($value) {
                $open_groups = json_decode($value->value, true);
                $open_groups = array_fill_keys($open_groups, true);
                $value->value = json_encode($open_groups);
                $value->store();
            },
            'MY_COURSES_OPEN_GROUPS'
        );
    }
}