1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Auto Generated from Blender |
5
|
|
|
* Date: 2017/11/10 at 15:29:37 EST -05:00 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
use \LCI\Blend\Migrations; |
9
|
|
|
use LCI\MODX\Console\Console; |
10
|
|
|
|
11
|
|
|
class Update_001_000_000_beta_013 extends Migrations |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* Run the migrations. |
15
|
|
|
* |
16
|
|
|
* @return void |
17
|
|
|
*/ |
18
|
|
|
public function up() |
19
|
|
|
{ |
20
|
|
|
/** @var \xPDOManager $manager */ |
21
|
|
|
$manager = $this->modx->getManager(); |
22
|
|
|
|
23
|
|
|
$columns = $this->getCurrentColumns(); |
24
|
|
|
|
25
|
|
|
if (!in_array('project', $columns)) { |
26
|
|
|
// the class table object name |
27
|
|
|
if ($manager->addField('BlendMigrations', 'project', ['after' => 'id'])) { |
28
|
|
|
$this->blender->outSuccess('The project column was add to the BlendMigrations class (' . |
29
|
|
|
$this->modx->getTableName('BlendMigrations') . ') successfully'); |
30
|
|
|
|
31
|
|
|
} else { |
32
|
|
|
$this->blender->out('The project column was not added to the BlendMigrations class (' . |
33
|
|
|
$this->modx->getTableName('BlendMigrations') . ') successfully', true); |
|
|
|
|
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
if (!in_array('ran_sequence', $columns)) { |
39
|
|
|
// the class table object name |
40
|
|
|
if ($manager->addField('BlendMigrations', 'ran_sequence', ['after' => 'processed_at'])) { |
41
|
|
|
$this->blender->outSuccess('The ran_sequence column was add to the BlendMigrations class (' . |
42
|
|
|
$this->modx->getTableName('BlendMigrations') . ') successfully'); |
43
|
|
|
|
44
|
|
|
} else { |
45
|
|
|
$this->blender->out('The author ran_sequence was not added to the BlendMigrations class (' . |
46
|
|
|
$this->modx->getTableName('BlendMigrations') . ') successfully', true); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** @var \LCI\MODX\Console\Console $console */ |
51
|
|
|
$console = new Console(); |
52
|
|
|
$console->registerPackageCommands('LCI\Blend\Console\ActivePackageCommands'); |
53
|
|
|
|
54
|
|
|
/** @var \LCI\Blend\Blendable\SystemSetting $systemSetting */ |
55
|
|
|
$systemSetting = $this->blender->getBlendableLoader()->getBlendableSystemSetting('blend.version'); |
56
|
|
|
$systemSetting |
57
|
|
|
->setSeedsDir($this->getSeedsDir()) |
58
|
|
|
->setFieldValue('1.0.0-beta13') |
59
|
|
|
->setFieldArea('Blend') |
60
|
|
|
->blend(true); |
61
|
|
|
|
62
|
|
|
$this->modx->cacheManager->refresh(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Reverse the migrations. |
67
|
|
|
* |
68
|
|
|
* @return void |
69
|
|
|
*/ |
70
|
|
|
public function down() |
71
|
|
|
{ |
72
|
|
|
/** @var \LCI\MODX\Console\Console $console */ |
73
|
|
|
$console = new Console(); |
74
|
|
|
$console->cancelRegistrationPackageCommands('LCI\Blend\Console\ActivePackageCommands'); |
75
|
|
|
|
76
|
|
|
/** @var \LCI\Blend\Blendable\SystemSetting $systemSetting */ |
77
|
|
|
$systemSetting = $this->blender->getBlendableLoader()->getBlendableSystemSetting('blend.version'); |
78
|
|
|
$systemSetting |
79
|
|
|
->setSeedsDir($this->getSeedsDir()) |
80
|
|
|
->revertBlend(); |
81
|
|
|
|
82
|
|
|
$this->modx->cacheManager->refresh(); |
83
|
|
|
|
84
|
|
|
$previous_version = $this->modx->getOption('blend.version'); |
85
|
|
|
if (!$previous_version || version_compare($this->getVersion(), $previous_version, '>') ) { |
86
|
|
|
|
87
|
|
|
/** @var \xPDOManager $manager */ |
88
|
|
|
$manager = $this->modx->getManager(); |
89
|
|
|
|
90
|
|
|
// the class table object name |
91
|
|
|
if ($manager->removeField('BlendMigrations', 'project', ['after' => 'status'])) { |
92
|
|
|
$this->blender->outSuccess('The project column was removed from the BlendMigrations class ('. |
93
|
|
|
$this->modx->getTableName('BlendMigrations').') successfully'); |
94
|
|
|
|
95
|
|
|
} else { |
96
|
|
|
$this->blender->out('The project column was not removed from the BlendMigrations class ('. |
97
|
|
|
$this->modx->getTableName('BlendMigrations').') successfully', true); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
protected function getCurrentColumns() |
103
|
|
|
{ |
104
|
|
|
$columns = []; |
105
|
|
|
|
106
|
|
|
$rs = $this->modx->query('SELECT * FROM ' . $this->modx->getTableName('BlendMigrations') . ' LIMIT 0'); |
107
|
|
|
for ($i = 0; $i < $rs->columnCount(); $i++) { |
108
|
|
|
$col = $rs->getColumnMeta($i); |
109
|
|
|
$columns[] = $col['name']; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
return $columns; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Method is called on construct, please fill me in |
117
|
|
|
*/ |
118
|
|
|
protected function assignDescription() |
119
|
|
|
{ |
120
|
|
|
$this->description = 'Update Blend to v1.0.0 beta13 from v1.0.0 beta and below'; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Method is called on construct, please fill me in |
125
|
|
|
*/ |
126
|
|
|
protected function assignVersion() |
127
|
|
|
{ |
128
|
|
|
$this->version = '1.0.0 beta13'; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Method is called on construct, can change to only run this migration for those types |
133
|
|
|
*/ |
134
|
|
|
protected function assignType() |
135
|
|
|
{ |
136
|
|
|
$this->type = 'master'; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Method is called on construct, Child class can override and implement this |
141
|
|
|
*/ |
142
|
|
|
protected function assignSeedsDir() |
143
|
|
|
{ |
144
|
|
|
$this->seeds_dir = 'Update_001_000_000_beta_013'; |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
|