| Conditions | 4 |
| Paths | 20 |
| Total Lines | 32 |
| Code Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 20 | protected function truncateEntity( |
||
| 21 | string $entityName, |
||
| 22 | OutputInterface $output = null, |
||
| 23 | string $startEcho = '', |
||
| 24 | string $endEcho = '' |
||
| 25 | ) { |
||
| 26 | if ($output) { |
||
| 27 | $output->write($startEcho); |
||
| 28 | } |
||
| 29 | |||
| 30 | $em = $this->getContainer()->get('doctrine.orm.entity_manager'); |
||
| 31 | |||
| 32 | $entityMetadata = $em->getClassMetadata($entityName); |
||
| 33 | $tableName = $entityMetadata->getTableName(); |
||
| 34 | $connection = $em->getConnection(); |
||
| 35 | $connection->beginTransaction(); |
||
| 36 | |||
| 37 | try { |
||
| 38 | $connection->query('SET FOREIGN_KEY_CHECKS=0'); |
||
| 39 | $connection->query('DELETE FROM ' . $tableName); |
||
| 40 | $connection->query('SET FOREIGN_KEY_CHECKS=1'); |
||
| 41 | $connection->commit(); |
||
| 42 | } catch (\Exception $e) { |
||
| 43 | $connection->rollback(); |
||
| 44 | } |
||
| 45 | |||
| 46 | $connection->exec('ALTER TABLE ' . $tableName . ' AUTO_INCREMENT = 1;'); |
||
| 47 | |||
| 48 | if ($output) { |
||
| 49 | $output->writeln($endEcho); |
||
| 50 | } |
||
| 51 | } |
||
| 52 | } |
||
| 53 |