| Conditions | 5 |
| Paths | 4 |
| Total Lines | 21 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 12 | public function run(Registry $registry): Registry |
||
| 13 | { |
||
| 14 | foreach ($registry as $entity) { |
||
| 15 | foreach ($entity->getForeignKeys() as $fk) { |
||
| 16 | $target = $registry->getEntity($fk->getTarget()); |
||
| 17 | $targetSchema = $registry->getTableSchema($target); |
||
| 18 | |||
| 19 | $pkExists = \array_diff($fk->getOuterColumns(), $targetSchema->getPrimaryKeys()) === []; |
||
| 20 | if (!$pkExists && !$targetSchema->hasIndex($fk->getOuterColumns())) { |
||
| 21 | $targetSchema->index($fk->getOuterColumns())->unique(); |
||
| 22 | } |
||
| 23 | |||
| 24 | $registry->getTableSchema($entity) |
||
| 25 | ->foreignKey($fk->getInnerColumns(), $fk->isCreateIndex()) |
||
| 26 | ->references($registry->getTable($target), $fk->getOuterColumns()) |
||
| 27 | ->onUpdate($fk->getAction()) |
||
| 28 | ->onDelete($fk->getAction()); |
||
| 29 | } |
||
| 30 | } |
||
| 31 | |||
| 32 | return $registry; |
||
| 33 | } |
||
| 35 |