1

I have a Symfony project and I'm trying to get a list of available commands in my controller, so I tried to execute the list-command (together with --format=xml) to achieve that.

I used the code listed here to run a command from a controller but end up with the error "Not passing a connection provider as the first constructor argument is deprecated".

This is the code:

    $application = new Application($kernel);
    $application->setAutoExit(false);
    $input  = new ArrayInput(['command' => 'list', '--format' => 'xml']);
    $output = new BufferedOutput();
    $application->run($input, $output);
    $content = $output->fetch();

The mentioned error occurs in vendor\doctrine\dbal\lib\Doctrine\DBAL\Tools\Console\Command\RunSqlCommand.php. Here's the complete trace:

[
  "exception" => ErrorException {
    #message: "User Deprecated: Not passing a connection provider as the first constructor argument is deprecated"
    #code: 0
    #file: "C:\xampp\htdocs_shopfloor\shopfloorlist\vendor\doctrine\dbal\lib\Doctrine\DBAL\Tools\Console\Command\RunSqlCommand.php"
    #line: 44
    #severity: E_USER_DEPRECATED
    trace: {
      C:\xampp\htdocs_shopfloor\shopfloorlist\vendor\doctrine\dbal\lib\Doctrine\DBAL\Tools\Console\Command\RunSqlCommand.php:44 { …}
      C:\xampp\htdocs_shopfloor\shopfloorlist\var\cache\dev\Container54qfFMq\getDoctrine_QuerySqlCommandService.php:24 {
        Container54qfFMq\getDoctrine_QuerySqlCommandService::do($container, $lazyLoad = true)
        › 
        › $container->privates['doctrine.query_sql_command'] = $instance = new \Doctrine\Bundle\DoctrineBundle\Command\Proxy\RunSqlDoctrineCommand();
        › 
      }
      C:\xampp\htdocs_shopfloor\shopfloorlist\var\cache\dev\Container54qfFMq\App_KernelDevDebugContainer.php:609 { …}
      C:\xampp\htdocs_shopfloor\shopfloorlist\vendor\symfony\dependency-injection\Container.php:441 { …}
      C:\xampp\htdocs_shopfloor\shopfloorlist\vendor\symfony\dependency-injection\Argument\ServiceLocator.php:40 { …}
      C:\xampp\htdocs_shopfloor\shopfloorlist\vendor\symfony\console\CommandLoader\ContainerCommandLoader.php:45 { …}
      C:\xampp\htdocs_shopfloor\shopfloorlist\vendor\symfony\console\Application.php:527 { …}
      C:\xampp\htdocs_shopfloor\shopfloorlist\vendor\symfony\console\Application.php:723 { …}
      C:\xampp\htdocs_shopfloor\shopfloorlist\vendor\symfony\framework-bundle\Console\Application.php:142 { …}
      C:\xampp\htdocs_shopfloor\shopfloorlist\vendor\symfony\console\Descriptor\ApplicationDescription.php:91 { …}
      C:\xampp\htdocs_shopfloor\shopfloorlist\vendor\symfony\console\Descriptor\ApplicationDescription.php:68 { …}
      C:\xampp\htdocs_shopfloor\shopfloorlist\vendor\symfony\console\Descriptor\XmlDescriptor.php:97 { …}
      C:\xampp\htdocs_shopfloor\shopfloorlist\vendor\symfony\console\Descriptor\XmlDescriptor.php:155 { …}
      C:\xampp\htdocs_shopfloor\shopfloorlist\vendor\symfony\console\Descriptor\Descriptor.php:55 { …}
      C:\xampp\htdocs_shopfloor\shopfloorlist\vendor\symfony\console\Helper\DescriptorHelper.php:65 { …}
      C:\xampp\htdocs_shopfloor\shopfloorlist\vendor\symfony\console\Command\ListCommand.php:75 { …}
      C:\xampp\htdocs_shopfloor\shopfloorlist\vendor\symfony\console\Command\Command.php:258 { …}
      C:\xampp\htdocs_shopfloor\shopfloorlist\vendor\symfony\console\Application.php:938 { …}
      C:\xampp\htdocs_shopfloor\shopfloorlist\vendor\symfony\framework-bundle\Console\Application.php:99 { …}
      C:\xampp\htdocs_shopfloor\shopfloorlist\vendor\symfony\console\Application.php:266 { …}
      C:\xampp\htdocs_shopfloor\shopfloorlist\vendor\symfony\framework-bundle\Console\Application.php:82 { …}
      C:\xampp\htdocs_shopfloor\shopfloorlist\vendor\symfony\console\Application.php:142 { …}
      C:\xampp\htdocs_shopfloor\shopfloorlist\src\Controller\AdminController.php:134 { …}
      C:\xampp\htdocs_shopfloor\shopfloorlist\vendor\symfony\http-kernel\HttpKernel.php:157 { …}
      C:\xampp\htdocs_shopfloor\shopfloorlist\vendor\symfony\http-kernel\HttpKernel.php:79 { …}
      C:\xampp\htdocs_shopfloor\shopfloorlist\vendor\symfony\http-kernel\Kernel.php:196 { …}
      C:\xampp\htdocs_shopfloor\shopfloorlist\public\index.php:29 { …}
    }
  }
]

Strange enough running "bin/console list" (or just "bin/console") with or without the format set to XML will not show the error, also running any other command from my controller with the above code will work just fine.

I'm using Symfony 5.1.7 with Doctrine-bundle 2.1, I already tried downgrading doctrine/persistence to 1.x as 2.x showed some issues with some libraries, all to no avail.

2
  • Out of curiosity: why do you need commands in a controller? Also, why not ignore that message? It's a deprecation warning, not a runtime error, and probably generating the list on the console would yield the same error when using the same error level Commented Oct 21, 2020 at 11:27
  • 1
    I want to view a list of available commands on a webpage, clickable for admins to execute them manually. And as I need the list to expand when adding the commands automatically, I'm trying to do it this way. Of course I could "ignore" the error which means filtering it out (as it's part of $content) but I'd rather understand why/where the error occurs and have it fixed. Also some external library is getting the same error and I can't filter it there. Commented Oct 22, 2020 at 7:41

1 Answer 1

6

I fixed this issue by re-declaring the command in my project with the proper argument:

doctrine.query_sql_command:
    class: Doctrine\DBAL\Tools\Console\Command\RunSqlCommand
    arguments:
        - '@Doctrine\Bundle\DoctrineBundle\Dbal\ManagerRegistryAwareConnectionProvider'
    tags:
        - { name: console.command, command: doctrine:query:sql }
Sign up to request clarification or add additional context in comments.

1 Comment

@yivi don't know why but it is and it fixes the issue, haven't experienced any downside so far, thanks Vincent

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.