3 namespace Drupal\Console\Command\Database;
5 use Symfony\Component\Console\Input\InputArgument;
6 use Symfony\Component\Console\Input\InputInterface;
7 use Symfony\Component\Console\Output\OutputInterface;
10 * Class LogPollCommand
12 * @package Drupal\Console\Command\Database
14 class LogPollCommand extends DatabaseLogBase
24 protected function execute(InputInterface $input, OutputInterface $output)
26 $this->getIo()->note($this->trans('commands.database.log.poll.messages.warning'));
28 $this->getDefaultOptions($input);
29 $this->duration = $input->getArgument('duration');
31 $this->pollForEvents();
37 protected function configure()
40 ->setName('database:log:poll')
41 ->setDescription($this->trans('commands.database.log.poll.description'));
43 $this->addDefaultLoggingOptions();
47 InputArgument::OPTIONAL,
48 $this->trans('commands.database.log.poll.arguments.duration'),
50 )->setAliases(['dblp']);
54 protected function pollForEvents()
56 $query = $this->makeQuery()->countQuery();
57 $results = $query->execute()->fetchAssoc();
58 $count = $results['expression'] - 1;//minus 1 so the newest message always prints
60 $tableHeader = $this->createTableHeader();
62 //Poll, force no wait on first loop
63 $lastExec = time() - $this->duration;
65 if (time() > $lastExec + $this->duration) {
66 //Print out any new db logs
67 $query = $this->makeQuery($count);
68 $results = $query->execute()->fetchAll();
69 $count += count($results);
71 foreach ($results as $r) {
72 $tableRows[] = $this->createTableRow($r);
74 if (!empty($tableRows)) {
75 $this->getIo()->table($tableHeader, $tableRows);
77 //update the last exec time