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

NewsStatusColumnConversion::down()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 30
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 22
nc 1
nop 0
1
<?php
2
3
4
use Phinx\Migration\AbstractMigration;
5
6
class NewsStatusColumnConversion extends AbstractMigration
7
{
8 View Code Duplication
    public function up()
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...
9
    {
10
        $newsTable = $this->table('news');
11
        $newsTable
12
            ->addColumn('is_draft', 'boolean', [
13
                'after' => 'editor',
14
                'null' => false,
15
                'default' => false,
16
                'comment' => 'Whether or not the news article is a draft',
17
            ])
18
            ->addColumn('is_deleted', 'boolean', [
19
                'after' => 'is_draft',
20
                'null' => false,
21
                'default' => false,
22
                'comment' => 'Whether or not the news article has been soft deleted',
23
            ])
24
            ->update()
25
        ;
26
27
        $this->query("UPDATE news SET is_draft = 1 WHERE status = 'revision' OR status ='draft';");
28
        $this->query("UPDATE news SET is_deleted = 1 WHERE status = 'deleted' OR status = 'disabled';");
29
30
        $newsTable
31
            ->removeColumn('parent_id')
32
            ->removeColumn('status')
33
            ->update()
34
        ;
35
    }
36
37
    public function down()
38
    {
39
        $newsTable = $this->table('news');
40
        $newsTable
41
            ->addColumn('parent_id', 'integer', [
42
                'after' => 'id',
43
                'null' => true,
44
                'default' => null,
45
                'length' => 11,
46
                'comment' => 'The ID of the original news post. If this column is set, then it is a revision',
47
            ])
48
            ->addColumn('status', 'set', [
49
                'values' => ['published', 'revision', 'draft', 'disabled', 'deleted'],
50
                'after' => 'editor',
51
                'null' => false,
52
                'default' => 'published',
53
                'comment' => 'The status of the news element',
54
            ])
55
            ->update()
56
        ;
57
58
        $this->query("UPDATE news SET status = 'draft' WHERE is_draft = 1;");
59
        $this->query("UPDATE news SET status = 'deleted' WHERE is_deleted = 1;");
60
61
        $newsTable
62
            ->removeColumn('is_draft')
63
            ->removeColumn('is_deleted')
64
            ->update()
65
        ;
66
    }
67
}
68