5 * Contains \Drupal\Console\Command\Database\LogClearCommand.
8 namespace Drupal\Console\Command\Database;
10 use Symfony\Component\Console\Input\InputArgument;
11 use Symfony\Component\Console\Input\InputOption;
12 use Symfony\Component\Console\Input\InputInterface;
13 use Symfony\Component\Console\Output\OutputInterface;
14 use Symfony\Component\Console\Command\Command;
15 use Drupal\Core\Database\Connection;
16 use Drupal\Console\Core\Command\Shared\CommandTrait;
17 use Drupal\Core\Logger\RfcLogLevel;
18 use Drupal\Console\Core\Style\DrupalStyle;
20 class LogClearCommand extends Command
30 * LogClearCommand constructor.
32 * @param Connection $database
34 public function __construct(Connection $database)
36 $this->database = $database;
37 parent::__construct();
43 protected function configure()
46 ->setName('database:log:clear')
47 ->setDescription($this->trans('commands.database.log.clear.description'))
50 InputArgument::OPTIONAL,
51 $this->trans('commands.database.log.clear.arguments.event-id')
56 InputOption::VALUE_OPTIONAL,
57 $this->trans('commands.database.log.clear.options.type')
62 InputOption::VALUE_OPTIONAL,
63 $this->trans('commands.database.log.clear.options.severity')
68 InputOption::VALUE_OPTIONAL,
69 $this->trans('commands.database.log.clear.options.user-id')
76 protected function execute(InputInterface $input, OutputInterface $output)
78 $io = new DrupalStyle($input, $output);
80 $eventId = $input->getArgument('event-id');
81 $eventType = $input->getOption('type');
82 $eventSeverity = $input->getOption('severity');
83 $userId = $input->getOption('user-id');
86 $this->clearEvent($io, $eventId);
88 $this->clearEvents($io, $eventType, $eventSeverity, $userId);
95 * @param DrupalStyle $io
99 private function clearEvent(DrupalStyle $io, $eventId)
101 $result = $this->database->delete('watchdog')->condition('wid', $eventId)->execute();
106 $this->trans('commands.database.log.clear.messages.not-found'),
116 $this->trans('commands.database.log.clear.messages.event-deleted'),
125 * @param DrupalStyle $io
127 * @param $eventSeverity
131 protected function clearEvents(DrupalStyle $io, $eventType, $eventSeverity, $userId)
133 $severity = RfcLogLevel::getLevels();
134 $query = $this->database->delete('watchdog');
137 $query->condition('type', $eventType);
140 if ($eventSeverity) {
141 if (!in_array($eventSeverity, $severity)) {
144 $this->trans('commands.database.log.clear.messages.invalid-severity'),
152 $query->condition('severity', array_search($eventSeverity, $severity));
156 $query->condition('uid', $userId);
159 $result = $query->execute();
163 $this->trans('commands.database.log.clear.messages.clear-error')
170 $this->trans('commands.database.log.clear.messages.clear-sucess')