|
1
|
|
|
<?php |
|
2
|
|
|
namespace tmukherjee13\migration\console\controllers; |
|
3
|
|
|
|
|
4
|
|
|
use Yii; |
|
5
|
|
|
use yii\console\controllers\MigrateController; |
|
6
|
|
|
use yii\console\Exception; |
|
7
|
|
|
use yii\db\Connection; |
|
8
|
|
|
use yii\db\Query; |
|
9
|
|
|
use yii\helpers\ArrayHelper; |
|
10
|
|
|
use yii\helpers\Console; |
|
11
|
|
|
use yii\helpers\FileHelper; |
|
12
|
|
|
|
|
13
|
|
|
class MigrationController extends MigrateController |
|
14
|
|
|
{ |
|
15
|
|
|
use \tmukherjee13\migration\console\components\Formatter; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @inheritdoc |
|
19
|
|
|
*/ |
|
20
|
|
|
public $defaultAction = 'migrate'; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var string a migration table name |
|
24
|
|
|
*/ |
|
25
|
|
|
public $migrationTable = 'migration'; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var string a migration path |
|
29
|
|
|
*/ |
|
30
|
|
|
public $migrationPath = "@app/migrations"; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var string путь к данным |
|
34
|
|
|
*/ |
|
35
|
|
|
public $dataMigrationFolder = 'data'; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var bool использовать путь к данным |
|
39
|
|
|
*/ |
|
40
|
|
|
public $useDataMigrationFolder = true; |
|
41
|
|
|
|
|
42
|
|
|
/** @var string template file to use for generation */ |
|
43
|
|
|
public $templateFile = "@tmukherjee13/migration"; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var string class name |
|
47
|
|
|
*/ |
|
48
|
|
|
protected $class = ""; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @var string table name |
|
52
|
|
|
*/ |
|
53
|
|
|
protected $table = ""; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @var string table columns |
|
57
|
|
|
*/ |
|
58
|
|
|
public $fields = ""; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @var string file name |
|
62
|
|
|
*/ |
|
63
|
|
|
protected $fileName = ''; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @var Connection|string the DB connection object or the application component ID of the DB connection. |
|
67
|
|
|
*/ |
|
68
|
|
|
public $db = 'db'; |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @inheritdoc |
|
72
|
|
|
*/ |
|
73
|
|
|
public function options($actionID) |
|
74
|
|
|
{ |
|
75
|
|
|
return array_merge(parent::options($actionID), ['migrationTable', 'db']); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @inheritdoc |
|
80
|
|
|
*/ |
|
81
|
|
|
public function beforeAction($action) |
|
82
|
|
|
{ |
|
83
|
|
|
|
|
84
|
|
|
if (parent::beforeAction($action)) { |
|
85
|
|
|
if (is_string($this->db)) { |
|
86
|
|
|
$this->db = Yii::$app->get($this->db); |
|
87
|
|
|
} |
|
88
|
|
|
if (!$this->db instanceof Connection) { |
|
89
|
|
|
throw new Exception("The 'db' option must refer to the application component ID of a DB connection."); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
$path = (string)Yii::getAlias($this->migrationPath); |
|
93
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
if (!is_dir($path)) { |
|
96
|
|
|
if ($action->id !== 'table') { |
|
97
|
|
|
|
|
98
|
|
|
throw new Exception("Migration failed. Directory specified in migrationPath doesn't exist: {$this->migrationPath}"); |
|
99
|
|
|
} |
|
100
|
|
|
FileHelper::createDirectory($path); |
|
101
|
|
|
} |
|
102
|
|
|
$this->migrationPath = $path; |
|
103
|
|
|
|
|
104
|
|
|
$version = Yii::getVersion(); |
|
105
|
|
|
$this->stdout("Yii Database Migration Tool (based on Yii v{$version})\n", Console::FG_YELLOW); |
|
106
|
|
|
|
|
107
|
|
|
return true; |
|
108
|
|
|
} |
|
109
|
|
|
return false; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Collects the foreign key column details for the given table. |
|
114
|
|
|
* @param TableSchema $table the table metadata |
|
115
|
|
|
*/ |
|
116
|
|
|
protected function findConstraints($table) |
|
117
|
|
|
{ |
|
118
|
|
|
$sql = <<<SQL |
|
119
|
|
|
SELECT |
|
120
|
|
|
kcu.constraint_name, |
|
121
|
|
|
kcu.column_name, |
|
122
|
|
|
kcu.referenced_table_name, |
|
123
|
|
|
kcu.referenced_column_name, |
|
124
|
|
|
rc.DELETE_RULE, |
|
125
|
|
|
rc.UPDATE_RULE |
|
126
|
|
|
|
|
127
|
|
|
FROM information_schema.referential_constraints AS rc |
|
128
|
|
|
JOIN information_schema.key_column_usage AS kcu ON |
|
129
|
|
|
( |
|
130
|
|
|
kcu.constraint_catalog = rc.constraint_catalog OR |
|
131
|
|
|
(kcu.constraint_catalog IS NULL AND rc.constraint_catalog IS NULL) |
|
132
|
|
|
) AND |
|
133
|
|
|
kcu.constraint_schema = rc.constraint_schema AND |
|
134
|
|
|
kcu.constraint_name = rc.constraint_name |
|
135
|
|
|
WHERE rc.constraint_schema = database() AND kcu.table_schema = database() |
|
136
|
|
|
AND rc.table_name = :tableName AND kcu.table_name = :tableName |
|
137
|
|
|
SQL; |
|
138
|
|
|
try { |
|
139
|
|
|
|
|
140
|
|
|
$rows = $this->db->createCommand($sql, [':tableName' => $table->name])->queryAll(); |
|
141
|
|
|
|
|
142
|
|
|
$constraints = []; |
|
143
|
|
|
$table->foreignKeys = []; |
|
144
|
|
|
foreach ($rows as $row) { |
|
145
|
|
|
$constraints[$row['constraint_name']]['referenced_table_name'] = $row['referenced_table_name']; |
|
146
|
|
|
$constraints[$row['constraint_name']]['columns'][$row['column_name']] = $row['referenced_column_name']; |
|
147
|
|
|
|
|
148
|
|
|
$table->foreignKeys[$row['constraint_name']]['table'] = $row['referenced_table_name']; |
|
149
|
|
|
$table->foreignKeys[$row['constraint_name']]['column'] = $row['column_name']; |
|
150
|
|
|
$table->foreignKeys[$row['constraint_name']]['ref_column'] = $row['referenced_column_name']; |
|
151
|
|
|
$table->foreignKeys[$row['constraint_name']]['delete'] = $row['DELETE_RULE']; |
|
152
|
|
|
$table->foreignKeys[$row['constraint_name']]['update'] = $row['UPDATE_RULE']; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
return $constraints; |
|
156
|
|
|
} catch (\Exception $e) { |
|
157
|
|
|
$previous = $e->getPrevious(); |
|
158
|
|
|
if (!$previous instanceof \PDOException || strpos($previous->getMessage(), 'SQLSTATE[42S02') === false) { |
|
159
|
|
|
throw $e; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
// table does not exist, try to determine the foreign keys using the table creation sql |
|
163
|
|
|
$sql = $this->getCreateTableSql($table); |
|
164
|
|
|
$regexp = '/FOREIGN KEY\s+\(([^\)]+)\)\s+REFERENCES\s+([^\(^\s]+)\s*\(([^\)]+)\)/mi'; |
|
165
|
|
|
if (preg_match_all($regexp, $sql, $matches, PREG_SET_ORDER)) { |
|
166
|
|
|
foreach ($matches as $match) { |
|
167
|
|
|
$fks = array_map('trim', explode(',', str_replace('`', '', $match[1]))); |
|
168
|
|
|
$pks = array_map('trim', explode(',', str_replace('`', '', $match[3]))); |
|
169
|
|
|
$constraint = [str_replace('`', '', $match[2])]; |
|
170
|
|
|
foreach ($fks as $k => $name) { |
|
171
|
|
|
$constraint[$name] = $pks[$k]; |
|
172
|
|
|
} |
|
173
|
|
|
$table->foreignKeys[md5(serialize($constraint))] = $constraint; |
|
174
|
|
|
} |
|
175
|
|
|
$table->foreignKeys = array_values($table->foreignKeys); |
|
176
|
|
|
} |
|
177
|
|
|
} |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* Gets the CREATE TABLE sql string. |
|
182
|
|
|
* @param TableSchema $table the table metadata |
|
183
|
|
|
* @return string $sql the result of 'SHOW CREATE TABLE' |
|
184
|
|
|
*/ |
|
185
|
|
|
protected function getCreateTableSql($table) |
|
186
|
|
|
{ |
|
187
|
|
|
$row = $this->db->createCommand('SHOW CREATE TABLE ' . $this->quoteTableName($table->fullName))->queryOne(); |
|
188
|
|
|
if (isset($row['Create Table'])) { |
|
189
|
|
|
$sql = $row['Create Table']; |
|
190
|
|
|
} else { |
|
191
|
|
|
$row = array_values($row); |
|
192
|
|
|
$sql = $row[1]; |
|
193
|
|
|
} |
|
194
|
|
|
return $sql; |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
public function quoteTableName($name) |
|
198
|
|
|
{ |
|
199
|
|
|
return strpos($name, '`') !== false ? $name : "`$name`"; |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
/** |
|
203
|
|
|
* Up data |
|
204
|
|
|
* |
|
205
|
|
|
* @param int $limit |
|
206
|
|
|
* @return int |
|
207
|
|
|
*/ |
|
208
|
|
|
public function actionUpData($limit = 0) |
|
209
|
|
|
{ |
|
210
|
|
|
$this->migrationPath .= DIRECTORY_SEPARATOR . $this->dataMigrationFolder; |
|
211
|
|
|
return parent::actionUp($limit); |
|
|
|
|
|
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
/** |
|
215
|
|
|
* Creates migration based on table |
|
216
|
|
|
* @method actionTable |
|
217
|
|
|
* @param array $tables Name of the table to create migration |
|
218
|
|
|
* @return mixed |
|
219
|
|
|
* @author Tarun Mukherjee (https://github.com/tmukherjee13) |
|
220
|
|
|
*/ |
|
221
|
|
|
|
|
222
|
|
|
public function actionTable(array $tables) |
|
223
|
|
|
{ |
|
224
|
|
|
|
|
225
|
|
|
if ($this->confirm('Create the migration ' . "?")) { |
|
226
|
|
|
|
|
227
|
|
|
foreach ($tables as $key => $tableName) { |
|
228
|
|
|
|
|
229
|
|
|
$this->class = 'create_table_' . $tableName; |
|
230
|
|
|
|
|
231
|
|
|
try { |
|
232
|
|
|
|
|
233
|
|
|
$table = $this->db->getTableSchema($tableName); |
|
234
|
|
|
} catch (Exception $e) { |
|
235
|
|
|
throw new Exception("There has been an error processing the file. Please try after some time."); |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
if (empty($table)) { |
|
239
|
|
|
throw new Exception("Table doesn't exists"); |
|
240
|
|
|
} |
|
241
|
|
|
$this->findConstraints($table); |
|
242
|
|
|
|
|
243
|
|
|
$this->getCreateTableSql($table); |
|
244
|
|
|
|
|
245
|
|
|
$compositePrimaryKeyCols = array(); |
|
246
|
|
|
|
|
247
|
|
|
$addForeignKeys = ""; |
|
248
|
|
|
$dropForeignKeys = ""; |
|
249
|
|
|
$up = ""; |
|
250
|
|
|
|
|
251
|
|
|
$this->table = $this->getTableName($table); |
|
252
|
|
|
|
|
253
|
|
|
foreach ($table->columns as $col) { |
|
254
|
|
|
$up .= "\t\t\t" . '\'' . $col->name . '\'=>"' . $this->getColType($col) . '",' . "\n"; |
|
255
|
|
|
if ($col->isPrimaryKey) { |
|
256
|
|
|
// Add column to composite primary key array |
|
257
|
|
|
$compositePrimaryKeyCols[] = $col->name; |
|
258
|
|
|
} |
|
259
|
|
|
} |
|
260
|
|
|
|
|
261
|
|
|
$ukeys = $this->db->schema->findUniqueIndexes($table); |
|
262
|
|
|
if (!empty($ukeys)) { |
|
263
|
|
|
$indexArr =[]; |
|
264
|
|
|
foreach ($ukeys as $key => $value) { |
|
265
|
|
|
$indexKey = $key; |
|
266
|
|
|
foreach ($value as $id => $field) { |
|
267
|
|
|
$indexArr[] = $field; |
|
268
|
|
|
} |
|
269
|
|
|
} |
|
270
|
|
|
$indexStr = implode(',', $indexArr); |
|
271
|
|
|
$up .= "\t\t" . '$this->createIndex(\'idx_' . $indexKey . "', '" . $this->getTableName($table) . "', '$indexStr', TRUE);\n"; |
|
|
|
|
|
|
272
|
|
|
|
|
273
|
|
|
} |
|
274
|
|
|
|
|
275
|
|
|
if (!empty($table->foreignKeys)): |
|
276
|
|
|
|
|
277
|
|
|
foreach ($table->foreignKeys as $fkName => $fk) { |
|
278
|
|
|
$addForeignKeys .= "\t\t" . '$this->addForeignKey("' . $fkName . '", "' . $table->name . '", "' . $fk['column'] . '","' . $fk['table'] . '","' . $fk['ref_column'] . '", "' . $fk['delete'] . '", "' . $fk['update'] . '");' . "\n"; |
|
279
|
|
|
$dropForeignKeys .= '$this->dropForeignKey(' . "'$fkName', '$table->name');"; |
|
280
|
|
|
} |
|
281
|
|
|
|
|
282
|
|
|
endif; |
|
283
|
|
|
|
|
284
|
|
|
$this->fields = $table->columns; |
|
285
|
|
|
|
|
286
|
|
|
$fields = $this->parseFields(); |
|
287
|
|
|
|
|
288
|
|
|
$this->prepareFile(['up' => '', 'down' => '', 'foreignKeys' => $table->foreignKeys, 'fields' => $fields]) . "\n\n"; |
|
289
|
|
|
|
|
290
|
|
|
} |
|
291
|
|
|
|
|
292
|
|
|
} |
|
293
|
|
|
return; |
|
294
|
|
|
} |
|
295
|
|
|
|
|
296
|
|
|
/** |
|
297
|
|
|
* Returns the name of the data migration file created |
|
298
|
|
|
* @param array $tables the list of tables |
|
299
|
|
|
* @return integer|null |
|
300
|
|
|
*/ |
|
301
|
|
|
public function actionData(array $tables) |
|
302
|
|
|
{ |
|
303
|
|
|
|
|
304
|
|
|
if ($this->confirm('Create the migration ' . "?", true)) { |
|
305
|
|
|
foreach ($tables as $key => $args) { |
|
306
|
|
|
|
|
307
|
|
|
$table = $args; |
|
308
|
|
|
$this->class = 'insert_data_into_' . $table; |
|
309
|
|
|
$this->table = $table; |
|
310
|
|
|
$this->templateFile = '@tmukherjee13/migration/views/dataTemplate.php'; |
|
311
|
|
|
|
|
312
|
|
|
$columns = $this->db->getTableSchema($table); |
|
313
|
|
|
$prefix = $this->db->tablePrefix; |
|
314
|
|
|
$table = str_replace($prefix, '', $table); |
|
|
|
|
|
|
315
|
|
|
$table = $columns; |
|
316
|
|
|
|
|
317
|
|
|
$this->table = $this->getTableName($table); |
|
318
|
|
|
|
|
319
|
|
|
$prepared_columns = ''; |
|
|
|
|
|
|
320
|
|
|
$up = ''; |
|
|
|
|
|
|
321
|
|
|
$down = ''; |
|
|
|
|
|
|
322
|
|
|
$prepared_data = []; |
|
323
|
|
|
|
|
324
|
|
|
$name = $this->getFileName(); |
|
|
|
|
|
|
325
|
|
|
|
|
326
|
|
|
if (!empty($table)) { |
|
327
|
|
|
|
|
328
|
|
|
$query = new Query; |
|
329
|
|
|
$query->select('*') |
|
330
|
|
|
->from($table->name); |
|
331
|
|
|
$command = $query->createCommand(); |
|
332
|
|
|
$data = $command->queryAll(); |
|
333
|
|
|
|
|
334
|
|
|
$pcolumns = ''; |
|
335
|
|
|
foreach ($columns->columns as $column) { |
|
336
|
|
|
$pcolumns .= "'" . $column->name . "',"; |
|
337
|
|
|
} |
|
338
|
|
|
foreach ($data as $row) { |
|
339
|
|
|
array_push($prepared_data, $row); |
|
340
|
|
|
} |
|
341
|
|
|
|
|
342
|
|
|
if (empty($prepared_data)) { |
|
343
|
|
|
$this->stdout("\nTable '{$table->name}' doesn't contain any data.\n\n", Console::FG_RED); |
|
344
|
|
|
} else { |
|
345
|
|
|
$pcolumns = $this->prepareColumns($pcolumns); |
|
346
|
|
|
$prows = $this->prepareData($prepared_data); |
|
347
|
|
|
|
|
348
|
|
|
$this->prepareFile(['columns' => $pcolumns, 'rows' => $prows]); |
|
349
|
|
|
} |
|
350
|
|
|
// return self::EXIT_CODE_ERROR; |
|
|
|
|
|
|
351
|
|
|
} |
|
352
|
|
|
} |
|
353
|
|
|
return self::EXIT_CODE_NORMAL; |
|
354
|
|
|
} |
|
355
|
|
|
} |
|
356
|
|
|
|
|
357
|
|
|
/** |
|
358
|
|
|
* Returns the name of the database migration file created |
|
359
|
|
|
* @param string $args the schema name |
|
360
|
|
|
* @return integer |
|
361
|
|
|
*/ |
|
362
|
|
|
public function actionSchema($args) |
|
363
|
|
|
{ |
|
364
|
|
|
|
|
365
|
|
|
$schema = $args; |
|
366
|
|
|
$this->class = 'dump_database_' . $schema; |
|
367
|
|
|
|
|
368
|
|
|
// $tables = $this->db->schema->getTableNames($schema); |
|
|
|
|
|
|
369
|
|
|
|
|
370
|
|
|
$tables = $this->db->schema->getTableSchemas($schema); |
|
371
|
|
|
$addForeignKeys = ''; |
|
|
|
|
|
|
372
|
|
|
$dropForeignKeys = ''; |
|
|
|
|
|
|
373
|
|
|
$up = ''; |
|
|
|
|
|
|
374
|
|
|
$down = ''; |
|
|
|
|
|
|
375
|
|
|
$hasPrimaryKey = false; |
|
|
|
|
|
|
376
|
|
|
$name = $this->getFileName(); |
|
|
|
|
|
|
377
|
|
|
$tablePrefix = $this->db->tablePrefix; |
|
|
|
|
|
|
378
|
|
|
$generateTables = []; |
|
379
|
|
|
|
|
380
|
|
|
foreach ($tables as $table) { |
|
381
|
|
|
if ($table->name === $this->db->tablePrefix . $this->migrationTable) { |
|
382
|
|
|
continue; |
|
383
|
|
|
} |
|
384
|
|
|
$generateTables[] = $table->name; |
|
385
|
|
|
} |
|
386
|
|
|
$this->actionTable($generateTables); |
|
387
|
|
|
return self::EXIT_CODE_NORMAL; |
|
388
|
|
|
|
|
389
|
|
|
} |
|
390
|
|
|
|
|
391
|
|
|
public function getFileName() |
|
392
|
|
|
{ |
|
393
|
|
|
return 'm' . gmdate('ymd_His') . '_' . $this->class; |
|
394
|
|
|
} |
|
395
|
|
|
|
|
396
|
|
|
public function setFileName() |
|
397
|
|
|
{ |
|
398
|
|
|
$this->fileName = $this->getFileName(); |
|
399
|
|
|
} |
|
400
|
|
|
|
|
401
|
|
|
public function prepareFile($data) |
|
402
|
|
|
{ |
|
403
|
|
|
if ($this->useDataMigrationFolder) { |
|
404
|
|
|
FileHelper::createDirectory($this->migrationPath . DIRECTORY_SEPARATOR . $this->dataMigrationFolder); |
|
405
|
|
|
} |
|
406
|
|
|
$file = $this->migrationPath . DIRECTORY_SEPARATOR . ($this->useDataMigrationFolder ? $this->dataMigrationFolder . DIRECTORY_SEPARATOR : null) . $this->getFileName() . '.php'; |
|
407
|
|
|
try { |
|
408
|
|
|
|
|
409
|
|
|
$data['table'] = $this->table; |
|
410
|
|
|
$data['className'] = $this->getFileName(); |
|
411
|
|
|
$content = $this->renderFile(Yii::getAlias($this->templateFile), $data); |
|
|
|
|
|
|
412
|
|
|
file_put_contents($file, $content); |
|
413
|
|
|
$this->stdout("\nNew migration {$this->getFileName()} successfully created.\nRun yii migrate to apply migrations.\n", Console::FG_GREEN); |
|
414
|
|
|
return $file; |
|
415
|
|
|
} catch (Exception $e) { |
|
416
|
|
|
throw new Exception("There has been an error processing the file. Please try after some time."); |
|
417
|
|
|
} |
|
418
|
|
|
} |
|
419
|
|
|
|
|
420
|
|
|
|
|
421
|
|
|
|
|
422
|
|
|
/** |
|
423
|
|
|
* @inheritdoc |
|
424
|
|
|
*/ |
|
425
|
|
|
protected function getMigrationHistory($limit) |
|
426
|
|
|
{ |
|
427
|
|
|
if ($this->db->schema->getTableSchema($this->migrationTable, true) === null) { |
|
428
|
|
|
$this->createMigrationHistoryTable(); |
|
429
|
|
|
} |
|
430
|
|
|
$query = new Query; |
|
431
|
|
|
$rows = $query->select(['version', 'apply_time']) |
|
432
|
|
|
->from($this->migrationTable) |
|
433
|
|
|
->orderBy('apply_time DESC, version DESC') |
|
434
|
|
|
->limit($limit) |
|
435
|
|
|
->createCommand($this->db) |
|
|
|
|
|
|
436
|
|
|
->queryAll(); |
|
437
|
|
|
$history = ArrayHelper::map($rows, 'version', 'apply_time'); |
|
438
|
|
|
unset($history[self::BASE_MIGRATION]); |
|
439
|
|
|
|
|
440
|
|
|
return $history; |
|
441
|
|
|
} |
|
442
|
|
|
|
|
443
|
|
|
/** |
|
444
|
|
|
* @inheritdoc |
|
445
|
|
|
*/ |
|
446
|
|
|
protected function addMigrationHistory($version) |
|
447
|
|
|
{ |
|
448
|
|
|
$command = $this->db->createCommand(); |
|
449
|
|
|
$command->insert($this->migrationTable, [ |
|
450
|
|
|
'version' => $version, |
|
451
|
|
|
'apply_time' => time(), |
|
452
|
|
|
])->execute(); |
|
453
|
|
|
} |
|
454
|
|
|
|
|
455
|
|
|
/** |
|
456
|
|
|
* @inheritdoc |
|
457
|
|
|
*/ |
|
458
|
|
|
protected function removeMigrationHistory($version) |
|
459
|
|
|
{ |
|
460
|
|
|
$command = $this->db->createCommand(); |
|
461
|
|
|
$command->delete($this->migrationTable, [ |
|
462
|
|
|
'version' => $version, |
|
463
|
|
|
])->execute(); |
|
464
|
|
|
} |
|
465
|
|
|
|
|
466
|
|
|
/** |
|
467
|
|
|
* @inheritdoc |
|
468
|
|
|
*/ |
|
469
|
|
|
protected function parseFields() |
|
470
|
|
|
{ |
|
471
|
|
|
$fields = []; |
|
472
|
|
|
|
|
473
|
|
|
foreach ($this->fields as $column => $schema) { |
|
|
|
|
|
|
474
|
|
|
$chunks = []; |
|
475
|
|
|
|
|
476
|
|
|
$columns = $this->formatCol($schema); |
|
477
|
|
|
|
|
478
|
|
|
foreach ($columns as $key => $chunk) { |
|
479
|
|
|
if (!preg_match('/^(.+?)\(([^)]+)\)$/', $chunk)) { |
|
480
|
|
|
$chunk .= '()'; |
|
481
|
|
|
} |
|
482
|
|
|
$chunks[] = $chunk; |
|
483
|
|
|
} |
|
484
|
|
|
$fields[] = [ |
|
485
|
|
|
'property' => $column, |
|
486
|
|
|
'decorators' => implode('->', $chunks), |
|
487
|
|
|
]; |
|
488
|
|
|
} |
|
489
|
|
|
return $fields; |
|
490
|
|
|
} |
|
491
|
|
|
} |
|
492
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()method in theSoncalls the wrong method in the parent class.