Skip to content

Commit 5485b6e

Browse files
committed
Revert to --purge-with-delete
1 parent 2ff49b7 commit 5485b6e

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

src/Command/LoadDataFixturesDoctrineODMCommand.php

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected function configure(): void
4444
->addOption('group', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Only load fixtures that belong to this group (use with --services)')
4545
->addOption('append', null, InputOption::VALUE_NONE, 'Append the data fixtures instead of flushing the database first.')
4646
->addOption('dm', null, InputOption::VALUE_REQUIRED, 'The document manager to use for this command.')
47-
->addOption('purge', null, InputOption::VALUE_OPTIONAL, 'Purge the database before loading the fixtures. If set to "delete", collections will be kept and documents deleted instead of dropping the collections.', null, self::getPurgeModes(...))
47+
->addOption('purge-with-delete', null, InputOption::VALUE_NONE, 'Purge the database using deleteMany() instead of dropping and recreating the collections.')
4848
->setHelp(<<<'EOT'
4949
The <info>doctrine:mongodb:fixtures:load</info> command loads data fixtures from your application:
5050
@@ -58,9 +58,9 @@ protected function configure(): void
5858
5959
<info>php %command.full_name%</info> <comment>--group=group1</comment>
6060
61-
If the collection uses search indexes or encryption, you can use the <info>--purge=delete</info> option to keep the collections instead of dropping them when purging the database:
61+
If the collection uses search indexes or encryption, you can use the <info>--purge-with-delete</info> option to keep the collections instead of dropping them when purging the database:
6262
63-
<info>php %command.full_name%</info> --purge=delete
63+
<info>php %command.full_name%</info> --purge-with-delete
6464
EOT
6565
);
6666
}
@@ -72,13 +72,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7272

7373
$ui = new SymfonyStyle($input, $output);
7474

75-
if ($input->hasOption('purge')) {
76-
if ($input->getOption('append')) {
77-
$ui->error('The --purge option cannot be used with the --append option.');
78-
79-
return self::INVALID;
80-
}
81-
} elseif ($input->isInteractive() && ! $input->getOption('append')) {
75+
if ($input->isInteractive() && ! $input->getOption('append')) {
8276
$helper = $this->getHelper('question');
8377
$question = new ConfirmationQuestion('Careful, database will be purged. Do you want to continue (y/N) ?', false);
8478

@@ -102,19 +96,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int
10296
}
10397

10498
$purger = new MongoDBPurger($dm);
105-
$purge = $input->getOption('purge');
106-
if ($purge) {
99+
if ($input->getOption('purge-with-delete')) {
107100
if (! class_exists(MongoDBPurgeMode::class)) {
108101
$ui->error('The --purge-with-delete option requires doctrine/data-fixtures >= 2.1.0.');
109102

110103
return self::INVALID;
111104
}
112105

113-
$purger->setPurgeMode(MongoDBPurgeMode::tryFrom($purge) ?? throw new InvalidArgumentException('Invalid purge mode: ' . $purge));
106+
$purger->setPurgeMode(MongoDBPurgeMode::Delete);
114107
}
115108

116109
$executor = new MongoDBExecutor($dm, $purger);
117-
118110
$executor->setLogger(new class ($output) extends AbstractLogger {
119111
public function __construct(private OutputInterface $output)
120112
{

tests/Command/LoadDataFixturesDoctrineODMCommandTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@ public function testExecute(): void
6060
$commandTester->execute([], ['interactive' => false]);
6161

6262
$output = $commandTester->getDisplay();
63+
$this->assertStringContainsString('purging database', $output);
64+
$this->assertStringContainsString('loading Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\CommandBundle\DataFixtures\UserFixtures', $output);
65+
$this->assertStringContainsString('loading Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\CommandBundle\DataFixtures\OtherFixtures', $output);
66+
}
67+
68+
public function testExecutePurgeWithDelete(): void
69+
{
70+
$commandTester = new CommandTester($this->command);
71+
$commandTester->execute(['--purge-with-delete'], ['interactive' => false]);
72+
73+
$output = $commandTester->getDisplay();
74+
$this->assertStringContainsString('purging database', $output);
6375
$this->assertStringContainsString('loading Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\CommandBundle\DataFixtures\UserFixtures', $output);
6476
$this->assertStringContainsString('loading Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\CommandBundle\DataFixtures\OtherFixtures', $output);
6577
}

0 commit comments

Comments
 (0)