Completed
Pull Request — master (#186)
by Vladimir
06:00 queued 03:00
created

NewsCategoryStatusColumnConversion::up()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 32
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 32
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 23
nc 1
nop 0
1
<?php
2
3
use Phinx\Migration\AbstractMigration;
4
5
class NewsCategoryStatusColumnConversion extends AbstractMigration
6
{
7
    public function up()
8
    {
9
        $newsCategoryTable = $this->table('news_categories');
10
        $newsCategoryTable
11
            ->addColumn('is_read_only', 'boolean', [
12
                'after' => 'protected',
13
                'null' => false,
14
                'default' => false,
15
                'comment' => 'When set to true, no new articles should be able to use this category'
16
            ])
17
            ->addColumn('is_deleted', 'boolean', [
18
                'after' => 'is_read_only',
19
                'null' => false,
20
                'default' => false,
21
                'comment' => 'Whether or not the news category has been soft deleted',
22
            ])
23
            ->changeColumn('protected', 'boolean', [
24
                'default' => false,
25
                'null' => false,
26
                'comment' => 'When set to true, prevents the category from being deleted from the UI',
27
            ])
28
            ->update()
29
        ;
30
31
        $this->query("UPDATE news_categories SET is_deleted = 1 WHERE status = 'deleted';");
32
33
        $newsCategoryTable
34
            ->removeColumn('status')
35
            ->renameColumn('protected', 'is_protected')
36
            ->update()
37
        ;
38
    }
39
40 View Code Duplication
    public function down()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
41
    {
42
        $newsCategoryTable = $this->table('news_categories');
43
        $newsCategoryTable
44
            ->addColumn('status', 'set', [
45
                'values' => ['enabled', 'disabled', 'deleted'],
46
                'after' => 'is_deleted',
47
                'null' => false,
48
                'default' => 'enabled',
49
                'comment' => 'The status of the news element',
50
            ])
51
            ->renameColumn('is_protected', 'protected')
52
            ->update()
53
        ;
54
55
        $this->query("UPDATE news_categories SET status = 'deleted' WHERE is_deleted = 1;");
56
57
        $newsCategoryTable
58
            ->removeColumn('is_deleted')
59
            ->removeColumn('is_read_only')
60
            ->update()
61
        ;
62
    }
63
}
64