Skip to content

Commit

Permalink
Pass a PSR logger to LoadDataFixturesDoctrineCommand
Browse files Browse the repository at this point in the history
Not doing so is deprecated.
See doctrine/data-fixtures#462
  • Loading branch information
greg0ire committed Nov 6, 2024
1 parent a345e6c commit 0f4f1ac
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<service id="doctrine.fixtures_load_command" class="Doctrine\Bundle\FixturesBundle\Command\LoadDataFixturesDoctrineCommand">
<argument type="service" id="doctrine.fixtures.loader" />
<argument type="service" id="doctrine" />
<argument type="collection"></argument>
<tag name="console.command" command="doctrine:fixtures:load" />
</service>

Expand Down
23 changes: 21 additions & 2 deletions src/Command/LoadDataFixturesDoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ManagerRegistry;
use Psr\Log\AbstractLogger;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -134,9 +135,27 @@ private function doExecute(InputInterface $input, OutputInterface $output): int
$input->getOption('purge-with-truncate'),
);
$executor = new ORMExecutor($em, $purger);
$executor->setLogger(static function ($message) use ($ui): void {
$ui->text(sprintf(' <comment>></comment> <info>%s</info>', $message));
$executor->setLogger(new class ($ui) extends AbstractLogger {
private SymfonyStyle $ui;

public function __construct(SymfonyStyle $ui)
{
$this->ui = $ui;
}

/** {@inheritDoc} */
public function log($level, $message, array $context = []): void
{
$this->ui->text(sprintf(' <comment>></comment> <info>%s</info>', $message));
}

/** @deprecated to be removed when dropping support for doctrine/data-fixtures <1.8 */
public function __invoke(string $message): void
{
$this->log(0, $message);
}
});

$executor->execute($fixtures, $input->getOption('append'));

return 0;
Expand Down

0 comments on commit 0f4f1ac

Please sign in to comment.