QueryLogDisableCommand.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Developer\Console\Command;
  7. use Symfony\Component\Console\Command\Command;
  8. use Symfony\Component\Console\Input\InputInterface;
  9. use Symfony\Component\Console\Output\OutputInterface;
  10. use Magento\Framework\App\DeploymentConfig\Writer;
  11. use Magento\Framework\Config\File\ConfigFilePool;
  12. use Magento\Framework\DB\Logger\LoggerProxy;
  13. class QueryLogDisableCommand extends Command
  14. {
  15. /**
  16. * command name
  17. */
  18. const COMMAND_NAME = 'dev:query-log:disable';
  19. /**
  20. * Success message
  21. */
  22. const SUCCESS_MESSAGE = "DB query logging disabled.";
  23. /**
  24. * @var Writer
  25. */
  26. private $deployConfigWriter;
  27. /**
  28. * QueryLogDisableCommand constructor.
  29. * @param Writer $deployConfigWriter
  30. * @param null $name
  31. */
  32. public function __construct(
  33. Writer $deployConfigWriter,
  34. $name = null
  35. ) {
  36. parent::__construct($name);
  37. $this->deployConfigWriter = $deployConfigWriter;
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. protected function configure()
  43. {
  44. $this->setName(self::COMMAND_NAME)
  45. ->setDescription('Disable DB query logging');
  46. parent::configure();
  47. }
  48. /**
  49. * {@inheritdoc}
  50. * @throws \InvalidArgumentException
  51. */
  52. protected function execute(InputInterface $input, OutputInterface $output)
  53. {
  54. $data = [LoggerProxy::PARAM_ALIAS => LoggerProxy::LOGGER_ALIAS_DISABLED];
  55. $this->deployConfigWriter->saveConfig([ConfigFilePool::APP_ENV => [LoggerProxy::CONF_GROUP_NAME => $data]]);
  56. $output->writeln("<info>". self::SUCCESS_MESSAGE . "</info>");
  57. }
  58. }