|
@@ -6,9 +6,12 @@ declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace App\Commands\Doctrine;
|
|
namespace App\Commands\Doctrine;
|
|
|
|
|
|
|
|
-use App\Service\Utils\Path;
|
|
|
|
|
|
|
+use App\Service\Utils\FileUtils;
|
|
|
|
|
+use App\Service\Utils\PathUtils;
|
|
|
use Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand;
|
|
use Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand;
|
|
|
|
|
+use Doctrine\ORM\Tools\Console\EntityManagerProvider;
|
|
|
use Doctrine\ORM\Tools\SchemaTool;
|
|
use Doctrine\ORM\Tools\SchemaTool;
|
|
|
|
|
+use Path\Path;
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
|
@@ -18,13 +21,28 @@ use Symfony\Component\Console\Style\SymfonyStyle;
|
|
|
*/
|
|
*/
|
|
|
class SchemaUpdateCommand extends UpdateCommand
|
|
class SchemaUpdateCommand extends UpdateCommand
|
|
|
{
|
|
{
|
|
|
|
|
+ public static function getDefaultName(): string
|
|
|
|
|
+ {
|
|
|
|
|
+ return 'doctrine:schema:update';
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function __construct(
|
|
|
|
|
+ private readonly EntityManagerProvider $entityManagerProvider
|
|
|
|
|
+ )
|
|
|
|
|
+ {
|
|
|
|
|
+ parent::__construct($this->entityManagerProvider);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas, SymfonyStyle $ui): int
|
|
protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas, SymfonyStyle $ui): int
|
|
|
{
|
|
{
|
|
|
$output->writeln('-- Executing pre-update scripts');
|
|
$output->writeln('-- Executing pre-update scripts');
|
|
|
|
|
|
|
|
// Lists schema extensions scripts in the '/sql/schema-extensions' dir
|
|
// Lists schema extensions scripts in the '/sql/schema-extensions' dir
|
|
|
$schemaExtensionsDir = PathUtils::join(PathUtils::getProjectDir(), 'sql', 'schema-extensions');
|
|
$schemaExtensionsDir = PathUtils::join(PathUtils::getProjectDir(), 'sql', 'schema-extensions');
|
|
|
- $scripts = $this->fileUtils->list($schemaExtensionsDir, '*.sql');
|
|
|
|
|
|
|
+
|
|
|
|
|
+ $schemaExtensionsDir = (new Path(PathUtils::getProjectDir()))->append('sql', 'schema-extensions');
|
|
|
|
|
+
|
|
|
|
|
+ $scripts = $schemaExtensionsDir->glob('*.sql');
|
|
|
sort($scripts);
|
|
sort($scripts);
|
|
|
|
|
|
|
|
// Execute those scripts in alphabetical order
|
|
// Execute those scripts in alphabetical order
|
|
@@ -32,7 +50,7 @@ class SchemaUpdateCommand extends UpdateCommand
|
|
|
$conn = $em->getConnection();
|
|
$conn = $em->getConnection();
|
|
|
|
|
|
|
|
foreach ($scripts as $script) {
|
|
foreach ($scripts as $script) {
|
|
|
- $sql = $this->fileUtils->getFileContent($script);
|
|
|
|
|
|
|
+ $sql = $script->getContent();
|
|
|
$conn->executeQuery($sql);
|
|
$conn->executeQuery($sql);
|
|
|
}
|
|
}
|
|
|
|
|
|