TestCommand.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php /** @noinspection PhpUnused */
  2. namespace App\Commands\Doctrine;
  3. use App\Service\Utils\Path;
  4. use Doctrine\Bundle\DoctrineBundle\Command\Proxy\UpdateSchemaDoctrineCommand;
  5. use Doctrine\ORM\Tools\SchemaTool;
  6. use Symfony\Component\Console\Input\InputInterface;
  7. use Symfony\Component\Console\Output\OutputInterface;
  8. use Symfony\Component\Console\Style\SymfonyStyle;
  9. /**
  10. * Overrides the default doctrine:schema:update command
  11. */
  12. class SchemaUpdateCommand extends UpdateSchemaDoctrineCommand
  13. {
  14. protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas, SymfonyStyle $ui)
  15. {
  16. $output->writeln('-- Executing pre-update scripts');
  17. // Lists schema extensions scripts in the '/sql/schema-extensions' dir
  18. $schemaExtensionsDir = Path::join(Path::getProjectDir(), 'sql', 'schema-extensions');
  19. $scripts = Path::list($schemaExtensionsDir, '*.sql');
  20. sort($scripts);
  21. // Execute those scripts in alphabetical order
  22. $em = $this->getEntityManager($input);
  23. $conn = $em->getConnection();
  24. foreach ($scripts as $script) {
  25. $sql = Path::read($script);
  26. $conn->executeQuery($sql);
  27. }
  28. $output->writeln(sprintf('-- Database successfully updated, %s scripts executed', count($scripts)));
  29. throw new \RuntimeException('<!> Operation interrupted: use the d:s:u command on the current version to update the DB tables');
  30. // parent::executeSchemaCommand($input, $output, $schemaTool, $metadatas, $ui);
  31. }
  32. }