1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the O2System Framework package. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
* |
8
|
|
|
* @author Steeve Andrian Salim |
9
|
|
|
* @copyright Copyright (c) Steeve Andrian Salim |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
// ------------------------------------------------------------------------ |
13
|
|
|
|
14
|
|
|
namespace O2System\Framework\Cli\Commanders\Make; |
15
|
|
|
|
16
|
|
|
// ------------------------------------------------------------------------ |
17
|
|
|
|
18
|
|
|
use O2System\Framework\Cli\Commanders\Make; |
19
|
|
|
use O2System\Kernel\Cli\Writers\Format; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class Migration |
23
|
|
|
* |
24
|
|
|
* @package O2System\Framework\Cli\Commanders\Make |
25
|
|
|
*/ |
26
|
|
|
class Migration extends Make |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Migration::$commandDescription |
30
|
|
|
* |
31
|
|
|
* Command description. |
32
|
|
|
* |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
protected $commandDescription = 'CLI_MAKE_MIGRATION_DESC'; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Migration::$optionFileVersion |
39
|
|
|
* |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
protected $optionFileVersion = 'v.0.0.0'; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Migration::$optionNoSql |
46
|
|
|
* |
47
|
|
|
* @var bool |
48
|
|
|
*/ |
49
|
|
|
protected $optionNoSql = false; |
50
|
|
|
|
51
|
|
|
// ------------------------------------------------------------------------ |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Migration::optionFileVersion |
55
|
|
|
*/ |
56
|
|
|
public function optionFileVersion($version) |
57
|
|
|
{ |
58
|
|
|
$this->optionFileVersion = $version; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
// ------------------------------------------------------------------------ |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Migration::optionPath |
65
|
|
|
* |
66
|
|
|
* @param string $path |
67
|
|
|
*/ |
68
|
|
|
public function optionPath($path) |
69
|
|
|
{ |
70
|
|
|
$this->optionPath = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $path); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
// ------------------------------------------------------------------------ |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Migration::optionNoSql |
77
|
|
|
*/ |
78
|
|
|
public function optionNoSql() |
79
|
|
|
{ |
80
|
|
|
$this->optionNoSql = true; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
// ------------------------------------------------------------------------ |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Migration::execute |
87
|
|
|
*/ |
88
|
|
|
public function execute() |
89
|
|
|
{ |
90
|
|
|
$this->__callOptions(); |
91
|
|
|
|
92
|
|
|
if (empty($this->optionFilename)) { |
93
|
|
|
output()->write( |
|
|
|
|
94
|
|
|
(new Format()) |
95
|
|
|
->setContextualClass(Format::DANGER) |
96
|
|
|
->setString(language()->getLine('CLI_MAKE_MIGRATION_E_FILENAME')) |
97
|
|
|
->setNewLinesAfter(1) |
98
|
|
|
); |
99
|
|
|
|
100
|
|
|
exit(EXIT_ERROR); |
|
|
|
|
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
$className = studlycase($this->optionFilename); |
104
|
|
|
|
105
|
|
|
if(empty($this->optionFileVersion)) { |
106
|
|
|
$filename = date('YmdHis') . '_' . underscore($this->optionFilename); |
107
|
|
|
} else { |
108
|
|
|
$filename = $this->optionFileVersion . '_' . underscore($this->optionFilename); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
$filePath = PATH_DATABASE . 'migrations' . DIRECTORY_SEPARATOR; |
112
|
|
|
|
113
|
|
|
if( ! empty($this->optionPath) ) { |
114
|
|
|
$filePath = $filePath . $this->optionPath; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
$filePath = $filePath . $filename; |
118
|
|
|
|
119
|
|
|
$fileDirectory = dirname($filePath) . DIRECTORY_SEPARATOR; |
120
|
|
|
|
121
|
|
|
if ( ! is_dir($fileDirectory)) { |
122
|
|
|
mkdir($fileDirectory, 0777, true); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
if (is_file($filePath)) { |
126
|
|
|
output()->write( |
127
|
|
|
(new Format()) |
128
|
|
|
->setContextualClass(Format::DANGER) |
129
|
|
|
->setString(language()->getLine('CLI_MAKE_MIGRATION_E_EXISTS', [$filePath])) |
130
|
|
|
->setNewLinesAfter(1) |
131
|
|
|
); |
132
|
|
|
|
133
|
|
|
exit(EXIT_ERROR); |
|
|
|
|
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
$vars[ 'CREATE_DATETIME' ] = date('d/m/Y H:m'); |
|
|
|
|
137
|
|
|
$vars[ 'BASE_MIGRATION' ] = 'O2System\Framework\Models\Sql\Migration'; |
138
|
|
|
|
139
|
|
|
if($this->optionNoSql) { |
140
|
|
|
$vars[ 'BASE_MIGRATION' ] = 'O2System\Framework\Models\NoSql\Migration'; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
$vars[ 'CLASS' ] = $className; |
144
|
|
|
$vars[ 'FILEPATH' ] = $filePath; |
145
|
|
|
|
146
|
|
|
$phpTemplate = <<<PHPTEMPLATE |
147
|
|
|
<?php |
148
|
|
|
/** |
149
|
|
|
* Created by O2System Framework File Generator. |
150
|
|
|
* DateTime: CREATE_DATETIME |
151
|
|
|
*/ |
152
|
|
|
|
153
|
|
|
// ------------------------------------------------------------------------ |
154
|
|
|
|
155
|
|
|
use BASE_MIGRATION |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Class CLASS |
159
|
|
|
*/ |
160
|
|
|
class CLASS extends Migration |
161
|
|
|
{ |
162
|
|
|
/** |
163
|
|
|
* CLASS::up |
164
|
|
|
*/ |
165
|
|
|
public function up() |
166
|
|
|
{ |
167
|
|
|
// TODO: Change the autogenerated stub |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
// ------------------------------------------------------------------------ |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* CLASS::down |
174
|
|
|
*/ |
175
|
|
|
public function down() |
176
|
|
|
{ |
177
|
|
|
// TODO: Change the autogenerated stub |
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
PHPTEMPLATE; |
181
|
|
|
|
182
|
|
|
$fileContent = str_replace(array_keys($vars), array_values($vars), $phpTemplate); |
183
|
|
|
file_put_contents($filePath, $fileContent); |
184
|
|
|
|
185
|
|
|
if (is_file($filePath)) { |
186
|
|
|
output()->write( |
187
|
|
|
(new Format()) |
188
|
|
|
->setContextualClass(Format::SUCCESS) |
189
|
|
|
->setString(language()->getLine('CLI_MAKE_MIGRATION_S_MAKE', [$filePath])) |
190
|
|
|
->setNewLinesAfter(1) |
191
|
|
|
); |
192
|
|
|
|
193
|
|
|
exit(EXIT_SUCCESS); |
|
|
|
|
194
|
|
|
} |
195
|
|
|
} |
196
|
|
|
} |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.