1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Phinx\Migration\AbstractMigration; |
4
|
|
|
|
5
|
|
|
class PageStatusConversion extends AbstractMigration |
6
|
|
|
{ |
7
|
|
View Code Duplication |
public function up() |
|
|
|
|
8
|
|
|
{ |
9
|
|
|
$pagesTable = $this->table('pages'); |
10
|
|
|
$pagesTable |
11
|
|
|
->addColumn('is_unlisted', 'boolean', [ |
12
|
|
|
'after' => 'home', |
13
|
|
|
'null' => false, |
14
|
|
|
'default' => false, |
15
|
|
|
'comment' => 'Whether or not this page should be listed in the secondary navigation', |
16
|
|
|
]) |
17
|
|
|
->addColumn('is_draft', 'boolean', [ |
18
|
|
|
'after' => 'is_unlisted', |
19
|
|
|
'null' => false, |
20
|
|
|
'default' => false, |
21
|
|
|
'comment' => 'Whether or not the news article is a draft', |
22
|
|
|
]) |
23
|
|
|
->addColumn('is_deleted', 'boolean', [ |
24
|
|
|
'after' => 'is_draft', |
25
|
|
|
'null' => false, |
26
|
|
|
'default' => false, |
27
|
|
|
'comment' => 'Whether or not this entry has been soft-deleted', |
28
|
|
|
]) |
29
|
|
|
->update() |
30
|
|
|
; |
31
|
|
|
|
32
|
|
|
$this->query("UPDATE pages SET is_deleted = 1 WHERE status != 'live';"); |
33
|
|
|
|
34
|
|
|
$pagesTable |
35
|
|
|
->removeColumn('parent_id') |
36
|
|
|
->removeColumn('home') |
37
|
|
|
->removeColumn('status') |
38
|
|
|
->update() |
39
|
|
|
; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function down() |
43
|
|
|
{ |
44
|
|
|
$pagesTable = $this->table('pages'); |
45
|
|
|
$pagesTable |
46
|
|
|
->addColumn('parent_id', 'integer', [ |
47
|
|
|
'after' => 'id', |
48
|
|
|
'null' => true, |
49
|
|
|
'default' => null, |
50
|
|
|
'length' => 10, |
51
|
|
|
'comment' => 'The ID of the original page. If this column is set, then it is a revision', |
52
|
|
|
]) |
53
|
|
|
->addColumn('home', 'integer', [ |
54
|
|
|
'after' => 'author', |
55
|
|
|
'length' => 4, |
56
|
|
|
'null' => true, |
57
|
|
|
'default' => null, |
58
|
|
|
'comment' => '(Deprecated) Whether or not the page is the home page', |
59
|
|
|
]) |
60
|
|
|
->addColumn('status', 'set', [ |
61
|
|
|
'values' => ['live', 'revision', 'disabled', 'deleted'], |
62
|
|
|
'after' => 'home', |
63
|
|
|
'null' => false, |
64
|
|
|
'default' => 'live', |
65
|
|
|
'comment' => 'The status of this page', |
66
|
|
|
]) |
67
|
|
|
->update() |
68
|
|
|
; |
69
|
|
|
|
70
|
|
|
$this->query("UPDATE pages SET status = 'deleted' WHERE is_deleted = 1"); |
71
|
|
|
|
72
|
|
|
$pagesTable |
73
|
|
|
->removeColumn('is_unlisted') |
74
|
|
|
->removeColumn('is_draft') |
75
|
|
|
->removeColumn('is_deleted') |
76
|
|
|
->update() |
77
|
|
|
; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
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.