Skip to content

Commit d26bf20

Browse files
author
Paweł Brzozowski
committed
drop Yii < 2.0.15 conditions
1 parent e1c819d commit d26bf20

File tree

3 files changed

+36
-69
lines changed

3 files changed

+36
-69
lines changed

src/Generator.php

Lines changed: 33 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -119,22 +119,16 @@ public function getTableSchema(): ?TableSchema
119119
protected function getTablePrimaryKey(): TablePrimaryKey
120120
{
121121
$data = [];
122-
if (method_exists($this->db->schema, 'getTablePrimaryKey')) {
123-
/* @var $constraint \yii\db\Constraint */
124-
$constraint = $this->db->schema->getTablePrimaryKey($this->tableName, true);
125-
if ($constraint) {
126-
$data = [
127-
'columns' => $constraint->columnNames,
128-
'name' => $constraint->name,
129-
];
130-
}
131-
} elseif ($this->tableSchema instanceof TableSchema) {
132-
if ($this->tableSchema->primaryKey) {
133-
$data = [
134-
'columns' => $this->tableSchema->primaryKey,
135-
];
136-
}
122+
123+
/* @var $constraint \yii\db\Constraint */
124+
$constraint = $this->db->schema->getTablePrimaryKey($this->tableName, true);
125+
if ($constraint) {
126+
$data = [
127+
'columns' => $constraint->columnNames,
128+
'name' => $constraint->name,
129+
];
137130
}
131+
138132
return new TablePrimaryKey($data);
139133
}
140134

@@ -184,34 +178,20 @@ protected function getTableColumns(array $indexes = []): array
184178
protected function getTableForeignKeys(): array
185179
{
186180
$data = [];
187-
if (method_exists($this->db->schema, 'getTableForeignKeys')) {
188-
$fks = $this->db->schema->getTableForeignKeys($this->tableName, true);
189-
/* @var $fk \yii\db\ForeignKeyConstraint */
190-
foreach ($fks as $fk) {
191-
$data[$fk->name] = new TableForeignKey([
192-
'name' => $fk->name,
193-
'columns' => $fk->columnNames,
194-
'refTable' => $fk->foreignTableName,
195-
'refColumns' => $fk->foreignColumnNames,
196-
'onDelete' => $fk->onDelete,
197-
'onUpdate' => $fk->onUpdate,
198-
]);
199-
}
200-
} elseif ($this->tableSchema instanceof TableSchema) {
201-
foreach ($this->tableSchema->foreignKeys as $name => $key) {
202-
$fk = new TableForeignKey([
203-
'name' => $name,
204-
'refTable' => ArrayHelper::remove($key, 0),
205-
'onDelete' => null,
206-
'onUpdate' => null,
207-
]);
208-
foreach ($key as $col => $ref) {
209-
$fk->columns[] = $col;
210-
$fk->refColumns[] = $ref;
211-
}
212-
$data[$name] = $fk;
213-
}
181+
182+
$fks = $this->db->schema->getTableForeignKeys($this->tableName, true);
183+
/* @var $fk \yii\db\ForeignKeyConstraint */
184+
foreach ($fks as $fk) {
185+
$data[$fk->name] = new TableForeignKey([
186+
'name' => $fk->name,
187+
'columns' => $fk->columnNames,
188+
'refTable' => $fk->foreignTableName,
189+
'refColumns' => $fk->foreignColumnNames,
190+
'onDelete' => $fk->onDelete,
191+
'onUpdate' => $fk->onUpdate,
192+
]);
214193
}
194+
215195
return $data;
216196
}
217197

@@ -223,30 +203,19 @@ protected function getTableForeignKeys(): array
223203
protected function getTableIndexes(): array
224204
{
225205
$data = [];
226-
if (method_exists($this->db->schema, 'getTableIndexes')) {
227-
$idxs = $this->db->schema->getTableIndexes($this->tableName, true);
228-
/* @var $idx \yii\db\IndexConstraint */
229-
foreach ($idxs as $idx) {
230-
if (!$idx->isPrimary) {
231-
$data[$idx->name] = new TableIndex([
232-
'name' => $idx->name,
233-
'unique' => $idx->isUnique,
234-
'columns' => $idx->columnNames
235-
]);
236-
}
206+
207+
$idxs = $this->db->schema->getTableIndexes($this->tableName, true);
208+
/* @var $idx \yii\db\IndexConstraint */
209+
foreach ($idxs as $idx) {
210+
if (!$idx->isPrimary) {
211+
$data[$idx->name] = new TableIndex([
212+
'name' => $idx->name,
213+
'unique' => $idx->isUnique,
214+
'columns' => $idx->columnNames
215+
]);
237216
}
238-
} else {
239-
try {
240-
$uidxs = $this->db->schema->findUniqueIndexes($this->tableSchema);
241-
foreach ($uidxs as $name => $cols) {
242-
$data[$name] = new TableIndex([
243-
'name' => $name,
244-
'unique' => true,
245-
'columns' => $cols
246-
]);
247-
}
248-
} catch (NotSupportedException $exc) {}
249217
}
218+
250219
return $data;
251220
}
252221

src/controllers/MigrationController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public function init(): void
191191
if ($this->$property === 'true' || $this->$property === 1) {
192192
$this->$property = true;
193193
}
194-
$this->$property = (bool)$this->$property;
194+
$this->$property = (bool) $this->$property;
195195
}
196196
}
197197
}

src/table/TableColumnFactory.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ public static function build(array $configuration = []): ?TableColumn
3737
return new TableColumnString($configuration);
3838
case Schema::TYPE_TEXT:
3939
return new TableColumnText($configuration);
40-
case \defined('yii\db\Schema::TYPE_TINYINT') ? Schema::TYPE_TINYINT : 'nottinyint':
41-
// TinyInt support since Yii 2.0.14
40+
case Schema::TYPE_TINYINT:
4241
return new TableColumnTinyInt($configuration);
4342
case Schema::TYPE_SMALLINT:
4443
return new TableColumnSmallInt($configuration);
@@ -66,8 +65,7 @@ public static function build(array $configuration = []): ?TableColumn
6665
return new TableColumnBoolean($configuration);
6766
case Schema::TYPE_MONEY:
6867
return new TableColumnMoney($configuration);
69-
case \defined('yii\db\Schema::TYPE_JSON') ? Schema::TYPE_JSON : 'notjson':
70-
// Json support since Yii 2.0.14
68+
case Schema::TYPE_JSON:
7169
return new TableColumnJson($configuration);
7270
default:
7371
throw new InvalidConfigException("Unsupported schema type '{$configuration['type']}' for TableColumnFactory.");

0 commit comments

Comments
 (0)